Skip to content

Commit 101ca06

Browse files
committed
Accept torch's fake stand-in for a DeviceMesh in the fx splitter
Newer torch puts a DeviceMesh into the graph as a FakeScriptObject rather than the mesh itself. Three places in the splitter rejected it: make_input_proxy raised, so every node taking a mesh became a split reason, and the placeholder round-trip raised outright. Treat it as the opaque value it is. It is its own metadata, and the object it wraps is what the ops and the proxy check want, so hand that over when an input is needed.
1 parent 293fb59 commit 101ca06

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

thunder/dynamo/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from torch.utils.weak import TensorWeakRef
2020
from torch._guards import tracing, TracingContext
2121
from torch._subclasses.fake_tensor import DynamicOutputShapeException
22+
from torch._library.fake_class_registry import FakeScriptObject
2223

2324
from torch._inductor import list_mode_options
2425

@@ -305,6 +306,11 @@ def make_input_proxy(arg_node):
305306
)
306307
elif isinstance(example_value, torch.types.py_sym_types) and example_value.node.has_hint():
307308
return proxy(example_value.node.hint)
309+
elif isinstance(example_value, FakeScriptObject):
310+
# Newer torch puts a DeviceMesh into the graph as a fake stand-in. We are only
311+
# checking here whether thunder can run the op, and the ops that take one want
312+
# the mesh itself, so hand over the object the fake wraps.
313+
return example_value.real_obj
308314
else:
309315
# NOTE - This will be caught and be part of the SplitReason.
310316
raise TypeError(
@@ -694,6 +700,9 @@ def example_input_meta_to_input(meta):
694700
return _create_random_tensor_from_tensor_metadata(meta)
695701
elif isinstance(meta, (int, bool, float)):
696702
return meta
703+
elif isinstance(meta, FakeScriptObject):
704+
# Carried through as itself; the object it stands in for is what an input wants.
705+
return meta.real_obj
697706
elif isinstance(meta, Sequence):
698707
return tuple(example_input_meta_to_input(i) for i in meta)
699708
else:
@@ -707,6 +716,10 @@ def input_to_example_input_meta(input):
707716
return input
708717
elif isinstance(input, torch.types.py_sym_types):
709718
return input.node.hint
719+
elif isinstance(input, FakeScriptObject):
720+
# Newer torch passes a DeviceMesh in as a fake stand-in. There is no metadata to take apart,
721+
# so it is its own metadata and example_input_meta_to_input unwraps it again.
722+
return input
710723
elif isinstance(input, Sequence):
711724
return tuple(input_to_example_input_meta(i) for i in input)
712725
else:

0 commit comments

Comments
 (0)