Skip to content

Conversation

@supriyar
Copy link
Contributor

@supriyar supriyar commented Sep 16, 2020

Stack from ghstack:

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D23746821

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 16, 2020
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: e1275f7
Pull Request resolved: #44846
@supriyar supriyar requested review from jerryzh168, qizzzh, radkris-git and vkuzo and removed request for radkris-git September 16, 2020 23:12
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 17, 2020
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 296c73e
Pull Request resolved: #44846
@dr-ci
Copy link

dr-ci bot commented Sep 17, 2020

💊 CI failures summary and remediations

As of commit efc434f (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).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 49 times.

@codecov
Copy link

codecov bot commented Sep 18, 2020

Codecov Report

❗ No coverage uploaded for pull request base (gh/supriyar/181/base@b9633ff). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@                   Coverage Diff                   @@
##             gh/supriyar/181/base   #44846   +/-   ##
=======================================================
  Coverage                        ?   68.07%           
=======================================================
  Files                           ?      396           
  Lines                           ?    51293           
  Branches                        ?        0           
=======================================================
  Hits                            ?    34920           
  Misses                          ?    16373           
  Partials                        ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9633ff...efc434f. Read the comment docs.

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 18, 2020
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 923da1a
Pull Request resolved: #44846
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 18, 2020
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 8e69ddd
Pull Request resolved: #44846

# save state_dict of model
import io
obs_dict = torch.quantization.get_observer_state_dict(model)
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently we seem to be doing this only for activation observers. As we move to QAT, we will need similar functionality, but we will need to consider weight fake-quants too. Is there a plan to add weight observers to the state dict?

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 21, 2020
…line with a title. Use 1 line only, 67 chars or less>

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict
python test/test_quantization.py TestQuantizeJitPasses.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 63d3db8
Pull Request resolved: #44846
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 22, 2020
…line with a title. Use 1 line only, 67 chars or less>

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict
python test/test_quantization.py TestQuantizeJitPasses.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: df483ce
Pull Request resolved: #44846
missing_keys, unexpected_keys, error_msgs)

@torch.jit.export
def _load_from_state_dict_script(self, state_dict: Union[Dict[str, torch.Tensor], Dict[str, torch.Tensor]],
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems to call _load_from_state_dict, just curious on what would break if this function wasn't there? I might be missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that without this, the call to load_from_state_dict was calling the one defined in module.py. Once we script the model we lose access to the overridden load_from_state_dict so we need to call a different fn here to get around it.

_is_observer_script_module(module, "torch.quantization.observer.MovingAveragePerChannelMinMaxObserver")
return False

def get_observer_state_dict(mod):
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts about making most of these FB-only, since the use case is pretty specific? Or are there OSS needs as well?

Copy link
Contributor Author

@supriyar supriyar Sep 22, 2020

Choose a reason for hiding this comment

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

That may be true right now, but Raghu mentioned these will come in use when we develop the numeric suite and auto quantizer for OSS. One can argue that the OSS use cases might not need this functionality for script models, but it might be better to keep it all in the same place.

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 23, 2020
…line with a title. Use 1 line only, 67 chars or less>

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict
python test/test_quantization.py TestQuantizeJitPasses.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: c27c255
Pull Request resolved: #44846
loadbxh pushed a commit to loadbxh/Torch that referenced this pull request Sep 23, 2020
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: f0d591a
Pull Request resolved: pytorch/pytorch#44846
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 24, 2020
…line with a title. Use 1 line only, 67 chars or less>

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict
python test/test_quantization.py TestQuantizeJitPasses.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 69c958d
Pull Request resolved: #44846
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 28, 2020
…line with a title. Use 1 line only, 67 chars or less>

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict
python test/test_quantization.py TestQuantizeJitPasses.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 0b6130c
Pull Request resolved: #44846
Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D23746821](https://our.internmc.facebook.com/intern/diff/D23746821)

[ghstack-poisoned]
supriyar added a commit that referenced this pull request Sep 29, 2020
…line with a title. Use 1 line only, 67 chars or less>

Summary:
The save function traverses the model state dict to pick out the observer stats
load function traverse the module hierarchy to load the state dict into module attributes depending on observer type

Test Plan:
python test/test_quantization.py TestQuantizeFx.test_save_observer_state_dict
python test/test_quantization.py TestQuantizeJitPasses.test_save_observer_state_dict

Reviewers:

Subscribers:

Tasks:

Tags:
ghstack-source-id: 246eac0
Pull Request resolved: #44846
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 489af4d.

@facebook-github-bot facebook-github-bot deleted the gh/supriyar/181/head branch October 2, 2020 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants