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

what is the exact meaning of iterating in the parameters ? #19

Open
Oussamab21 opened this issue Jul 8, 2019 · 2 comments
Open

what is the exact meaning of iterating in the parameters ? #19

Oussamab21 opened this issue Jul 8, 2019 · 2 comments

Comments

@Oussamab21
Copy link

Hi , I just wanted to know what is the exact effect of these instructions:

for p in list(model.parameters()):
if hasattr(p,'org'):
p.data.copy_(p.org)

for p in list(model.parameters()):
if hasattr(p,'org'):
p.org.copy_(p.data.clamp_(-1,1))

@Ashokvardhan
Copy link

@Oussamab21 : The first for loop is to ensure that when you take a gradient step it's on the real weight parameters. However before this line p.data.copy_(p.org), the weights are actually binary because binary weights are needed for forward and backward passes. Once the backward pass is done using binary weights, we actually want to update the real weights and hence we copy the real weights which were temporarily stored in self.weight.org here

The second for loop is to ensure that weights are bounded in [-1,1].

@Oussamab21
Copy link
Author

Thank you if you only wants to binarize the weights is there any thing to change ?

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

2 participants