Skip to content

Commit a9da19c

Browse files
rascaniclaude
andauthored
Guard node.graph.owning_module against None for mypy (pytorch#20792)
### Summary torch 2.13.0 types torch.fx.Graph.owning_module as Optional[GraphModule], which surfaced two latent lintrunner-mypy errors on unchanged code. The lint job installs torch unpinned, so this began failing on trunk once a run resolved a torchvision compatible with torch 2.13.0 (earlier runs were silently downgraded to 2.12.1, masking the errors). Guard owning_module for None (and narrow node.target to str in the arm pass) before use. This also hardens both call sites against a genuinely absent owning module at runtime. cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ff927c8 commit a9da19c

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

backends/arm/_passes/arm_pass_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@
4343
def is_submodule_node(node: torch.fx.Node):
4444
if node.op not in ("get_attr", "placeholder"):
4545
return False
46+
owning_module = node.graph.owning_module
47+
if owning_module is None or not isinstance(node.target, str):
48+
return False
4649
try:
47-
node.graph.owning_module.get_submodule(node.target)
50+
owning_module.get_submodule(node.target)
4851
except AttributeError:
4952
return False
5053
return True

backends/cortex_m/quantizer/pattern_matcher.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def _validate_match(
6969
return PatternMatchResult(match, False, self.REJECT_PREVIOUSLY_ANNOTATED)
7070

7171
# Reject match if it contains a node that has an input which is too large to be quantized
72-
if any(_is_large_scalar(node, node.graph.owning_module) for node in match):
72+
owning_module = match[0].graph.owning_module if match else None
73+
if owning_module is not None and any(
74+
_is_large_scalar(node, owning_module) for node in match
75+
):
7376
return PatternMatchResult(match, False, self.REJECT_LARGE_SCALAR)
7477

7578
if all(node.op in ("placeholder", "output") for node in match):

0 commit comments

Comments
 (0)