Fix SequenceEmpty dtype parameter ignored in eager mode#2949
Open
PratikWayase wants to merge 1 commit into
Open
Fix SequenceEmpty dtype parameter ignored in eager mode#2949PratikWayase wants to merge 1 commit into
PratikWayase wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
SequenceEmptydtype parameter being ignored in eager/trace mode by introducing a typed runtime representation for sequences. Fixes #1562.Changes
As noted by @gramalingam in the issue, the root cause is that we reuse Python lists for runtime sequence values, and when the list is empty, we cannot infer a suitable ONNX type. This PR implements the first proposed fix: using a runtime representation that combines a type with the value.
_TypedSequence, alistsubclass inonnxscript/_internal/typed_sequence.pythat preserves ONNX dtype information for empty sequencesBaseEvaluator.eval_opinonnxscript/_internal/evaluator.pyto wrapSequenceEmptyresults with_TypedSequenceusing the provideddtypeattribute (defaults toFLOATifNone)_onnxscript_to_numpy_valueinonnxscript/_internal/evaluator.pyto preserve the_TypedSequencewrapper (instead of downcasting to a plainlist) when preparing inputs for the ONNX runtimevalue_to_type_protoinonnxscript/_internal/utils.pyto extract the dtype from_TypedSequencewhen inferring the ONNX TypeProtoTests
Added OpInfo-style regression test
test_sequence_empty_preserves_dtypecovering:FLOAT16dtypeDOUBLEdtypeINT64dtypeAdditionally verified edge cases:
dtypeattribute (correctly defaults toFLOAT)SequenceInsertoperations on the same typed sequenceSequenceAton a typed sequenceFiles:
onnxscript/_internal/typed_sequence.py(new)onnxscript/_internal/evaluator.pyonnxscript/_internal/utils.pytests/eager_mode_test.pyValidation
python -m pytest tests/eager_mode_test.py -k "test_sequence_empty_preserves_dtype" -vPassed: