|
35 | 35 | # are quantized dynamically (per batch) to int8 when the weights are
|
36 | 36 | # quantized to int8.
|
37 | 37 | #
|
38 |
| -# In PyTorch, we have ``torch.quantization.quantize_dynamic`` API support |
39 |
| -# (https://pytorch.org/docs/stable/quantization.html#torch.quantization.quantize_dynamic), |
40 |
| -# which replaces specified modules with dynamic weight-only quantized |
| 38 | +# In PyTorch, we have `torch.quantization.quantize_dynamic API |
| 39 | +# <https://pytorch.org/docs/stable/quantization.html#torch.quantization.quantize_dynamic>`_ |
| 40 | +# ,which replaces specified modules with dynamic weight-only quantized |
41 | 41 | # versions and output the quantized model.
|
42 | 42 | #
|
43 | 43 | # - We demonstrate the accuracy and inference performance results on the
|
44 |
| -# Microsoft Research Paraphrase Corpus (MRPC) task |
45 |
| -# (https://www.microsoft.com/en-us/download/details.aspx?id=52398) in |
46 |
| -# the General Language Understanding Evaluation benchmark (GLUE) |
47 |
| -# (https://gluebenchmark.com/). The MRPC (Dolan and Brockett, 2005) is |
| 44 | +# `Microsoft Research Paraphrase Corpus (MRPC) task <https://www.microsoft.com/en-us/download/details.aspx?id=52398>`_ |
| 45 | +# in the General Language Understanding Evaluation benchmark `(GLUE) |
| 46 | +# <https://gluebenchmark.com/>`_. The MRPC (Dolan and Brockett, 2005) is |
48 | 47 | # a corpus of sentence pairs automatically extracted from online news
|
49 | 48 | # sources, with human annotations of whether the sentences in the pair
|
50 | 49 | # are semantically equivalent. Because the classes are imbalanced (68%
|
51 | 50 | # positive, 32% negative), we follow common practice and report both
|
52 |
| -# accuracy and F1 score |
53 |
| -# (https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html). |
| 51 | +# accuracy and `F1 score <https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html>`_ |
54 | 52 | # MRPC is a common NLP task for language pair classification, as shown
|
55 | 53 | # below.
|
56 | 54 | #
|
|
66 | 64 | #
|
67 | 65 | # To start this tutorial, let’s first follow the installation instructions
|
68 | 66 | # in PyTorch and HuggingFace Github Repo: -
|
69 |
| -# https://github.com/pytorch/pytorch/#installation - |
70 |
| -# https://github.com/huggingface/transformers#installation |
| 67 | +# |
| 68 | +# * https://github.com/pytorch/pytorch/#installation - |
| 69 | +# |
| 70 | +# * https://github.com/huggingface/transformers#installation |
71 | 71 | #
|
72 | 72 | # In addition, we also install ``sklearn`` package, as we will reuse its
|
73 | 73 | # built-in F1 score calculation helper function.
|
|
82 | 82 | ######################################################################
|
83 | 83 | # Because we will be using the experimental parts of the PyTorch, it is
|
84 | 84 | # recommended to install the latest version of torch and torchvision. You
|
85 |
| -# can find the most recent instructions on local installation here |
86 |
| -# https://pytorch.org/get-started/locally/. For example, to install on |
| 85 | +# can find the most recent instructions on local installation `here |
| 86 | +# <https://pytorch.org/get-started/locally/>`_. For example, to install on |
87 | 87 | # Mac:
|
88 | 88 | #
|
89 | 89 | # .. code:: shell
|
|
140 | 140 | # Download the dataset
|
141 | 141 | # --------------------
|
142 | 142 | #
|
143 |
| -# Before running MRPC tasks we download the GLUE data |
144 |
| -# (https://gluebenchmark.com/tasks) by running this script |
145 |
| -# (https://gist.github.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e, |
146 |
| -# https://github.com/nyu-mll/GLUE-baselines/blob/master/download_glue_data.py) |
| 143 | +# Before running MRPC tasks we download the `GLUE data |
| 144 | +# <https://gluebenchmark.com/tasks>`_ by running this `script |
| 145 | +# <https://gist.github.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e>`_ followed by |
| 146 | +# `download_glue_data <https://github.com/nyu-mll/GLUE-baselines/blob/master/download_glue_data.py>`_. |
147 | 147 | # and unpack it to some directory “glue_data/MRPC”.
|
148 | 148 | #
|
149 | 149 | #
|
|
167 | 167 | # Convert the texts into features
|
168 | 168 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
169 | 169 | #
|
170 |
| -# glue_convert_examples_to_features ( |
171 |
| -# https://github.com/huggingface/transformers/blob/master/transformers/data/processors/glue.py) |
| 170 | +# `glue_convert_examples_to_features <https://github.com/huggingface/transformers/blob/master/transformers/data/processors/glue.py>`_. |
172 | 171 | # load a data file into a list of ``InputFeatures``.
|
173 | 172 | #
|
174 | 173 | # - Tokenize the input sequences;
|
|
181 | 180 | # F1 metric
|
182 | 181 | # ~~~~~~~~~
|
183 | 182 | #
|
184 |
| -# The F1 score |
185 |
| -# (https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html) |
| 183 | +# The `F1 score <https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html>`_ |
186 | 184 | # can be interpreted as a weighted average of the precision and recall,
|
187 | 185 | # where an F1 score reaches its best value at 1 and worst score at 0. The
|
188 | 186 | # relative contribution of precision and recall to the F1 score are equal.
|
|
208 | 206 | #
|
209 | 207 | # To fine-tune the pre-trained BERT model (“bert-base-uncased” model in
|
210 | 208 | # HuggingFace transformers) for the MRPC task, you can follow the command
|
211 |
| -# in (https://github.com/huggingface/transformers/tree/master/examples): |
| 209 | +# in `examples<https://github.com/huggingface/transformers/tree/master/examples>`_" |
212 | 210 | #
|
213 | 211 | # ::
|
214 | 212 | #
|
@@ -317,10 +315,8 @@ def set_seed(seed):
|
317 | 315 | # Define the tokenize and evaluation function
|
318 | 316 | # -------------------------------------------
|
319 | 317 | #
|
320 |
| -# We reuse the tokenize and evaluation function from |
321 |
| -# https://github.com/huggingface/transformers/blob/master/examples/run_glue.py. |
| 318 | +# We reuse the tokenize and evaluation function from `huggingface <https://github.com/huggingface/transformers/blob/master/examples/run_glue.py>`_. |
322 | 319 | #
|
323 |
| - |
324 | 320 | # coding=utf-8
|
325 | 321 | # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
|
326 | 322 | # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
@@ -555,8 +551,8 @@ def time_model_evaluation(model, configs, tokenizer):
|
555 | 551 | # set multi-thread by ``torch.set_num_threads(N)`` (``N`` is the number of
|
556 | 552 | # intra-op parallelization threads). One preliminary requirement to enable
|
557 | 553 | # the intra-op parallelization support is to build PyTorch with the right
|
558 |
| -# backend such as OpenMP, Native, or TBB |
559 |
| -# (https://pytorch.org/docs/stable/notes/cpu_threading_torchscript_inference.html#build-options). |
| 554 | +# `backend <https://pytorch.org/docs/stable/notes/cpu_threading_torchscript_inference.html#build-options>`_ |
| 555 | +# such as OpenMP, Native or TBB. |
560 | 556 | # You can use ``torch.__config__.parallel_info()`` to check the
|
561 | 557 | # parallelization settings. On the same MacBook Pro using PyTorch with
|
562 | 558 | # Native backend for parallelization, we can get about 46 seconds for
|
|
0 commit comments