-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Block set from param_group['params'] #6031
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
Conversation
This might cause `list(params)` to output in random order. In this case, in `load_state_dict()`, `id_map` would not be matched correctly.
|
Just to make it easier to understand: optim = torch.optim.Adam(set(p for p in model.parameters()))should be avoided. A reasonable use case: biases = set(param for name, param in model.named_parameters() if 'bias' in name)
weights = [p for p in model.parameters() if p not in biases] # make biases a set to accelerate `in`
groups = [
dict(params=weights, lr=0.1, weight_decay=5e-4),
dict(params=biases, lr=0.2, weight_decay=0)
]
optim = torch.optim.Adam(groups)This might raise error after |
|
@pytorchbot test this please Looks reasonable to me |
|
maybe add some suggestions in the error msg? |
|
I'd suggest this: "Optimizer parameters need to be organized in ordered collections, but the ordering of tensors in sets will change between runs. Please use a list instead." Also, can you please add a warning that parameters need to give a deterministically ordered iterator in the optim docs? Thanks! |
|
@pytorchbot test this please |
|
warning added. but i havent got the time to compile & see |
|
@pytorchbot test this please |
|
Nice work. One little suggestion to the pytorch team: I think it would be better if we can assign each parameter a unique identifier (based on its hierarchy in the graph). By current design, the |
|
@codinfox i agree with that but it's hard to find sth other than name. even hierarchy can make things nontransparent and fragile. |
|
@Jiaming-Liu Yeah, name is a good identifier. |
|
@codinfox We don't do that just because there's no good way to get identifiers in a deterministic way. I guess we could extend the optimizer API to accept named lists of parameters, but we also need to keep the current API. |
|
@pytorchbot test this please |
|
thanks @Jiaming-Liu ! |
|
I met this problem when load state from check point. How can I solve this problem? |
This might cause
list(params)to output in random order. In this case, inload_state_dict(), keys & values ofid_mapwould not be matched correctly.