Skip to content

Conversation

justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Apr 11, 2025

Always assign a Graph object to the node's graph.

Fix #2181

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

onnxscript/ir/passes/common/constant_manipulation.py:54

  • [nitpick] The type assertion for node.graph was removed, which may allow unintended types if the invariant is not otherwise enforced. Consider documenting or validating that node.graph is always a Graph as it is set in _core.py.
assert isinstance(node.graph, ir.Graph)

Copy link

codecov bot commented Apr 11, 2025

❌ 18 Tests Failed:

Tests completed Failed Passed Skipped
15423 18 15405 2898
View the top 3 failed test(s) by shortest run time
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0041_test_argmax_keepdims_example_select_last_index
Stack Traces | 0.003s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_argmax_keepdims_example_select_last_index'

The above exception was the direct cause of the following exception:
.nox\test\lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_argmax_keepdims_example_select_last_index' (e=No module named 'tests.onnx_backend_test_code.test_argmax_keepdims_example_select_last_index') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_argmax_keepdims_example_select_last_index.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_argmax_keepdims_example_select_last_index.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import FLOAT, INT64
E   from onnxscript.onnx_opset import opset13
E   
E   @script()
E   def bck_test_argmax_keepdims_example_select_last_index(data: FLOAT[2,2]) -> (INT64[2,1]):
E       result = opset13.ArgMax(data, axis=1, keepdims=1, select_last_index=1)
E       return result
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0173_test_cast_DOUBLE_to_FLOAT
Stack Traces | 0.003s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_cast_DOUBLE_to_FLOAT'

The above exception was the direct cause of the following exception:
.nox\test\lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_cast_DOUBLE_to_FLOAT' (e=No module named 'tests.onnx_backend_test_code.test_cast_DOUBLE_to_FLOAT') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_cast_DOUBLE_to_FLOAT.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_cast_DOUBLE_to_FLOAT.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import DOUBLE, FLOAT
E   from onnxscript.onnx_opset import opset21
E   
E   @script()
E   def bck_test_cast_DOUBLE_to_FLOAT(input: DOUBLE[3,4]) -> (FLOAT[3,4]):
E       output = opset21.Cast(input, to=1)
E       return output
onnxscript.backend.onnx_export_test.TestOnnxBackEnd::test_export2python_produces_correct_onnx_script_model_0586_test_log_example
Stack Traces | 0.003s run time
onnxscript\backend\onnx_export_test.py:137: in extract_functions
    mod = importlib.import_module(import_name)
C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.onnx_backend_test_code.test_log_example'

The above exception was the direct cause of the following exception:
.nox\test\Lib\site-packages\parameterized\parameterized.py:620: in standalone_func
    return func(*(a + p.args), **p.kwargs, **kw)
onnxscript\backend\onnx_export_test.py:271: in test_export2python_produces_correct_onnx_script_model
    functions = extract_functions(backend_test.name, code, self.test_folder)
onnxscript\backend\onnx_export_test.py:139: in extract_functions
    raise AssertionError(
E   AssertionError: Unable to import 'tests.onnx_backend_test_code.test_log_example' (e=No module named 'tests.onnx_backend_test_code.test_log_example') (file: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_log_example.py', absolute path: 'D:\\a\\onnxscript\\onnxscript\\tests\\onnx_backend_test_code\\test_log_example.py', current folder: D:\a\onnxscript\onnxscript
E   ---- CONTENT --
E   import numpy
E   from onnx import TensorProto
E   from onnx.helper import make_tensor
E   from onnxscript import script, external_tensor
E   from onnxscript.values import Opset
E   from onnxscript.onnx_types import FLOAT
E   from onnxscript.onnx_opset import opset13
E   
E   @script()
E   def bck_test_log_example(x: FLOAT[2]) -> (FLOAT[2]):
E       y = opset13.Log(x)
E       return y

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@justinchuby justinchuby requested a review from gramalingam April 13, 2025 00:56
@justinchuby justinchuby enabled auto-merge (squash) April 14, 2025 16:55

# Add the node to the graph if graph is specified
if self._graph is not None:
self._graph.append(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how moving these up make any difference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it closer to were graph is created so it is more readable.

@justinchuby justinchuby merged commit ef8e889 into main Apr 14, 2025
20 of 27 checks passed
@justinchuby justinchuby deleted the justinchu/node-graph branch April 14, 2025 22:17
justinchuby added a commit that referenced this pull request Apr 15, 2025
Implement model.graphs() as a way to retrieve the main graph and all
subgraphs of it in the model.

Given

(1) how useful the method is
(2) I couldn't find an appropriate name for it in `traversal.py`
(3) Users familiar with onnxruntime optimization tools expect this
method. In PyTorch a similar `modules()` method exists.

I created this method as a core method instead of an iterator in
`traversal.py`.

Depends on #2183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: IR Intermediate representation
Projects
Development

Successfully merging this pull request may close these issues.

[IR] Reconcile the graph attribute in ir.Node
4 participants