[Dynamic Shape] More correctness guards#276
Merged
yaoyaoding merged 23 commits intohidet-org:mainfrom Jun 16, 2023
Merged
Conversation
Contributor
Author
|
Moreover, there is a subtle bug where the symbol registry gets rewritten multiple times if there exists inputs which promises the same shape, but runtime inputs have different shapes. So added a check for that as well. |
Contributor
Author
|
I have no idea why the gpt2 test passed before, there was a similar error with the llama implementation, where the compiled model reinterpreted an int64 tensor as an int32 tensor, producing random outputs. |
yaoyaoding
reviewed
Jun 13, 2023
Comment on lines
+154
to
+177
| for i, (traced, new) in enumerate(zip(self.meta_data.inputs, inputs)): | ||
| if ir.data_type(traced.dtype) != new.dtype: | ||
| raise RuntimeError( | ||
| f"dtype mismatch at arg {i} between original: {traced.dtype} and new: {new.dtype}" | ||
| ) | ||
| traced_shape = traced.shape | ||
| concrete_shape = new.shape | ||
| if len(traced_shape) != len(concrete_shape): | ||
| raise RuntimeError( | ||
| f"Rank of input {i} not equal to original. ({len(concrete_shape)} vs. {len(traced_shape)})" | ||
| ) | ||
| for j, (orig_shape, new_shape) in enumerate(zip(traced_shape, concrete_shape)): | ||
| if isinstance(orig_shape, int) and orig_shape != new_shape: | ||
| raise RuntimeError( | ||
| f'shape mismatch at dimension {j}, original: \ | ||
| {orig_shape} vs. new: {new_shape}' | ||
| ) | ||
| elif orig_shape not in symbol_map: | ||
| symbol_map[orig_shape] = new_shape | ||
| elif symbol_map[orig_shape] != new_shape: | ||
| raise RuntimeError( | ||
| f"There exists multiple instances of the same symbol {orig_shape}\ | ||
| with different values in inputs (ex: {symbol_map[orig_shape]} and {new_shape})" | ||
| ) |
Member
There was a problem hiding this comment.
Same logic as the CompiledGraph. Consider implement as a utility function and put it at the same module of TensorSignature.
Co-authored-by: Yaoyao Ding <dingyaoyao.cs@gmail.com>
Co-authored-by: Yaoyao Ding <dingyaoyao.cs@gmail.com>
Co-authored-by: Yaoyao Ding <dingyaoyao.cs@gmail.com>
Co-authored-by: Yaoyao Ding <dingyaoyao.cs@gmail.com>
Member
|
Thanks @Aalanli ! |
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.
Add support for dynamic shape assertions in the C++ runtime.
Further, add shape and dtype check for python runtime. With this being enabled by default.