Skip to content

Commit e58f6c6

Browse files
author
root
committed
Update on "extend torch.jit._overload to module methods"
Follow up to #23886, add the same overload api specified in PEP 484 to module methods to reduce the friction of adding method overloads that was brought up in #23266. The usage is: ``` @torch.jit.overload def add(self, y: int) -> int: ... @torch.jit.overload def add(self, y: float) -> float: ... def add(): ... ```
1 parent 99e7370 commit e58f6c6

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

torch/csrc/jit/script/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ void initJitScriptBindings(PyObject* module) {
751751
return script_compile_function(name, new_def, defaults, std::move(rcb));
752752
});
753753
m.def(
754-
"replace_overloaded_method_decl",
754+
"_replace_overloaded_method_decl",
755755
[](const Decl& overload_decl,
756756
const Def& implementation_def,
757757
const std::string& new_name) {

torch/jit/_recursive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def recursive_script(mod):
142142
for overload_fn, name in zip(overload_fns, names):
143143
torch.jit._check_no_signature(overload_fn)
144144
over_ast = torch.jit.get_jit_def(overload_fn, self_name="ScriptModule")
145-
new_ast = torch._C.replace_overloaded_method_decl(over_ast.decl(), orig_ast, name)
145+
new_ast = torch._C._replace_overloaded_method_decl(over_ast.decl(), orig_ast, name)
146146
_rcb = _jit_internal.createResolutionCallbackFromClosure(orig_fn)
147147
overload_stubs.append(torch.jit.ScriptMethodStub(_rcb, new_ast, overload_fn))
148148

0 commit comments

Comments
 (0)