-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[ao][sparsity] comsability for sparsity and QAT convert #74848
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
Conversation
Summary: WIP Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit 0cc5bdc (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
Summary: WIP Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to identify all parametrizations on the original module and then move them (and their associated parameters) to the new module. Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to identify all parametrizations on the original module and then move them (and their associated parameters) to the new module. Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to identify all parametrizations on the original module and then move them (and their associated parameters) to the new module. Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to identify all parametrizations on the original module and then move them (and their associated parameters) to the new module. Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to identify all parametrizations on the original module and then move them (and their associated parameters) to the new module. Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to identify all parametrizations on the original module and then move them (and their associated parameters) to the new module. Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 2153364 Pull Request resolved: #74848
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to identify all parametrizations on the original module and then move them (and their associated parameters) to the new module. Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations also added comments to the test code Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 57f9e42 Pull Request resolved: #74848
|
@HDCharles has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations also added comments to the test code Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D35240272](https://our.internmc.facebook.com/intern/diff/D35240272) [ghstack-poisoned]
|
@HDCharles has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations also added comments to the test code Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D35240272](https://our.internmc.facebook.com/intern/diff/D35240272) [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations also added comments to the test code Test Plan: python test/test_ao_sparsity.py TestComposability Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 53b5776 Pull Request resolved: #74848
|
@HDCharles has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations to test_nn.py and also added comments to the test code for composability. Test Plan: python test/test_ao_sparsity.py TestComposability python test/test_nn.py TestNN Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D35240272](https://our.internmc.facebook.com/intern/diff/D35240272) [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations to test_nn.py and also added comments to the test code for composability. Test Plan: python test/test_ao_sparsity.py TestComposability python test/test_nn.py TestNN Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 3bf0f42 Pull Request resolved: #74848
|
@HDCharles has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
lezcano
left a comment
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.
Just one more thing I forgot! Parametrisations may be many-to-one if the right-inverse returns more than one tensor. You can find examples of these in test_multiple_inputs_parametrization. Could you add a test for this case?
torch/nn/utils/parametrize.py
Outdated
|
|
||
| # need to initialize the param in to_module if it doesn't exist already | ||
| if not hasattr(to_module, parameter_name): | ||
| setattr(to_module, parameter_name, deepcopy(from_module.parametrizations[parameter_name].original)) |
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.
I believe this branch is not tested, is it? Furthermore, I believe it is incorrect. I think it should be
| setattr(to_module, parameter_name, deepcopy(from_module.parametrizations[parameter_name].original)) | |
| setattr(to_module, parameter_name, getattr(from_module, parameter_name)) |
Note that the original parameter may be a tuple if the parametrization is many-to-one, so setting it as an attribute would not be of much use.
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.
yeah, its tested in line 3282 in test_nn.py within test_transfer_parametrizations_and_params, I can split it into another test if you like, it looked like some of the other parametriation tests were grouped in some similar cases so I wasn't sure.
I added your suggested change, and added a test for the many-to-one case which works after some changes.
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations to test_nn.py and also added comments to the test code for composability. Test Plan: python test/test_ao_sparsity.py TestComposability python test/test_nn.py TestNN Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D35240272](https://our.internmc.facebook.com/intern/diff/D35240272) [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations to test_nn.py and also added comments to the test code for composability. Test Plan: python test/test_ao_sparsity.py TestComposability python test/test_nn.py TestNN Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D35240272](https://our.internmc.facebook.com/intern/diff/D35240272) [ghstack-poisoned]
|
@HDCharles has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
lezcano
left a comment
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.
LGTM CI abiding. Thank you for the many improvements and the testing on the parametrisations end!
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations to test_nn.py and also added comments to the test code for composability. Test Plan: python test/test_ao_sparsity.py TestComposability python test/test_nn.py TestNN Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D35240272](https://our.internmc.facebook.com/intern/diff/D35240272) [ghstack-poisoned]
Summary: The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to move the weight and bias and any associated paramerizations to the new module. This PR also adds tests for transfer_parametrizations_and_params and type_before_parametrizations to test_nn.py and also added comments to the test code for composability. Test Plan: python test/test_ao_sparsity.py TestComposability python test/test_nn.py TestNN Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 0cd91d0 Pull Request resolved: #74848
|
@HDCharles has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
|
@pytorchbot merge this (Initiating merge automatically since Phabricator Diff has merged) |
|
Hey @HDCharles. |
Summary: Pull Request resolved: #74848 The primary issue for enabling sparsity to work with QAT convert (unlike normal quantization convert) is that when the parametrized module undergoes the QAT convert, the parametrizations need to be maintained. If the parametrizations don't get transfered during the convert, the sparsifier would lose its connection to the model. In practice this was handled using the transfer_parametrizations_and_params function to identify all parametrizations on the original module and then move them (and their associated parameters) to the new module. Test Plan: python test/test_ao_sparsity.py TestComposability Imported from OSS Reviewed By: malfet Differential Revision: D35240272 fbshipit-source-id: 08d6a938d5919ba2dfd8490b1c768fafc5b179dd
Stack from ghstack (oldest at bottom):
Summary: The primary issue for enabling sparsity to work with QAT
convert (unlike normal quantization convert) is that when the
parametrized module undergoes the QAT convert, the parametrizations need
to be maintained. If the parametrizations don't
get transfered during the convert, the sparsifier would lose its
connection to the model. In practice this was handled using the
transfer_parametrizations_and_params function to move the weight and
bias and any associated paramerizations to the new module. This PR also adds
tests for transfer_parametrizations_and_params and type_before_parametrizations
to test_nn.py and also added comments to the test code for
composability.
Test Plan: python test/test_ao_sparsity.py TestComposability
python test/test_nn.py TestNN
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: D35240272