Skip to content

Commit 2fb957d

Browse files
authored
workaround for Sequential when one cannot retrieve python source (#8048)
1 parent eb2f21f commit 2fb957d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

torch/jit/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,17 @@ class _ConstSequential(_ConstModuleList):
717717
def __init__(self, mods):
718718
super(_ConstSequential, self).__init__(mods._modules.values())
719719

720-
@script_method
721-
def forward(self, input):
722-
for m in self:
723-
input = m(input)
724-
return input
725-
720+
# we define the forward method via self.define rather than
721+
# making it a direct class member (with a @script) annotation
722+
# because, in optimized runtime environments where only .pyc files
723+
# are shipped, we cant retrieve the source code.
724+
# TODO: find a workaround for this and remove this hack
725+
self.define("""
726+
def forward(self, input):
727+
for m in self:
728+
input = m(input)
729+
return input
730+
""")
726731

727732
if not torch._C._jit_init():
728733
raise RuntimeError("JIT initialization failed")

0 commit comments

Comments
 (0)