(model_params, master_params,
                     flat_master: bool = False)
Copy the `model_params` gradients to `master_params` for the optimizer step.
Copy the `model_params` gradients to `master_params` for the optimizer step.
Copy the model_params gradients to master_params for the optimizer step .
def model_g2master_g(model_params, master_params,
                     flat_master: bool = False) -> None:
    "Copy the `model_params` gradients to `master_params` for the optimizer step."
    if flat_master:
        for model_group, master_group in zip(model_params, master_params):
            if len(master_group) != 0:
                master_group[0].grad.data.copy_(
                    parameters_to_vector(
                        [p.grad.data.float() for p in model_group]))
    else:
        for model_group, master_group in zip(model_params, master_params):
            for model, master in zip(model_group, master_group):
                if model.grad is not None:
                    if master.grad is None:
                        master.grad = master.data.new(*master.data.size())
                    master.grad.data.copy_(model.grad.data)
                else:
                    master.grad = None
def model_g2master_g ( model_params , master_params , flat_master : bool = False ) -> None : if flat_master : for model_group , master_group in zip ( model_params , master_params ) : if len ( master_group ) != 0 : master_group [ 0 ] . grad . data . copy_ ( parameters_to_vector ( [ p . grad . data . float ( ) for p in model_group ] ) ) else : for model_group , master_group in zip ( model_params , master_params ) : for model , master in zip ( model_group , master_group ) : if model . grad is not None : if master . grad is None : master . grad = master . data . new ( * master . data . size ( ) ) master . grad . data . copy_ ( model . grad . data ) else : master . grad = None