Skip to content

requiresGrad lost when creating tensors from scalars or sequences #80

@marcelluethi

Description

@marcelluethi

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions