Skip to content

Commit d2f44ea

Browse files
sidt-metapytorchmergebot
authored andcommitted
[Export] Support aten.full.default and aten.full_like.default (pytorch#130639)
Summary: Add operator tests for full & full_like operators Test Plan: Rerun kernel test using ``` buck2 run //glow/fba/tests:run_kernel mode/dev -- --kernel splat --config "input=1;dtype=fp32;fill_value=42.0" -tl_time ``` {F1752274071} Operator tests ``` buck2 run mode/{opt,inplace} //caffe2/torch/fb/test_library:afg_operator_test -- -k __full__ ``` {F1752340913} Differential Revision: D59593849 Pull Request resolved: pytorch#130639 Approved by: https://github.com/StellarrZ
1 parent f272e0a commit d2f44ea

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

torch/fx/experimental/const_fold.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ def mod_partition(node: torch.fx.Node):
198198

199199
split = split_module(mod_traced, module, mod_partition)
200200

201-
const_gm, non_const_gm = split.submod_0, split.submod_1
202201
const_mod_name, non_const_mod_name = "submod_0", "submod_1"
202+
# Safely get submod_1 in case there are no non-const nodes
203+
const_gm, non_const_gm = split.submod_0, getattr(split, non_const_mod_name, None)
203204

204205
# The module that a call_module node refers to gets copied to submodules during split.
205206
# The path to the module also gets inlined, i.e. mod.a.b -> mod_a_b. Here we need to
206207
# attach inlined modules to `split` as it's the owning module now.
207-
for node in non_const_gm.graph.nodes:
208+
for node in non_const_gm.graph.nodes if non_const_gm else []:
208209
if node.op == "call_module":
209210
setattr(split, node.target, getattr(non_const_gm, node.target))
210211
for node in const_gm.graph.nodes:
@@ -276,10 +277,11 @@ def mod_partition(node: torch.fx.Node):
276277

277278
split.graph.eliminate_dead_code()
278279

279-
# Finally, inline the non-constant submod into the split submod. This is so that the
280-
# original caller who may have passed in a graph module will get back out a graph
281-
# module whose graph is traced to the same granularity.
282-
_inline_module(split, non_const_mod_name)
280+
# Finally, inline the non-constant submod (if it exists) into the split submod.
281+
# This is so that the original caller who may have passed in a graph module will
282+
# get back out a graph module whose graph is traced to the same granularity.
283+
if hasattr(split, non_const_mod_name):
284+
_inline_module(split, non_const_mod_name)
283285

284286
return FoldedGraphModule(
285287
split,

0 commit comments

Comments
 (0)