Chua, Vui Seng commited on
Commit
b24eac5
1 Parent(s): 0e66ada

Update documentation

Browse files
Files changed (1) hide show
  1. README.md +84 -8
README.md CHANGED
@@ -1,7 +1,7 @@
1
- TODO: Update documentation
2
-
3
- Quantized version of the following. Scores are correct.
4
- This model is transfer-learning of [bert-base pruneofa 90% sparse](https://huggingface.co/Intel/bert-base-uncased-sparse-90-unstructured-pruneofa) on Squadv1 dataset.
5
 
6
  ```
7
  eval_exact_match = 80.6623
@@ -10,21 +10,97 @@ This model is transfer-learning of [bert-base pruneofa 90% sparse](https://huggi
10
  ```
11
 
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # Train
14
- use https://github.com/IntelLabs/Model-Compression-Research-Package.git
15
- see ```pruneofa-transfer-learning.sh```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # Eval
 
18
  ```bash
 
 
 
19
  export CUDA_VISIBLE_DEVICES=0
20
 
21
- OUTDIR=eval-bert-base-squadv1-pruneofa-90pc-bt
22
- WORKDIR=transformers/examples/pytorch/question-answering
23
  cd $WORKDIR
 
 
24
 
25
  nohup python run_qa.py \
26
  --model_name_or_path vuiseng9/bert-base-squadv1-pruneofa-90pc-bt \
27
  --dataset_name squad \
 
 
 
28
  --do_eval \
29
  --per_device_eval_batch_size 128 \
30
  --max_seq_length 384 \
 
1
+ This model is a downstream optimization of [```vuiseng9/bert-base-squadv1-pruneofa-90pc-bt```](https://huggingface.co/vuiseng9/bert-base-squadv1-pruneofa-90pc-bt) using [OpenVINO/NNCF](https://github.com/openvinotoolkit/nncf). Applied optimization includes:
2
+ 1. magnitude sparsification at 0% upon initialization. Custom reverse masking and sparsity freezing are applied.
3
+ 2. NNCF Quantize-Aware Training - Symmetric 8-bit for both weight and activation on all learnable layers.
4
+ 3. Custom distillation with large model ```bert-large-uncased-whole-word-masking-finetuned-squad```
5
 
6
  ```
7
  eval_exact_match = 80.6623
 
10
  ```
11
 
12
 
13
+ # Setup
14
+ ```bash
15
+ # OpenVINO/NNCF
16
+ git clone https://github.com/vuiseng9/nncf && cd nncf
17
+ git checkout tld-poc
18
+ git reset --hard 5647610d5ee2bf9f1324604e6579bca1c391e260
19
+ python setup.py develop
20
+ pip install -r examples/torch/requirements.txt
21
+
22
+ # Huggingface nn_pruning
23
+ git clone https://github.com/vuiseng9/nn_pruning && cd nn_pruning
24
+ git checkout reproduce-evaluation
25
+ git reset --hard 2d4e196d694c465e43e5fbce6c3836d0a60e1446
26
+ pip install -e ".[dev]"
27
+
28
+ # Huggingface Transformers
29
+ git clone https://github.com/vuiseng9/transformers && cd transformers
30
+ git checkout tld-poc
31
+ git reset --hard 5dd7402e9a316041dea4ff67508c01047323616e
32
+ pip install -e .
33
+ head -n 1 examples/pytorch/question-answering/requirements.txt | xargs -i pip install {}
34
+
35
+ # Additional dependencies
36
+ pip install onnx
37
+ ```
38
+
39
  # Train
40
+
41
+ ```bash
42
+ wget https://huggingface.co/vuiseng9/bert-base-squadv1-pruneofa-90pc-bt-qat-lt/raw/main/nncf_bert_squad_sparsity.json
43
+ NNCF_CFG=/path/to/downloaded_nncf_cfg_above #to-revise
44
+
45
+ OUTROOT=/path/to/train_output_root #to-revise
46
+ WORKDIR=transformers/examples/pytorch/question-answering #to-revise
47
+ RUNID=bert-base-squadv1-pruneofa-90pc-bt-qat-lt
48
+
49
+ cd $WORKDIR
50
+
51
+ OUTDIR=$OUTROOT/$RUNID
52
+ mkdir -p $OUTDIR
53
+
54
+ export CUDA_VISIBLE_DEVICES=0
55
+ NEPOCH=5
56
+
57
+ python run_qa.py \
58
+ --model_name_or_path vuiseng9/bert-base-squadv1-pruneofa-90pc-bt \
59
+ --pruneofa_qat \
60
+ --dataset_name squad \
61
+ --do_eval \
62
+ --do_train \
63
+ --evaluation_strategy steps \
64
+ --eval_steps 250 \
65
+ --learning_rate 3e-5 \
66
+ --lr_scheduler_type cosine_with_restarts \
67
+ --warmup_ratio 0.25 \
68
+ --cosine_cycles 1 \
69
+ --teacher bert-large-uncased-whole-word-masking-finetuned-squad \
70
+ --teacher_ratio 0.9 \
71
+ --num_train_epochs $NEPOCH \
72
+ --per_device_eval_batch_size 128 \
73
+ --per_device_train_batch_size 16 \
74
+ --max_seq_length 384 \
75
+ --doc_stride 128 \
76
+ --save_steps 250 \
77
+ --nncf_config $NNCF_CFG \
78
+ --logging_steps 1 \
79
+ --overwrite_output_dir \
80
+ --run_name $RUNID \
81
+ --output_dir $OUTDIR
82
+ ```
83
 
84
  # Eval
85
+ This repo must be cloned locally.
86
  ```bash
87
+ git clone https://huggingface.co/vuiseng9/bert-base-squadv1-pruneofa-90pc-bt-qat-lt
88
+ MODELROOT=/path/to/cloned_repo_above #to-revise
89
+
90
  export CUDA_VISIBLE_DEVICES=0
91
 
92
+ OUTDIR=eval-bert-base-squadv1-pruneofa-90pc-bt-qat-lt
93
+ WORKDIR=transformers/examples/pytorch/question-answering #to-revise
94
  cd $WORKDIR
95
+ mkdir $OUTDIR
96
+
97
 
98
  nohup python run_qa.py \
99
  --model_name_or_path vuiseng9/bert-base-squadv1-pruneofa-90pc-bt \
100
  --dataset_name squad \
101
+ --qat_checkpoint $MODELROOT/checkpoint-22000 \
102
+ --nncf_config $MODELROOT/nncf_bert_squad_sparsity.json \
103
+ --to_onnx $OUTDIR/bert-base-squadv1-pruneofa-90pc-bt-qat-lt.onnx \
104
  --do_eval \
105
  --per_device_eval_batch_size 128 \
106
  --max_seq_length 384 \