Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2829,6 +2829,13 @@ def test_pytorch_jit_env_off(self):
except subprocess.CalledProcessError as e:
raise RuntimeError("Could not 'import torch' with PYTORCH_JIT=0")

def test_print_op_module(self):
# Issue #19351: python2 and python3 go through different paths.
# python2 returns '<module 'torch.ops' (built-in)>'
# python3 uses __file__ and return
# '<module 'torch.ops' from '/scratch/ailzhang/pytorch/torch/_ops.py'>'
s = str(torch.ops)
self.assertRegex(s, r'ops')

def execWrapper(code, glob, loc):
if PY2:
Expand Down
3 changes: 3 additions & 0 deletions torch/_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import contextlib
import ctypes
import os
import sys
import types

Expand Down Expand Up @@ -66,6 +67,8 @@ def __getattr__(self, op_name):


class _Ops(types.ModuleType):
__file__ = os.path.join(os.path.dirname(__file__), '_ops.py')

def __init__(self):
super(_Ops, self).__init__('torch.ops')
self.loaded_libraries = set()
Expand Down