Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradient share problem #59

Closed
vergilus opened this issue Mar 13, 2019 · 1 comment
Closed

gradient share problem #59

vergilus opened this issue Mar 13, 2019 · 1 comment

Comments

@vergilus
Copy link

in pytorch 1.0 the following line:

https://github.com/ikostrikov/pytorch-a3c/blob/master/train.py#L14

returns the gradient assignment error:
RuntimeError: assigned grad has data of a different type.

any fixes or suggestions?

@vergilus
Copy link
Author

I think I figure it out.
there is no grad in global params (None type), the way to solve this problem is to move the local parameters to CPU, then you can assign local parameter. to make life easier, you can wrap this function in the model.
ensure_shared_grads(model, shared_model)
becomes
model.to("cpu").ensure_shared_grads(shared_model)
but do mind that when you run your model on GPU, you have to switch it back to the device which it was running for next backward() (in case sometimes model can have "expected GPU but got CPU backend" error)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant