Skip to content

Update Dynamic Quant BERT Tutorial 4 #760

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions intermediate_source/dynamic_quantization_bert_tutorial.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(experimental) Dynamic Quantization on HuggingFace BERT model
==============================================================
(experimental) Dynamic Quantization on BERT
===========================================

**Author**: `Jianyu Huang <https://github.com/jianyuh>`_

Expand Down Expand Up @@ -128,21 +128,7 @@ In the end of the tutorial, the user can set other number of threads by building
print(torch.__config__.parallel_info())


1.3 Download the dataset
^^^^^^^^^^^^^^^^^^^^^^^^

Before running MRPC tasks we download the `GLUE data
<https://gluebenchmark.com/tasks>`_ by running `this script
<https://gist.github.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e>`_
and unpack it to a directory ``glue_data``.


.. code:: shell

python download_glue_data.py --data_dir='glue_data' --tasks='MRPC'


1.4 Learn about helper functions
1.3 Learn about helper functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The helper functions are built-in in transformers library. We mainly use
Expand All @@ -159,7 +145,8 @@ The `glue_convert_examples_to_features <https://github.com/huggingface/transform
- Generate token type ids to indicate whether a token belongs to the
first sequence or the second sequence.

The `F1 score <https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html>`_
The `glue_compute_metrics <https://github.com/huggingface/transformers/blob/master/transformers/data/processors/glue.py>`_ function has the compute metrics with
the `F1 score <https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html>`_, which
can be interpreted as a weighted average of the precision and recall,
where an F1 score reaches its best value at 1 and worst score at 0. The
relative contribution of precision and recall to the F1 score are equal.
Expand All @@ -168,6 +155,20 @@ relative contribution of precision and recall to the F1 score are equal.
.. math:: F1 = 2 * (\text{precision} * \text{recall}) / (\text{precision} + \text{recall})


1.4 Download the dataset
^^^^^^^^^^^^^^^^^^^^^^^^

Before running MRPC tasks we download the `GLUE data
<https://gluebenchmark.com/tasks>`_ by running `this script
<https://gist.github.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e>`_
and unpack it to a directory ``glue_data``.


.. code:: shell

python download_glue_data.py --data_dir='glue_data' --tasks='MRPC'


2. Fine-tune the BERT model
---------------------------

Expand Down