File tree Expand file tree Collapse file tree
modelopt/torch/_deploy/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818import base64
1919import inspect
2020import json
21+ import logging
2122import os
2223import shutil
2324import tempfile
24- from contextlib import nullcontext , suppress
25+ from contextlib import nullcontext
2526from typing import Any
2627
2728import onnx
6061
6162from ..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
6776def _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
You can’t perform that action at this time.
0 commit comments