-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compression for UIE #3496
Add compression for UIE #3496
Conversation
5dd6387
to
b28d7cd
Compare
b28d7cd
to
76c05e2
Compare
* [模型评估与部署](#模型评估与部署) | ||
* [FAQ](#FAQ) | ||
* [参考文献](#References) | ||
|
||
|
||
<a name="模型压缩API功能介绍"></a> | ||
<a name="模型压缩API功能简介"></a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在文档里面还是建议说清楚一些技术概念,可以通过图片的方式解释
同时压缩API的使用流程,裁剪和量化的区别 ;静态量化和动态量化在使用的流程区别在什么地方 需要说清楚
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要在下一个PR中对压缩API的文档进行进一步更新。
``` | ||
|
||
示例代码中压缩使用的是 datasets 内置的数据集,若想要使用自定义数据集压缩,可参考 [datasets 加载自定义数据集文档](https://huggingface.co/docs/datasets/loading)。 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里还有另外一个问题,cpu和gpu量化对机器要求不一样,这里是否可以概括一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经把对机器的要求包括在4.7模型部署中的使用建议中
model_zoo/uie/README.md
Outdated
- `logging_steps`: 日志打印的间隔steps数,默认10。 | ||
- `valid_steps`: evaluate的间隔steps数,默认100。 | ||
- `device`: 选用什么设备进行训练,可选cpu或gpu。 | ||
可配置的压缩相关的参数: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有些担忧,do_compress是不是要关闭最好,因为开源用户的机器可能无法支持INT8量化
同时动态量化模型导出的模型是静态图,而之前我们是有export_model.py脚本,如何整合了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do_compress
已关闭,感谢指出
self.inference_backend = InferBackend(args.model_path_prefix, | ||
device=args.device, | ||
use_fp16=args.use_fp16, | ||
device_id=args.device_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
INT8量化模型和use_fp16这里要不要加一个逻辑,同时FP16和INT8如何使用能不能有个最佳指南
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最佳指南在文档中已给出
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里还是不太明确怎么使用INT8的模型
model_zoo/uie/run_trainer.py
Outdated
# for key, val in resource_file_urls.items(): | ||
# file_path = os.path.join(model_args.model_name_or_path, key) | ||
# if not os.path.exists(file_path): | ||
# get_path_from_url(val, model_args.model_name_or_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done Thanks
8ca31a8
to
759d620
Compare
759d620
to
e546afd
Compare
model_zoo/uie/README.md
Outdated
<a name="模型评估"></a> | ||
|
||
#### 4.4 模型评估 | ||
export finetuned_model=uie_finetuned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里保存模型地址和之前下面的目录有冲突
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢提醒,目录和下面进行了统一
--overwrite_output_dir \ | ||
--disable_tqdm True \ | ||
--metric_for_best_model eval_f1 \ | ||
--load_best_model_at_end True \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多卡的示例是不是要保留
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多卡的脚本已经补充出来了,感谢提醒,应该和之前体验保持一致
self.inference_backend = InferBackend(args.model_path_prefix, | ||
device=args.device, | ||
use_fp16=args.use_fp16, | ||
device_id=args.device_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里还是不太明确怎么使用INT8的模型
model_zoo/uie/README.md
Outdated
|
||
通过运行以下命令进行模型评估: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的evaluate的逻辑还包括了debug逻辑 不建议删除
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经恢复了evaluate.py
--learning_rate 1e-5 \ | ||
--do_train \ | ||
--do_eval \ | ||
--do_export \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我看最新的finetune脚本这里已经默认开启了do_export
,后面的模型导出章节是否可以删掉和模型压缩的流程保持一致
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经删掉了,只用了一句话介绍了下导出模型
model_zoo/uie/README.md
Outdated
* `device`: 训练设备,可选择 'cpu'、'gpu' 其中的一种;默认为 GPU 训练。 | ||
* `per_device_train_batch_size`:训练集训练过程批处理大小,请结合显存情况进行调整,若出现显存不足,请适当调低这一参数;默认为 32。 | ||
* `per_device_eval_batch_size`:开发集评测过程批处理大小,请结合显存情况进行调整,若出现显存不足,请适当调低这一参数;默认为 32。 | ||
* `learning_rate`:训练最大学习率;默认为3e-5。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UIE微调学习率默认值建议用1e-5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,因为这里用的Trainer API,可能默认值不好直接改,但是我这里对文档进行了补充,:训练最大学习率,UIE 推荐设置为 1e-5;默认值为3e-5。
model_zoo/uie/README.md
Outdated
* `logging_steps`: 训练过程中日志打印的间隔 steps 数,默认100。 | ||
* `save_steps`: 训练过程中保存模型 checkpoint 的间隔 steps 数,默认100。 | ||
* `seed`:全局随机种子,默认为 42。 | ||
* `label_names`:训练数据标签的key的名称,例如 'labels'、'start_postions' 或者 'end_positions' 等。自定义数据集需要设置,否则可能会造成识别错误;默认为 None。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里如果UIE默认需要用'start_postions' + 'end_positions'是否可以不作为可配置项暴露出来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通过对Trainer API进行修改,修改了UIE 模型的默认label_names值,不需要让用户再学习使用这个参数。Trainer 这里也请@ZHUI 帮忙review下
@@ -625,57 +626,96 @@ python labelstudio2doccano.py --labelstudio_file label-studio.json | |||
|
|||
#### 4.3 模型微调 | |||
|
|||
推荐使用 [Trainer API ](../../docs/trainer.md) 对模型进行微调。只需输入模型、数据集等就可以使用 Trainer API 高效快速地进行预训练、微调和模型压缩等任务,可以一键启动多卡训练、混合精度训练、梯度累积、断点重启、日志显示等功能,Trainer API 还针对训练过程的通用训练配置做了封装,比如:优化器、学习率调度等。 | |||
|
|||
使用下面的命令,使用 `uie-base` 作为预训练模型进行模型微调,将微调后的模型保存至`$finetuned_model`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
想问下这里改为trainer后保存路径下的文件及命名是否和之前一致,后续Taskflow加载定制模型需要用到
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最好的动态图模型、导出的静态图模型、量化后模型都在 ./checkpoint/model_best
下面,只是用 $finetuned_model 变量来 表示,但是这样是不是不能确保用户一定会存在 ./checkpoint/model_best
下面
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for UIE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
给个环境配置吧,uie训练加上do_compress参数一直压缩失败。 |
PR types
New features
PR changes
Models
Description