mlverse / torch

R Interface to Torch
https://torch.mlverse.org
Other
483 stars 66 forks source link

Calling `$detach()` discards attributes #1136

Closed sebffischer closed 4 months ago

sebffischer commented 4 months ago
library(torch)

x = nn_parameter(torch_randn(1))
class(x)
#> [1] "torch_tensor" "R7"           "nn_parameter"
class(x$detach())
#> [1] "torch_tensor" "R7"

Created on 2024-02-12 with reprex v2.0.2

dfalbel commented 4 months ago

We could use a similar approach to what we did for clone, right?

sebffischer commented 4 months ago

Yes, I will PR it. Just noted it down here so it won't be forgotten and I did not want to include even more changes in the cloning PR.