Skip to content

Commit 93717b2

Browse files
authored
Use default FakeTensorMode when calling module without input (pytorch#16222)
Before, _ExportPassBase set self.tracer.fake_tensor_mode to a default value, but didn't use it when tracing. This caused operators that only have fake tensor implementations to crash. Signed-off-by: Erik Lundell <erik.lundell@arm.com>
1 parent e63b441 commit 93717b2

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

‎backends/arm/test/ops/test_cond.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ def test_cond_tosa_FP(case: Callable[[], tuple[torch.nn.Module, tuple]]):
238238
"case",
239239
test_cases,
240240
xfails={
241-
"zero_args_one_output": "Since the submodules have no input, the tracer fails finding a fake tensor mode,"
242-
" and traces the graph with real tensors, which tosa.RESCALE can't handle.",
243241
"one_arg_and_scalar_one_output": "Incorrect quantization on the scalar.",
244242
"nested_one_arg_one_output": "Node submodule_0 target submodule_0 references nonexistent attribute submodule_0",
245243
},

‎exir/pass_base.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2025 Arm Limited and/or its affiliates.
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
@@ -632,14 +633,13 @@ def call(self, graph_module: fx.GraphModule) -> PassResult:
632633
), "Multiple fake tensor mode detected."
633634
fake_tensor_mode = i.fake_mode
634635
if fake_tensor_mode is None:
635-
self.tracer.fake_tensor_mode = FakeTensorMode(allow_non_fake_inputs=True)
636-
fake_tensor_mode = nullcontext() # type: ignore[assignment]
636+
fake_tensor_mode = FakeTensorMode(allow_non_fake_inputs=True)
637637
dispatcher_mode = nullcontext() # type: ignore[assignment]
638638
else:
639639
fake_tensor_mode.allow_non_fake_inputs = True
640-
self.tracer.fake_tensor_mode = fake_tensor_mode
641640
dispatcher_mode = enable_python_dispatcher() # type: ignore[assignment]
642-
self.fake_tensor_mode = self.tracer.fake_tensor_mode
641+
self.tracer.fake_tensor_mode = fake_tensor_mode
642+
self.fake_tensor_mode = fake_tensor_mode
643643

644644
with fake_tensor_mode, dispatcher_mode: # type: ignore[assignment, union-attr]
645645
result = self.call_submodule(graph_module, tuple(inputs))

0 commit comments

Comments
 (0)