-
Notifications
You must be signed in to change notification settings - Fork 249
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
[FX] Dynamic Shapes Support #3225
[FX] Dynamic Shapes Support #3225
Conversation
NNCFGraphEdge and NNCF algorithms expect the edge shape to be a Could you please show an example with a quantization of a dynamic model? Perhaps we can cover the case with less drastic change (using -1 as a shape dim, for example) |
I can add an exception for the case where the in_channel has a non-static . |
@anzr299, please check a two ways of dynamic shapes handling:
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reuse existing reference dot files? AFAIK they look identical
Test case have caught the issue with dynamic shape model here ynimmaga/executorch#26 |
@@ -196,7 +196,9 @@ def get_edge_params( | |||
else: | |||
tensor = source_node.meta["val"] | |||
if isinstance(tensor, torch.Tensor): | |||
tensor_shape = tuple(tensor.shape) | |||
tensor_shape = tuple(-1 if isinstance(i, torch.SymInt) else i for i in tensor.shape) | |||
if isinstance(tensor, torch.SymInt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isinstance(tensor, torch.SymInt): | |
elif isinstance(tensor, torch.SymInt): |
Co-authored-by: Alexander Dokuchaev <alexander.dokuchaev@intel.com>
### Changes Modify NNCF Graph Builder for FX backend to correctly get and insert the dynamic shapes into NNCFGraph ### Reason for changes To support quantization of Torch FX models exported with dynamic shapes ### Tests test is added to `tests/torch/fx/test_models.py` in test_quantized_models(). Currently only the synthetic transformer is tested because torch.export.dynamic_shapes.Dim.DYNAMIC is not supported in pytorch but is supported in upcoming releases. https://pytorch.org/tutorials/intermediate/torch_export_tutorial.html#constraints-dynamic-shapes `test_dynamic_edge()` is also added in `tests/torch/fx/test_models.py` to check that the tensor shape in NNCF Graph edge has values only of type int or str and not SymInt. --------- Co-authored-by: Alexander Dokuchaev <alexander.dokuchaev@intel.com>
Changes
Modify NNCF Graph Builder for FX backend to correctly get and insert the dynamic shapes into NNCFGraph
Reason for changes
To support quantization of Torch FX models exported with dynamic shapes
Tests
test is added to
tests/torch/fx/test_models.py
in test_quantized_models(). Currently only the synthetic transformer is tested because torch.export.dynamic_shapes.Dim.DYNAMIC is not supported in pytorch but is supported in upcoming releases. https://pytorch.org/tutorials/intermediate/torch_export_tutorial.html#constraints-dynamic-shapestest_dynamic_edge()
is also added intests/torch/fx/test_models.py
to check that the tensor shape in NNCF Graph edge has values only of type int or str and not SymInt.