Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

I tried to embed the soft rank into the pytorch model and loss function and the following error was reported. #16

@XiaoqiWang

Description

@XiaoqiWang
loss.backward()

File "E:\conda\lib\site-packages\torch_tensor.py", line 307, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
File "E:\conda\lib\site-packages\torch\autograd_init_.py", line 154, in backward
Variable._execution_engine.run_backward(
RuntimeError: Function NumpyOpWrapperBackward returned an invalid gradient at index 0 - expected type TensorOptions(dtype=float, device=cuda:0, layout=Strided, requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt)) but got TensorOptions(dtype=float, device=cpu, layout=Strided, requires_grad=false (default), pinned_memory=false (default), memory_format=(nullopt))

the forward part of the loss function is as follows:

def forward(self, preds, gt):
preds_rank = torch_ops.soft_rank(preds.unsqueeze(0)).float()
gt_rank = torch_ops.soft_rank(gt.unsqueeze(0)).float()

Looking forward to your reply.

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