storch
storch copied to clipboard
requiresGrad lost when creating tensors from scalars or sequences
Hello
I just stumbled upon the following problem. When creating a tensor from a scalar or sequence, with requiresGrad=true, the value of the argument is lost. The following code exposes the problem
val x = Tensor(Seq(1.0f), requiresGrad = true)
assert(x.requiresGrad == true)
Setting the parameter explicitly with x.requiresGrad(true) works.
I looked into the problem but could not spot anything wrong. It seems to get lost in this line
The problem persists when using the latest pytorch version (2.5.1). Does anybody know what could be the problem?
@marcelluethi thanks for reporting. I'm not sure yet either. We could move the call to requiresGrad into in the conversion as a workaround for now.