ParameterDict keys *must* be strings?

Is there a good reason for this? I would like to use general hashable objects as keys in my ParameterDict, just as I would in a normal Python dict.
Currently, the Pytorch documentation lies by claiming “ParameterDict can be indexed like a regular Python dictionary”, since the indexing must be done only with strings.

There is an issue about a similar topic on github (ModuleDict instead of ParameterDict).
If you like, you could describe your use case there.

Thanks, I’m also just going with the str(int) solution for now, it’s probably not that much of a performance-loss. Still a bit ugly is all.

Sure, I get it, and I think it’s a valid discussion, since there seem to be a few users noting this behavior. :wink:

The main reason is that we need to get a string key for the registered submodule, for purpose like saving state dict. Many things are hashable, but not all of them hash to same value when you run the same code in a new process.

1 Like