Skip to content

Use the new IR for building graphs in torchlib #1354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Apr 19, 2024

Conversation

justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Apr 9, 2024

Use the new IR for building graphs in torchlib. I created a flag TORCHLIB_EXPERIMENTAL_USE_IR to control the feature. When enabled the classes in graph_building will be swapped to use the new IR. The exporter should see the same interfaces and not feel anything. After the transition period we can decide where this should live.

Set TORCHLIB_EXPERIMENTAL_USE_IR=1 to enable this feature.

Fix #997

Copy link

codecov bot commented Apr 9, 2024

Codecov Report

Attention: Patch coverage is 65.47619% with 116 lines in your changes are missing coverage. Please review.

Project coverage is 77.17%. Comparing base (f06f303) to head (6fcd30e).

Files Patch % Lines
...ibs/torch_lib/graph_building/_graph_building_ir.py 67.21% 84 Missing and 16 partials ⚠️
onnxscript/ir/_naming_authority.py 30.00% 14 Missing ⚠️
onnxscript/_internal/runtime_typing.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1354      +/-   ##
==========================================
- Coverage   77.26%   77.17%   -0.09%     
==========================================
  Files         209      212       +3     
  Lines       22533    22867     +334     
  Branches     3806     3887      +81     
==========================================
+ Hits        17410    17648     +238     
- Misses       4418     4502      +84     
- Partials      705      717      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

lintrunner found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Copy link

github-actions bot commented Apr 9, 2024

Test Results

     28 files  +     2      28 suites  +2   3h 21m 9s ⏱️ - 14m 28s
  7 135 tests + 1 300   3 974 ✅ +    17    1 972 💤 +    98   1 188 ❌ + 1 184   1 🔥 + 1 
415 865 runs   - 55 782  61 182 ✅  - 14 017  317 894 💤  - 78 550  36 777 ❌ +36 773  12 🔥 +12 

For more details on these failures and errors, see this check.

Results for commit d28b8d4. ± Comparison against base commit 9ea1d1c.

This pull request removes 68 and adds 1368 tests. Note that renamed tests count towards both.
onnxscript.function_libs.torch_lib.graph_building_test.TestModelSaving ‑ test_experimental_function_value_info_are_stored_in_graph_value_info
onnxscript.function_libs.torch_lib.graph_building_test.TestModelSaving ‑ test_input_output_and_initializer_are_not_stored_in_value_info
onnxscript.function_libs.torch_lib.graph_building_test.TestModelSaving ‑ test_save_initializer_to_files_for_large_model
onnxscript.function_libs.torch_lib.graph_building_test.TestTorchScriptGraph ‑ test_add_initializer_allows_adding_the_same_tensor_twice_using_same_name
onnxscript.function_libs.torch_lib.graph_building_test.TestTorchScriptGraph ‑ test_add_initializer_raises_when_the_same_name_used_for_different_tensors
onnxscript.function_libs.torch_lib.graph_building_test.TestTorchScriptTracingEvaluator ‑ test_add_input_with_optionaltype_does_not_raise_torch_internal_error
onnxscript.function_libs.torch_lib.graph_building_test.TestTorchScriptTracingEvaluator ‑ test_model_local_function_constructed_by_traced_graph_is_same_as_compiled_graph
onnxscript.function_libs.torch_lib.graph_building_test.TestTorchScriptTracingEvaluator ‑ test_traced_constant_op_is_same_as_compiled_graph
onnxscript.function_libs.torch_lib.graph_building_test.TestTorchScriptTracingEvaluator ‑ test_traced_graph_on_single_node_is_same_as_compiled_graph
onnxscript.function_libs.torch_lib.graph_building_test.TestTorchScriptTracingEvaluator ‑ test_traced_graph_on_single_node_multi_output_is_same_as_compiled_graph
…
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0000_test_abs
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0001_test_acos
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0002_test_acosh
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0003_test_acosh_example
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0004_test_acos_example
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0005_test_adagrad
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0006_test_adagrad_multiple
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0007_test_adam
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0008_test_adam_multiple
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0009_test_add
…
This pull request removes 1 skipped test and adds 335 skipped tests. Note that renamed tests count towards both.
onnxscript.function_libs.torch_lib.graph_building_test.TestTorchScriptTracingEvaluator ‑ test_traced_graph_on_single_node_multi_output_is_same_as_compiled_graph
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0005_test_adagrad
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0006_test_adagrad_multiple
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0007_test_adam
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0008_test_adam_multiple
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0011_test_add_uint8
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0020_test_ai_onnx_ml_array_feature_extractor
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0021_test_ai_onnx_ml_binarizer
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0022_test_ai_onnx_ml_label_encoder_string_int
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0023_test_ai_onnx_ml_label_encoder_string_int_no_default
onnxscript.backend.onnx_export_test.TestOnnxBackEnd ‑ test_export2python_produces_correct_onnx_script_model_0024_test_ai_onnx_ml_label_encoder_tensor_mapping
…

