-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add TensorTree type #7
Conversation
from optree.typing import PyTreeTypeVar | ||
from torch import Tensor | ||
|
||
TensorTree: TypeAlias = PyTreeTypeVar("TensorTree", Tensor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So PyTreeTypeVar("custom_name", Type)
defines a type custom_name
of pytree where the leaf nodes all have type Type
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah see optree.PyTreeTypeVar
Although looking at it now PyTree[torch.Tensor] is perhaps cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think either is fine :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll keep like this for now, this is what torchopt does 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may be a stupid question but why do we care so much about generalizing to tree-like structures? what are some crucial examples where parameters are not just dict
s? (otherwise LGTM)
The object to be optimised could just be a tensor (useful for testing and more traditional MCMC). Also can support lists of dicts (which I think is common in pytorch with so-called "parameter groups") https://pytorch.org/docs/stable/optim.html |
makes sense, thanks! |
Added TensorTree type. Don't think there are other custom types we'd like to add currently? But I think there will be in future.