Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .azure-pipelines/scripts/codeScan/pyspelling/lpot_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ Goyal
gpg
GPG
gpt
GPTJ
gpu
gpus
GPUs
Expand Down
9 changes: 9 additions & 0 deletions examples/.config/model_params_pytorch.json
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,15 @@
"batch_size": 64,
"new_benchmark": false
},
"gpt_j_wikitext":{
"model_src_dir": "nlp/huggingface_models/language-modeling/quantization/ptq_static/fx",
"dataset_location": "",
"input_model": "/tf_dataset2/models/pytorch/gpt-j-6B",
"yaml": "conf.yaml",
"strategy": "basic",
"batch_size": 8,
"new_benchmark": false
},
"xlm-roberta-base_MRPC": {
"model_src_dir": "nlp/huggingface_models/text-classification/quantization/ptq_static/eager",
"dataset_location": "",
Expand Down
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ Intel® Neural Compressor validated examples with multiple compression technique
<td>Post-Training Dynamic Quantization</td>
<td><a href="./pytorch/nlp/huggingface_models/summarization/quantization/ptq_dynamic/eager">eager</a></td>
</tr>
<tr>
<td>GPTJ</td>
<td>Natural Language Processing</td>
<td>Post-Training Static Quantization</td>
<td><a href="./pytorch/nlp/huggingface_models/language-modeling/quantization/ptq_static/fx">fx</a></td>
</tr>
</tbody>
</table>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Step-by-Step
============

This document is used to list steps of reproducing PyTorch BERT tuning zoo result.

# Prerequisite

## 1. Installation

The dependent packages are all in requirements, please install as following.

```
pip install -r requirements.txt
```

## 2. Run

If the automatic download from modelhub fails, you can download [EleutherAI/gpt-j-6B](https://huggingface.co/EleutherAI/gpt-j-6B?text=My+name+is+Clara+and+I+am) offline.

```shell

python run_clm.py \
--model_name_or_path EleutherAI/gpt-j-6B \
--dataset_name wikitext\
--dataset_config_name wikitext-2-raw-v1 \
--do_train \
--do_eval \
--tune \
--output_dir /path/to/checkpoint/dir
```


## 3. Command

```
bash run_tuning.sh --topology=gpt_j_wikitext
bash run_benchmark.sh --topology=gpt_j_wikitext --mode=performance --int8=true
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright (c) 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version: 1.0

model: # mandatory. used to specify model specific information.
name: bert
framework: pytorch_fx # mandatory. possible values are tensorflow, mxnet, pytorch, pytorch_ipex, onnxrt_integerops and onnxrt_qlinearops.

quantization: # optional. tuning constraints on model-wise for advance user to reduce tuning space.
approach: post_training_static_quant

tuning:
accuracy_criterion:
relative: 0.5 # optional. default value is relative, other value is absolute. this example allows relative accuracy loss: 1%.
higher_is_better: False
exit_policy:
max_trials: 600
random_seed: 9527 # optional. random seed for deterministic tuning.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sentencepiece != 0.1.92
protobuf
evaluate
datasets
transformers >= 4.22.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash
set -x

function main {

init_params "$@"
run_benchmark

}

# init params
function init_params {
iters=100
batch_size=16
tuned_checkpoint=saved_results
max_eval_samples=`expr ${iters} \* ${batch_size}`
echo ${max_eval_samples}
for var in "$@"
do
case $var in
--topology=*)
topology=$(echo $var |cut -f2 -d=)
;;
--dataset_location=*)
dataset_location=$(echo $var |cut -f2 -d=)
;;
--input_model=*)
input_model=$(echo $var |cut -f2 -d=)
;;
--mode=*)
mode=$(echo $var |cut -f2 -d=)
;;
--batch_size=*)
batch_size=$(echo $var |cut -f2 -d=)
;;
--iters=*)
iters=$(echo ${var} |cut -f2 -d=)
;;
--int8=*)
int8=$(echo ${var} |cut -f2 -d=)
;;
--config=*)
tuned_checkpoint=$(echo $var |cut -f2 -d=)
;;
*)
echo "Error: No such parameter: ${var}"
exit 1
;;
esac
done

}


# run_benchmark
function run_benchmark {
extra_cmd=''

if [[ ${mode} == "accuracy" ]]; then
mode_cmd=" --accuracy_only "
elif [[ ${mode} == "benchmark" ]]; then
mode_cmd=" --benchmark "
extra_cmd=$extra_cmd" --max_eval_samples ${max_eval_samples}"
else
echo "Error: No such mode: ${mode}"
exit 1
fi

if [ "${topology}" = "gpt_j_wikitext" ]; then
TASK_NAME='wikitext'
model_name_or_path=$input_model
extra_cmd='--dataset_config_name=wikitext-2-raw-v1'
fi

if [[ ${int8} == "true" ]]; then
extra_cmd=$extra_cmd" --int8"
fi
echo $extra_cmd

python -u run_clm.py \
--model_name_or_path ${model_name_or_path} \
--dataset_name ${TASK_NAME} \
--do_eval \
--per_device_eval_batch_size ${batch_size} \
--output_dir ${tuned_checkpoint} \
${mode_cmd} \
${extra_cmd}

}

main "$@"
Loading