Use the basic knowledge of software engineering.
class MultipleOptimizer(object):
def __init__(*op):
self.optimizers = op
def zero_grad(self):
for op in self.optimizers:
op.zero_grad()
def step(self):
for op in self.optimizers:
op.step()
opt = MultipleOptimizer(optimizer1(params1, lr=lr1),
optimizer2(params2, lr=lr2))
loss.backward()
opt.zero_grad()
opt.step()