Skip to content

Commit

Permalink
add examples for GPTJ (#162)
Browse files Browse the repository at this point in the history
Signed-off-by: Wang, Chang1 <chang1.wang@intel.com>
  • Loading branch information
changwangss committed Dec 2, 2022
1 parent 0346c53 commit 01899d6
Show file tree
Hide file tree
Showing 9 changed files with 894 additions and 0 deletions.
1 change: 1 addition & 0 deletions .azure-pipelines/scripts/codeScan/pyspelling/lpot_dict.txt
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
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
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
@@ -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
```
@@ -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.
@@ -0,0 +1,5 @@
sentencepiece != 0.1.92
protobuf
evaluate
datasets
transformers >= 4.22.0
@@ -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 "$@"

0 comments on commit 01899d6

Please sign in to comment.