♻️ This comment has been updated with latest results.

@justinchuby justinchuby added module: torchlib Related to the torch/aten function lib in development module: IR Intermediate representation labels Apr 9, 2024
@justinchuby justinchuby force-pushed the justinchu/ir-build-graph branch from 21b7c4e to ccdca53 Compare April 9, 2024 18:47
@justinchuby justinchuby force-pushed the justinchu/ir-build-graph branch from 9f1f36f to 529801f Compare April 9, 2024 23:56
@justinchuby justinchuby changed the title [WIP] Use the new IR for building graphs in torchlib Use the new IR for building graphs in torchlib Apr 12, 2024
@justinchuby justinchuby marked this pull request as ready for review April 12, 2024 04:21
@justinchuby justinchuby marked this pull request as draft April 12, 2024 04:22
return _ONNX_DTYPE_TO_TORCH[dtype]


class TorchScriptTensor(ir.Value, onnxscript_tensor.Tensor):

Check warning

Code scanning / CodeQL

`__eq__` not overridden when adding attributes Warning

The class 'TorchScriptTensor' does not override
'__eq__'
, but adds the new attribute
_is_complex
.
The class 'TorchScriptTensor' does not override
'__eq__'
, but adds the new attribute
_concrete_value
.
The class 'TorchScriptTensor' does not override
'__eq__'
, but adds the new attribute _device.
@justinchuby justinchuby marked this pull request as ready for review April 17, 2024 16:42
Copy link
Contributor

@thiagocrepaldi thiagocrepaldi left a comment

Choose a reason for hiding this comment

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

Overall LGTM. The TorchScript naming should go away, though :)

Maybe some docstrings for both graph_building/__init__.py and ir/__init__.py exaplining the goal of each module, the basic design idea/mechanics would help a lot the hand off to pytorch and new comers that start on the project

@justinchuby
Copy link
Collaborator Author

justinchuby commented Apr 19, 2024

The TorchScript naming should go away

Absolutely. We need the exporter to decide how it wants to interface with the IR and move away from referencing this object. Then we can remove this class

@justinchuby
Copy link
Collaborator Author

Maybe some docstrings for both graph_building/__init__.py and ir/__init__.py exaplining the goal of each module, the basic design idea/mechanics would help a lot the hand off to pytorch and new comers that start on the project

I added that to graph_building/__init__.py. I will improve docs to the ir in a separate PR.

@justinchuby justinchuby merged commit 63f3809 into main Apr 19, 2024
35 of 41 checks passed
@justinchuby justinchuby deleted the justinchu/ir-build-graph branch April 19, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: IR Intermediate representation module: torchlib Related to the torch/aten function lib in development
Projects
Development

Successfully merging this pull request may close these issues.

Remove dependence on JitScalarType
2 participants