Skip to content

Commit

Permalink
Merge branch 'main' into noqqaqq-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
sekyondaMeta committed Jun 1, 2023
2 parents 979ec8e + 4cd44ae commit 121169a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/docathon-label-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def main():
repo = g.get_repo(f'{repo_owner}/{repo_name}')
pull_request = repo.get_pull(pull_request_number)
pull_request_body = pull_request.body
# PR without description
if pull_request_body is None:
return

# get issue number from the PR body
if not re.search(r'#\d{1,5}', pull_request_body):
Expand Down
10 changes: 10 additions & 0 deletions beginner_source/finetuning_torchvision_models_tutorial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Finetuning Torchvision Models
=============================

This tutorial has been moved to https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html

It will redirect in 3 seconds.

.. raw:: html

<meta http-equiv="Refresh" content="3; url='https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html'" />
2 changes: 1 addition & 1 deletion beginner_source/transformer_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def forward(self, x: Tensor) -> Tensor:
# into ``batch_size`` columns. If the data does not divide evenly into
# ``batch_size`` columns, then the data is trimmed to fit. For instance, with
# the alphabet as the data (total length of 26) and ``batch_size=4``, we would
# divide the alphabet into 4 sequences of length 6:
# divide the alphabet into sequences of length 6, resulting in 4 of such sequences.
#
# .. math::
# \begin{bmatrix}
Expand Down
14 changes: 7 additions & 7 deletions intermediate_source/tensorboard_profiler_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-----
To install ``torch`` and ``torchvision`` use the following command:
::
.. code-block::
pip install torch torchvision
Expand Down Expand Up @@ -160,23 +160,23 @@ def train(data):
#
# Install PyTorch Profiler TensorBoard Plugin.
#
# ::
# .. code-block::
#
# pip install torch_tb_profiler
#

######################################################################
# Launch the TensorBoard.
#
# ::
# .. code-block::
#
# tensorboard --logdir=./log
#

######################################################################
# Open the TensorBoard profile URL in Google Chrome browser or Microsoft Edge browser.
#
# ::
# .. code-block::
#
# http://localhost:6006/#pytorch_profiler
#
Expand Down Expand Up @@ -287,7 +287,7 @@ def train(data):
# In this example, we follow the "Performance Recommendation" and set ``num_workers`` as below,
# pass a different name such as ``./log/resnet18_4workers`` to ``tensorboard_trace_handler``, and run it again.
#
# ::
# .. code-block::
#
# train_loader = torch.utils.data.DataLoader(train_set, batch_size=32, shuffle=True, num_workers=4)
#
Expand Down Expand Up @@ -316,7 +316,7 @@ def train(data):
#
# You can try it by using existing example on Azure
#
# ::
# .. code-block::
#
# pip install azure-storage-blob
# tensorboard --logdir=https://torchtbprofiler.blob.core.windows.net/torchtbprofiler/demo/memory_demo_1_10
Expand Down Expand Up @@ -366,7 +366,7 @@ def train(data):
#
# You can try it by using existing example on Azure:
#
# ::
# .. code-block::
#
# pip install azure-storage-blob
# tensorboard --logdir=https://torchtbprofiler.blob.core.windows.net/torchtbprofiler/demo/distributed_bert
Expand Down
27 changes: 12 additions & 15 deletions prototype_source/fx_graph_mode_quant_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
**Author**: `Jerry Zhang <https://github.com/jerryzh168>`_

FX Graph Mode Quantization requires a symbolically traceable model.
We use the FX framework (TODO: link) to convert a symbolically traceable nn.Module instance to IR,
We use the FX framework to convert a symbolically traceable nn.Module instance to IR,
and we operate on the IR to execute the quantization passes.
Please post your question about symbolically tracing your model in `PyTorch Discussion Forum <https://discuss.pytorch.org/c/quantization/17>`_

Expand All @@ -22,16 +22,19 @@ You can use any combination of these options:
b. Write your own observed and quantized submodule


####################################################################
If the code that is not symbolically traceable does not need to be quantized, we have the following two options
to run FX Graph Mode Quantization:
1.a. Symbolically trace only the code that needs to be quantized


Symbolically trace only the code that needs to be quantized
-----------------------------------------------------------------
When the whole model is not symbolically traceable but the submodule we want to quantize is
symbolically traceable, we can run quantization only on that submodule.

before:

.. code:: python
class M(nn.Module):
def forward(self, x):
x = non_traceable_code_1(x)
Expand All @@ -42,6 +45,7 @@ before:
after:

.. code:: python
class FP32Traceable(nn.Module):
def forward(self, x):
x = traceable_code(x)
Expand Down Expand Up @@ -69,8 +73,7 @@ Note if original model needs to be preserved, you will have to
copy it yourself before calling the quantization APIs.


#####################################################
1.b. Skip symbolically trace the non-traceable code
Skip symbolically trace the non-traceable code
---------------------------------------------------
When we have some non-traceable code in the module, and this part of code doesn’t need to be quantized,
we can factor out this part of the code into a submodule and skip symbolically trace that submodule.
Expand Down Expand Up @@ -134,8 +137,7 @@ quantization code:
If the code that is not symbolically traceable needs to be quantized, we have the following two options:

##########################################################
2.a Refactor your code to make it symbolically traceable
Refactor your code to make it symbolically traceable
--------------------------------------------------------
If it is easy to refactor the code and make the code symbolically traceable,
we can refactor the code and remove the use of non-traceable constructs in python.
Expand Down Expand Up @@ -167,15 +169,10 @@ after:
return x.permute(0, 2, 1, 3)
quantization code:

This can be combined with other approaches and the quantization code
depends on the model.



#######################################################
2.b. Write your own observed and quantized submodule
Write your own observed and quantized submodule
-----------------------------------------------------

If the non-traceable code can’t be refactored to be symbolically traceable,
Expand Down Expand Up @@ -207,8 +204,8 @@ non-traceable logic, wrapped in a module
class FP32NonTraceable:
...
2. Define observed version of FP32NonTraceable
2. Define observed version of
FP32NonTraceable

.. code:: python
Expand Down

0 comments on commit 121169a

Please sign in to comment.