* [WIP][JIT] Add ScriptModule._reconstruct (#39979)
Summary:
**Summary**
This commit adds an instance method `_reconstruct` that permits users
to reconstruct a `ScriptModule` from a given C++ `Module` instance.
**Testing**
This commit adds a unit test for `_reconstruct`.
**Fixes**
This pull request fixes https://github.com/pytorch/pytorch/issues/33912.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39979
Differential Revision: D22172323
Pulled By: SplitInfinity
fbshipit-source-id: 9aa6551c422a5a324b822a09cd8d7c660f99ca5c
* [quant][graphmode] Enable inplace option for top level API (#40414)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40414
after `_reconstruct` is supported in RecursiveScriptModule: https://github.com/pytorch/pytorch/pull/39979
we can support inplace option in quantization API
Test Plan: Imported from OSS
Differential Revision: D22178326
fbshipit-source-id: c78bc2bcf2c42b06280c12262bb31aebcadc6c32
Co-authored-by: Meghan Lele <meghanl@fb.com>
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40396
Removes activation and normalization modules from eager mode QAT.
These were incorrectly added, but we don't actually need them.
Test Plan:
```
python test/test_quantization.py TestQuantizationAwareTraining
```
Imported from OSS
Differential Revision: D22169768
fbshipit-source-id: b5bd753dafe92e90e226fb773eb18c6aae179703
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40191
When the first couple of inputs passed to histogram observer are all 0's subsequent non-zero inputs cause a div by 0 error
Test Plan:
python test/test_quantization.py TestHistogramObserver.test_histogram_observer_zero_inputs
Imported from OSS
Differential Revision: D22119422
fbshipit-source-id: 8bbbba914ba7f343121830c768ca0444439f8e03
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39915
Some of the usage, e.g. add_scalar will not be supporting the debug option,
that is, we will not have a numerically exact representation of the final quantized model
before finalize if people use add scalar.
warning will be added in a later PR.
Test Plan: Imported from OSS
Differential Revision: D22013026
fbshipit-source-id: 714b938f25c10fad3dfc79f095356b9803ef4b47
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39874
When fbgemm backend is set we make sure reduce_range is set to true to avoid overflow in the operator
Also adds test for per-channel quant with graph mode and compare numerics with eager mode
Test Plan:
python test/test_quantization.py
Imported from OSS
Differential Revision: D22011205
fbshipit-source-id: 1c7c9b7ab0d84200e3d8d85c34978554c30c0169
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39825
Removing the pass for now since it is causing error for some models
Test Plan: Imported from OSS
Differential Revision: D21987878
fbshipit-source-id: 129aefb34754d5390a4c9d3108fa1b6c2eae5a74
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39795
Replaces the `is_dynamic` bool by enums in Python and c++
graph quantization code. This makes the code more readable
and will make it easier to modify for adding QAT logic in the future.
Test Plan:
CI, as well as
```
python test/test_quantization.py TestQuantizeDynamicScript
python test/test_quantization.py TestQuantizeScriptJitPasses
```
Imported from OSS
Differential Revision: D21981643
fbshipit-source-id: d475760407bcc794aeae92a2c696bac4acda843d
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39750
Add a test to make the default QAT qconfig scriptable, and fix
all the errors.
Test Plan:
```
python test/test_quantization.py TestQATScript.fake_quant_scriptable
```
Imported from OSS
Differential Revision: D21975879
fbshipit-source-id: 8c48ad9f24b2c941d2267cb53eb70ebecd103744
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39090
Makes quantized GroupNorm work in eager mode post training static quant.
Test Plan:
```
python test/test_quantization.py TestPostTrainingStatic.test_normalization
python test/test_quantization.py TestStaticQuantizedModule.test_group_norm
```
Imported from OSS
Differential Revision: D21885262
fbshipit-source-id: 58b0ffb59c601fcb4c79f711c7c98a667ffc6170
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39412
This PR introduces changes to enable running the weight observer standalone in the graph
It extracts the nodes from the graph that correspond to the observed weight value and adds all the related nodes to a new subgraph
The subgraph is then executed using GraphFunction
Test Plan:
python test/test_quantization.py TestGraphMostPostTrainingStatic
python test/test_quantization.py TestQuantizeDynamicScript
Imported from OSS
Differential Revision: D21872940
fbshipit-source-id: 55f1dcc2caef193531e2b807c8e56288b9794520
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39337
In #39031 we made fake quantize respect device affinity of the
original module. However, that PR only handled modules with parameters
or buffers, and did not work properly for `ReLU`.
Fixing the logic to also work for `ReLU` by passing the parent's
device when adding observers.
Test Plan:
```
python test/test_quantization.py TestDistributed.test_device_affinity
```
Imported from OSS
Differential Revision: D21821243
fbshipit-source-id: cc6abda3694b80ce8ba0440dc6c1b5b58f3c0066
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39031
Makes the eager mode QAT prepare logic respect device affinity.
This fixes the issue where a module is on `cuda:0`, and running
the QAT prepare script would add observers on `cpu`. Now it
will add them on the original device.
Test Plan:
```
python test/test_quantization.py TestDistributed.test_device_affinity
```
Imported from OSS
Differential Revision: D21729272
fbshipit-source-id: 5537bf3977ddc23412184941978bf0d1cc6fb479
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38587
Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.
This diff makes the shape stay consistent. This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.
Test Plan:
```
python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations
```
Imported from OSS
Differential Revision: D21605532
fbshipit-source-id: e00cd268d6d3ded1006d18d6c6759c911b3a74ea
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38584
All observers will support tensor lists in future PR
Test Plan: Imported from OSS
Differential Revision: D21623464
fbshipit-source-id: c5c57ecfe14f7c3aa92b7c99d724e846132ae03b
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38368
There is a need for some customers to enable/disable these flags
in the middle of QAT. To make it work properly with DDP,
we need to implement them using buffers so that they are replicated
properly to all the nodes.
This should solve issue https://github.com/pytorch/pytorch/issues/38081
Test Plan:
CI
Imported from OSS
Differential Revision: D21537607
fbshipit-source-id: 8c9da022beb7aaa44c658268f02f99dd5aee93fd
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38407
We can still run some quantized tests even when fbgemm/qnnpack isn't enabled
Test Plan:
python test/test_quantization.py
Imported from OSS
Differential Revision: D21554257
fbshipit-source-id: e4fa8f61f6a6717881c00620ed7938c01ffbf958
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38283
Adds support for the modules and tests
Test Plan:
python test/test_quantization.py TestStaticQuantizedModule.test_conv1d_api
Imported from OSS
Differential Revision: D21553665
fbshipit-source-id: 7ea28da024bdf59f87f300d616c266f2b41f0bcd
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37032
DataParallel requires all params and buffers of child modules to be updated
in place because of how it implements model replication during the
forward pass (see https://github.com/pytorch/pytorch/pull/12671 for
context). Any params or buffers not updated in place are lost and not
propagated back to the master.
This diff updates (some quantized modules) (TBD: all quantized modules? determine a good cut
point) to do their parameter update in-place. This will enable static
quant and QAT to work correctly with DataParallel.
TODO: https://github.com/pytorch/pytorch/pull/32684 needs to land before we can fix the graph mode test failures on this PR.
Test Plan:
script failed before and passes after the diff:
https://gist.github.com/vkuzo/78b06c01f23f98ee2aaaeb37e55f8d40
TODO before land: add integration testing
Imported from OSS
Differential Revision: D21206454
fbshipit-source-id: df6b4b04d0ae0f7ef582c82d81418163019e96f7
Summary:
xref gh-32838, gh-34032
This is a major refactor of parts of the documentation to split it up using sphinx's `autosummary` feature which will build out `autofuction` and `autoclass` stub files and link to them. The end result is that the top module pages like torch.nn.rst and torch.rst are now more like table-of-contents to the actual single-class or single-function documentations pages.
Along the way, I modified many of the docstrings to eliminate sphinx warnings when building. I think the only thing I changed from a non-documentation perspective is to add names to `__all__` when adding them to `globals()` in `torch.__init__.py`
I do not know the CI system: are the documentation build artifacts available after the build, so reviewers can preview before merging?
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37419
Differential Revision: D21337640
Pulled By: ezyang
fbshipit-source-id: d4ad198780c3ae7a96a9f22651e00ff2d31a0c0f