UserWarning for torch.load_state_dict

I’m trying to load a model that was trained with pytorch 0.1 in pytorch 0.2. I got this UserWarning:

/scratch/qhv200/conda_envs/pytorch2_gpu_py36/lib/python3.6/site-packages/torch/nn/modules/module.py:360: UserWarning: src is not broadcastable to dst, but they have the same number of elements. Falling back to deprecated pointwise behavior.

own_state[name].copy_(param)

File “policy_gradient.py”, line 578, in
policy_net.load_state_dict(torch.load(args.save_policy + f’_{slurm_array_idx}’ + ‘.pickled’))

File “/scratch/qhv200/conda_envs/pytorch2_gpu_py36/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 360, in load_state_dict
own_state[name].copy_(param)

Should I be concerned about this ? Is there another way to savely load model trained in pytorch 0.1 in pytorch 0.2.

change the model definition slightly to .view the param to the same shape as own_state[name] explicitly rather than implicitly.

own_state[name].copy_(param.view_as(own_state[name]))
2 Likes

I am having the same issue with state_dict saved using older versions of Pytorch. To avoid changing some legacy code, would it still be fine if I didn’t make the change you suggested and ignored the warning ?

@IssamLaradji yes it is fine

1 Like