What does chain in itertools do?

I’m reading source code of DiscoGAN and found they use this for two Discriminators’ parameters:

gen_params = chain(generator_A.parameters(), generator_B.parameters())
optim_gen = optim.Adam( gen_params, lr=args.learning_rate, betas=(0.5,0.999), weight_decay=0.00001)

I can’t find documentation about what chain operation does, could anyone please explain to me ?

1 Like

It chains (concatenates) two iterable objects. chain yields the elements of the first iterator until it gets exhausted, and then it yields the elements of the second one. In your code chain puts together the parameters of the two generators so they will be optimized simultaneously. You can read more here: [docs].