返回模型
说明文档
该模型是使用 OpenVINO/NNCF 对 vuiseng9/bert-base-squadv1-block-pruning-hybrid-filled-lt 进行下游优化的结果。应用的优化包括:
- 在初始化时进行 57.92% 的幅度稀疏化,使得 bert-base 所有线性层的稀疏度达到 90%。参数通过其绝对范数进行全局排序。仅针对自注意力层和前馈神经网络(FFNN)的线性层。
- NNCF 量化感知训练(QAT)- 对所有可学习层的权重和激活值使用对称 8 位量化。
- 使用大模型
bert-large-uncased-whole-word-masking-finetuned-squad进行自定义蒸馏。
eval_exact_match = 80.4541
eval_f1 = 87.6832
eval_samples = 10784
环境配置
# OpenVINO/NNCF
git clone https://github.com/vuiseng9/nncf && cd nncf
git checkout tld-poc
git reset --hard 1dec7afe7a4b567c059fcf287ea2c234980fded2
python setup.py develop
pip install -r examples/torch/requirements.txt
# Huggingface nn_pruning
git clone https://github.com/vuiseng9/nn_pruning && cd nn_pruning
git checkout reproduce-evaluation
git reset --hard 2d4e196d694c465e43e5fbce6c3836d0a60e1446
pip install -e \".[dev]\"
# Huggingface Transformers
git clone https://github.com/vuiseng9/transformers && cd transformers
git checkout tld-poc
git reset --hard 10a1e29d84484e48fd106f58957d9ffc89dc43c5
pip install -e .
head -n 1 examples/pytorch/question-answering/requirements.txt | xargs -i pip install {}
# 其他依赖
pip install onnx
训练
git clone https://huggingface.co/vuiseng9/bert-base-squadv1-block-pruning-hybrid-filled-lt
BASE_MODEL=/path/to/cloned_repo_above #需修改
wget https://huggingface.co/vuiseng9/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt/raw/main/nncf_bert_squad_sparsity.json
NNCF_CFG=/path/to/downloaded_nncf_cfg_above #需修改
OUTROOT=/path/to/train_output_root #需修改
WORKDIR=transformers/examples/pytorch/question-answering #需修改
RUNID=bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt
cd $WORKDIR
OUTDIR=$OUTROOT/$RUNID
mkdir -p $OUTDIR
export CUDA_VISIBLE_DEVICES=0
NEPOCH=5
python run_qa.py \
--model_name_or_path vuiseng9/bert-base-squadv1-block-pruning-hybrid \
--optimize_model_before_eval \
--optimized_checkpoint $BASE_MODEL \
--dataset_name squad \
--do_eval \
--do_train \
--evaluation_strategy steps \
--eval_steps 250 \
--learning_rate 3e-5 \
--lr_scheduler_type cosine_with_restarts \
--warmup_ratio 0.25 \
--cosine_cycles 1 \
--teacher bert-large-uncased-whole-word-masking-finetuned-squad \
--teacher_ratio 0.9 \
--num_train_epochs $NEPOCH \
--per_device_eval_batch_size 128 \
--per_device_train_batch_size 16 \
--max_seq_length 384 \
--doc_stride 128 \
--save_steps 250 \
--nncf_config $NNCF_CFG \
--logging_steps 1 \
--overwrite_output_dir \
--run_name $RUNID \
--output_dir $OUTDIR
评估
此仓库必须克隆到本地。
git clone https://huggingface.co/vuiseng9/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt
MODELROOT=/path/to/cloned_repo_above #需修改
export CUDA_VISIBLE_DEVICES=0
OUTDIR=eval-bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt
WORKDIR=transformers/examples/pytorch/question-answering #需修改
cd $WORKDIR
mkdir $OUTDIR
nohup python run_qa.py \
--model_name_or_path vuiseng9/bert-base-squadv1-block-pruning-hybrid \
--dataset_name squad \
--optimize_model_before_eval \
--qat_checkpoint $MODELROOT/checkpoint-21750 \
--nncf_config $MODELROOT/nncf_bert_squad_sparsity.json \
--to_onnx $OUTDIR/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt.onnx \
--do_eval \
--per_device_eval_batch_size 128 \
--max_seq_length 384 \
--doc_stride 128 \
--overwrite_output_dir \
--output_dir $OUTDIR 2>&1 | tee $OUTDIR/run.log &
tile-alignment(分块对齐)
如需评估 tile-alignment 检查点,请添加 --tile_alignment 参数,并将 --qat_checkpoint 指向带有 'tilealigned' 后缀的检查点。使用 tld-poc 分支,提交 ID 为 c525c52cq。
vuiseng9/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt
作者 vuiseng9
transformers
↓ 0
♥ 0
创建时间: 2022-03-02 23:29:05+00:00
更新时间: 2022-02-08 22:58:08+00:00
在 Hugging Face 上查看文件 (56)
.gitattributes
README.md
XP_layer_wise_sparsity_global_rate_26.51.csv
XP_layer_wise_sparsity_global_rate_26.51.md
XP_linear_layer_sparsity_20M_params_57.92_sparsity.csv
XP_linear_layer_sparsity_20M_params_57.92_sparsity.md
XP_onnx_sparsity.csv
XP_onnx_sparsity.md
all_results.json
bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt-tilealigned.onnx
ONNX
bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt.onnx
ONNX
checkpoint-21750-tilealigned/config.json
checkpoint-21750-tilealigned/optimizer.pt
checkpoint-21750-tilealigned/pytorch_model.bin
checkpoint-21750-tilealigned/rng_state.pth
checkpoint-21750-tilealigned/scheduler.pt
checkpoint-21750-tilealigned/special_tokens_map.json
checkpoint-21750-tilealigned/tokenizer.json
checkpoint-21750-tilealigned/tokenizer_config.json
checkpoint-21750-tilealigned/trainer_state.json
checkpoint-21750-tilealigned/training_args.bin
checkpoint-21750-tilealigned/vocab.txt
checkpoint-21750/config.json
checkpoint-21750/optimizer.pt
checkpoint-21750/pytorch_model.bin
checkpoint-21750/rng_state.pth
checkpoint-21750/scheduler.pt
checkpoint-21750/special_tokens_map.json
checkpoint-21750/tokenizer.json
checkpoint-21750/tokenizer_config.json
checkpoint-21750/trainer_state.json
checkpoint-21750/training_args.bin
checkpoint-21750/vocab.txt
compressed_graph.dot
config.json
eval_XP_results.json
eval_nbest_predictions.json
eval_predictions.json
ir-tilealigned/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt-tilealigned.bin
ir-tilealigned/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt-tilealigned.mapping
ir-tilealigned/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt-tilealigned.xml
ir-tilealigned/mo.log
ir/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt.bin
ir/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt.mapping
ir/bert-base-squadv1-block-pruning-hybrid-filled-lt-nncf-57.92sparse-qat-lt.xml
ir/mo.log
nncf_bert_squad_sparsity.json
original_graph.dot
pytorch_model.bin
special_tokens_map.json
tokenizer.json
tokenizer_config.json
train_results.json
trainer_state.json
training_args.bin
vocab.txt