Skip to content

Commit 15411b8

Browse files
BowenBaopytorchmergebot
authored andcommitted
[ONNX] Make unsupported node analysis result deterministic (#105231)
Replace `Set` with `Dict` for node.target to keep insertion order. Fixes #105200 Pull Request resolved: #105231 Approved by: https://github.com/thiagocrepaldi
1 parent d438b99 commit 15411b8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

torch/onnx/_internal/fx/analysis/unsupported_nodes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from __future__ import annotations
22

33
import dataclasses
4-
from typing import Dict, List, Set
4+
from typing import Dict, List
55

66
import torch
77
from torch.onnx._internal.fx import _pass, diagnostics
88

99

1010
@dataclasses.dataclass
1111
class UnsupportedFxNodesAnalysisResult(_pass.AnalysisResult):
12-
unsupported_op_to_target_mapping: Dict[str, Set[str]]
12+
unsupported_op_to_target_mapping: Dict[str, Dict[str, None]]
1313

1414

1515
class UnsupportedFxNodesAnalysis(_pass.Analysis):
@@ -25,7 +25,7 @@ def _lint(
2525
return
2626

2727
normalized_op_targets_map = {
28-
op: [str(target) for target in targets]
28+
op: list(targets.keys())
2929
for op, targets in analysis_result.unsupported_op_to_target_mapping.items()
3030
}
3131

@@ -63,12 +63,12 @@ def analyze(
6363
except diagnostics.RuntimeErrorWithDiagnostic as e:
6464
unsupported_nodes.append(node)
6565

66-
op_to_target_mapping: Dict[str, Set[str]] = {}
66+
op_to_target_mapping: Dict[str, Dict[str, None]] = {}
6767

6868
for node in unsupported_nodes:
6969
op = node.op
7070
target = node.target
71-
op_to_target_mapping.setdefault(op, set()).add(str(target))
71+
op_to_target_mapping.setdefault(op, {}).setdefault(str(target), None)
7272

7373
analysis_result = UnsupportedFxNodesAnalysisResult(op_to_target_mapping)
7474
self._lint(analysis_result, diagnostic_level)

0 commit comments

Comments
 (0)