Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitefaa65d

Browse files
Elias Ellisonfacebook-github-bot
Elias Ellison
authored andcommitted
resolve ignored module method type annotations (#26683)
Summary:Previously we weren't passing an rcb around, causing NamedTuples with unused methods to fail.Pull Requestresolved:#26683Differential Revision: D17539656Pulled By: eellisonfbshipit-source-id: 50091e78eea5fa3a22b4655b65384eee47a1c9d6
1 parent5e5cbce commitefaa65d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

‎test/test_jit.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,21 @@ def fn2():
34453445

34463446
FileCheck().check("NamedTuple").run(fn2.graph)
34473447

3448+
class MyMod(torch.nn.Module):
3449+
def __init__(self):
3450+
super(MyMod, self).__init__()
3451+
3452+
@torch.jit.unused
3453+
def fn(self):
3454+
# type: () -> MyTuple
3455+
return MyTuple(1)
3456+
3457+
def forward(self, x):
3458+
return self.fn()
3459+
3460+
mod = torch.jit.script(MyMod())
3461+
FileCheck().check_dag("NamedTuple").check_dag("Exception").run(mod.forward.graph)
3462+
34483463
def test_inherit_method(self):
34493464
class A(torch.jit.ScriptModule):
34503465
def __init__(self):

‎torch/csrc/jit/script/python_sugared_value.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,12 @@ std::shared_ptr<SugaredValue> toSugaredValue(
660660
if (auto callee =as_function(compiled_fn)) {
661661
return std::make_shared<FunctionValue>(*callee);
662662
}
663+
}
664+
665+
py::bool_ isMethod =py::module::import("inspect").attr("ismethod")(obj);
666+
// methods here have been explicitly annotated to not be compiled,
667+
// so they do not have the same overload and compile checks as for functions
668+
if (isFunction || isMethod) {
663669
auto rcb =py::module::import("torch.jit").attr("_gen_rcb")(obj,0);
664670
return std::make_shared<PythonValue>(obj, rcb);
665671
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp