storch icon indicating copy to clipboard operation
storch copied to clipboard

requiresGrad lost when creating tensors from scalars or sequences

Open marcelluethi opened this issue 11 months ago • 1 comments

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 avatar Dec 22 '24 16:12 marcelluethi

@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.

sbrunk avatar Jan 05 '25 21:01 sbrunk