facebookresearch / mae

PyTorch implementation of MAE https//arxiv.org/abs/2111.06377
Other
7.32k stars 1.22k forks source link

TypeError: __call__() got an unexpected keyword argument 'update_grad' #84

Open bolongliu opened 2 years ago

bolongliu commented 2 years ago

I soved the problem by deleting update_grad param", update_grad=(data_iter_step + 1) % accum_iter == 0" in mae/engine_finetune.py

loss_scaler(loss, optimizer, clip_grad = max_norm,parameters = model.parameters(), create_graph = False, update_grad=(data_iter_step + 1) % accum_iter == 0)

because NativeScaler not have such params

class NativeScaler:
    state_dict_key = "amp_scaler"

    def __init__(self):
        self._scaler = torch.cuda.amp.GradScaler()

    def __call__(self, loss, optimizer, clip_grad=None, clip_mode='norm', parameters=None, create_graph=False):
        self._scaler.scale(loss).backward(create_graph=create_graph)
        if clip_grad is not None:
            assert parameters is not None
            self._scaler.unscale_(optimizer)  # unscale the gradients of optimizer's assigned params in-place
            dispatch_clip_grad(parameters, clip_grad, mode=clip_mode)
        self._scaler.step(optimizer)
        self._scaler.update()

    def state_dict(self):
        return self._scaler.state_dict()

    def load_state_dict(self, state_dict):
        self._scaler.load_state_dict(state_dict)
LinB203 commented 1 year ago

anyone has a solution?

bolongliu commented 1 year ago

I soved the problem by deleting update_grad param", update_grad=(data_iter_step + 1) % accum_iter == 0" in mae/engine_finetune.py