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

Issue loading mechanic optimizer state #2

Open
yitzhaklevi opened this issue Nov 6, 2023 · 4 comments
Open

Issue loading mechanic optimizer state #2

yitzhaklevi opened this issue Nov 6, 2023 · 4 comments

Comments

@yitzhaklevi
Copy link

The following simple script reproduces the issue:

model = torch.nn.Linear(1, 1)
optimizer = mechanize(torch.optim.AdamW)(model.parameters(), lr=1e-5)
x = torch.ones([5, 1])
out = torch.sum(model(x))
out.backward()
optimizer.step()
print('done first step')

new_optimizer = mechanize(torch.optim.AdamW)(model.parameters(), lr=1e-5)
new_optimizer.load_state_dict(optimizer.state_dict())
out = torch.sum(model(x))
out.backward()
new_optimizer.step()
print('done new steps using new optimizer loaded')
@yitzhaklevi
Copy link
Author

The issue is due to the fact that state_dict['state']['_mechanic'] has tensor pointers as keys, those does not have the same addresses when re-initializing new Mechanic optimizer

(other optimizers e.g AdamW has the indexes as keys for the state)

@acutkosky
Copy link
Contributor

Thanks for bringing this up! I'll take a look and make an update (or if you want to do so, please feel free to submit a PR).

@yitzhaklevi
Copy link
Author

Welcome, I actually fixed that (will submit a PR next week, ) but it seems that on Windows the issue does not reproduce. (tried on my local machine and it worked)

@ogencoglu
Copy link

Any update on this?

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

3 participants