Skip to content

Error tracing custom autograd.Function #32822

@twostay

Description

@twostay

🐛 Bug

I got an error when I tried to use jit to trace my autograd Function. In previous Pytorch versions(1.1.0), this works, but recently I updated to 1.4.0, and this stopped working. I'm not exactly sure which version exactly did this stopped working.

To Reproduce

Steps to reproduce the behavior:

  1. Make sure you have Pytorch1.4.0
  2. Make a custom autograd Function. In my case, I'm using this one
class raw(autograd.Function):
    @staticmethod
    def forward(ctx, inp):
        ctx.a = (inp * inp + 1).reciprocal()
        ctx.b = ctx.a.sqrt()
        return inp * ctx.b

    @staticmethod
    def backward(ctx, grad_output):
        return grad_output * ctx.a * ctx.b
  1. Trace this Function.
from torch import jit
jit.trace(raw.apply, example_inputs=tc.randn(1))
  1. The error should orginate from the line of tracing and look like this:
......................
    jit.trace(raw.apply, example_inputs=tc.randn(1))
  File "...\Python37\lib\site-packages\torch\jit\__init__.py", line 903, in trace
    name = _qualified_name(func)
  File "...\Python37\lib\site-packages\torch\_jit_internal.py", line 696, in _qualified_name
    "__module__ can't be None.".format(name))
RuntimeError: Could not get qualified name for class 'apply': __module__ can't be None.

Expected behavior

I expect the tracing to work like how the previous versions did.

Environment

Please copy and paste the output from our
environment collection script
(or fill out the checklist below manually).

You can get the script and run it with:

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

PyTorch version: 1.4.0+cpu
Is debug build: No
CUDA used to build PyTorch: None

OS: Microsoft Windows 10 Home
GCC version: Could not collect
CMake version: Could not collect

Python version: 3.7
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Versions of relevant libraries:
[pip3] numpy==1.16.3
[pip3] torch==1.4.0+cpu
[pip3] torchvision==0.5.0+cpu
[conda] Could not collect

Additional context

I'm bad at using Github so if I missed something please tell me :)

cc @suo

Metadata

Metadata

Assignees

No one assigned

    Labels

    oncall: jitAdd this issue/PR to JIT oncall triage queuetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions