-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Current ModuleT
traits do not allow in-place ops
#405
Comments
You mention fn forward(&self, xs: &Tensor) -> Tensor {
let mut out = xs.shallow_clone();
for submodule in self.submodules.iter() {
out = submodule.forward(&out);
}
out
} |
@LaurentMazare I understand that If we go deeper into the whole references thing, |
I agree that this low-level api doesn't reflect aliasing properly, and this has been the case from the start #33 (and this issue is not restricted to mutability). |
@LaurentMazare that makes sense, and does not seem unlike File.try_clone that also violates all the similar contracts. |
Ideally, they should consume and return
Tensor
. E.g.It does not work with mutable reference, because one needs to return the original tensor, and you can't get it from the reference (I am unsure if
shallow_clone
works with autograd. Documentation should explicitly mention that).Rant:
The current approach also makes it annoying to implement some modules because you can't do
xs = submodule.forward(xs)
. Which is very painful when the logic to find the first submodule to apply is complicated. Even forSequential
one has to do something likeThe text was updated successfully, but these errors were encountered: