Skip to content

Commit e223a2e

Browse files
committed
Add details about monkeypatch
Signed-off-by: ajrasane <131806219+ajrasane@users.noreply.github.com>
1 parent f6ce7b3 commit e223a2e

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

modelopt/torch/_deploy/utils/torch_onnx.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import base64
1919
import inspect
2020
import json
21+
import logging
2122
import os
2223
import shutil
2324
import tempfile
24-
from contextlib import nullcontext, suppress
25+
from contextlib import nullcontext
2526
from typing import Any
2627

2728
import onnx
@@ -60,13 +61,26 @@
6061

6162
from ..utils.onnx_optimizer import Optimizer
6263

63-
# Monkey-patch to fix onnxconverter_common bug where downstream_node is a list
64+
# Monkey-patch for onnxconverter_common bug in remove_unnecessary_cast_node():
65+
# cast_node_downstream_dict stores either a single node or a list of nodes, but the
66+
# downstream-node handling at lines ~770/787 always does `downstream_node.input`,
67+
# which raises AttributeError("'list' object has no attribute 'input'") when the
68+
# value is a list (i.e. a Cast output feeds multiple consumers).
69+
# TODO: Remove this patch once onnxconverter-common ships a fix.
70+
# Upstream issue: https://github.com/microsoft/onnxconverter-common/issues/261
6471
_original_remove_unnecessary_cast_node = _f16_module.remove_unnecessary_cast_node
6572

73+
_logger = logging.getLogger(__name__)
74+
6675

6776
def _patched_remove_unnecessary_cast_node(graph):
68-
with suppress(AttributeError):
77+
try:
6978
_original_remove_unnecessary_cast_node(graph)
79+
except AttributeError as e:
80+
if "'list' object has no attribute 'input'" in str(e):
81+
_logger.debug("Skipping remove_unnecessary_cast_node due to known upstream bug: %s", e)
82+
else:
83+
raise
7084

7185

7286
_f16_module.remove_unnecessary_cast_node = _patched_remove_unnecessary_cast_node

0 commit comments

Comments
 (0)