(layer_groups, flat_master: bool = False)
Return two lists, one for the model parameters in FP16 and one for the master parameters in FP32.
Return two lists, one for the model parameters in FP16 and one for the master parameters in FP32.
Return two lists one for the model parameters in FP16 and one for the master parameters in FP32 .
def get_master(layer_groups, flat_master: bool = False):
    "Return two lists, one for the model parameters in FP16 and one for the master parameters in FP32."
    split_groups = split_bn_bias(layer_groups)
    model_params = [[
        param for param in lg.parameters() if param.requires_grad
    ] for lg in split_groups]
    if flat_master:
        master_params = []
        for lg in model_params:
            if len(lg) != 0:
                mp = parameters_to_vector([param.data.float() for param in lg])
                mp = torch.nn.Parameter(mp, requires_grad=True)
                if mp.grad is None: mp.grad = mp.new(*mp.size())
                master_params.append([mp])
            else:
                master_params.append([])
        return model_params, master_params
    else:
        master_params = [[param.clone().float().detach() for param in lg]
                         for lg in model_params]
        for mp in master_params:
            for param in mp:
                param.requires_grad = True
        return model_params, master_params
def get_master ( layer_groups , flat_master : bool = False ) : split_groups = split_bn_bias ( layer_groups ) model_params = [ [ param for param in lg . parameters ( ) if param . requires_grad ] for lg in split_groups ] if flat_master : master_params = [ ] for lg in model_params : if len ( lg ) != 0 : mp = parameters_to_vector ( [ param . data . float ( ) for param in lg ] ) mp = torch . nn . Parameter ( mp , requires_grad = True ) if mp . grad is None : mp . grad = mp . new ( * mp . size ( ) ) master_params . append ( [ mp ] ) else : master_params . append ( [ ] ) return model_params , master_params else : master_params = [ [ param . clone ( ) . float ( ) . detach ( ) for param in lg ] for lg in model_params ] for mp in master_params : for param in mp : param . requires_grad = True return model_params , master_params