初始化项目,由ModelHub XC社区提供模型
Model: chg0901/EmoLLMV3.0 Source: Original Platform
This commit is contained in:
37
.gitattributes
vendored
Normal file
37
.gitattributes
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
||||
*.tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
*.db* filter=lfs diff=lfs merge=lfs -text
|
||||
*.ark* filter=lfs diff=lfs merge=lfs -text
|
||||
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
|
||||
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
||||
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.gguf* filter=lfs diff=lfs merge=lfs -text
|
||||
*.ggml filter=lfs diff=lfs merge=lfs -text
|
||||
*.llamafile* filter=lfs diff=lfs merge=lfs -text
|
||||
287
README.md
Normal file
287
README.md
Normal file
@@ -0,0 +1,287 @@
|
||||
<div align="center">
|
||||
|
||||
# EmoLLM-心理健康大模型
|
||||
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/aJupyter/EmoLLM/">
|
||||
<img src="https://github.com/SmartFlowAI/EmoLLM/raw/main/assets/logo.jpeg" alt="Logo" width="30%">
|
||||
</a>
|
||||
|
||||
<div align="center">
|
||||
|
||||
<!-- PROJECT SHIELDS -->
|
||||
[![Contributors][contributors-shield]][contributors-url]
|
||||
[![Forks][forks-shield]][forks-url]
|
||||
[![Issues][issues-shield]][issues-url]
|
||||
[![OpenXLab_App][OpenXLab_App-image]][OpenXLab_App-url]
|
||||
[![OpenXLab_Model][OpenXLab_Model-image]][OpenXLab_Model-url]
|
||||
[![MIT License][license-shield]][license-url]
|
||||
[![Stargazers][stars-shield]][stars-url]
|
||||
|
||||
</div>
|
||||
|
||||
<h3 align="center">EmoLLM</h3>
|
||||
|
||||
<div align="center">
|
||||
简体中文| <a href="README_EN.md" >English</a>
|
||||
<br />
|
||||
<br />
|
||||
<a href="https://github.com/aJupyter/EmoLLM"><strong>探索本项目的文档 »</strong></a>
|
||||
<br />
|
||||
<br />
|
||||
<a href="https://openxlab.org.cn/apps/detail/Farewell1/EmoLLMV2.0">体验EmoLLM 2.0</a>
|
||||
·
|
||||
<a href="https://github.com/aJupyter/EmoLLM/issues">报告Bug</a>
|
||||
·
|
||||
<a href="https://github.com/aJupyter/EmoLLM/issues">提出新特性</a>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 本篇README.md面向开发者 -->
|
||||
|
||||
**EmoLLM** 是一系列能够支持 **理解用户-支持用户-帮助用户** 心理健康辅导链路的心理健康大模型,由 `LLM`指令微调而来,欢迎大家star~⭐⭐。目前已经开源的 `LLM` 微调配置如下:
|
||||
|
||||
<div align="center">
|
||||
|
||||
| 模型 | 类型 |
|
||||
| :-------------------: | :------: |
|
||||
| InternLM2_7B_chat | QLORA |
|
||||
| InternLM2_7B_chat | 全量微调 |
|
||||
| InternLM2_1_8B_chat | 全量微调 |
|
||||
| InternLM2_20B_chat | LORA |
|
||||
| Qwen_7b_chat | QLORA |
|
||||
| Qwen1_5-0_5B-Chat | 全量微调 |
|
||||
| Baichuan2_13B_chat | QLORA |
|
||||
| ChatGLM3_6B | LORA |
|
||||
| DeepSeek MoE_16B_chat | QLORA |
|
||||
| Mixtral 8x7B_instruct | QLORA |
|
||||
| …… | …… |
|
||||
|
||||
</div>
|
||||
|
||||
欢迎大家为本项目做出贡献~
|
||||
|
||||
---
|
||||
|
||||
心理健康大模型(Mental Health Grand Model)是一个综合性的概念,它旨在全面理解和促进个体、群体乃至整个社会的心理健康状态。这个模型通常包含以下几个关键组成部分:
|
||||
|
||||
- 认知因素:涉及个体的思维模式、信念系统、认知偏差以及解决问题的能力。认知因素对心理健康有重要影响,因为它们影响个体如何解释和应对生活中的事件。
|
||||
- 情感因素:包括情绪调节、情感表达和情感体验。情感健康是心理健康的重要组成部分,涉及个体如何管理和表达自己的情感,以及如何从负面情绪中恢复。
|
||||
- 行为因素:涉及个体的行为模式、习惯和应对策略。这包括应对压力的技巧、社交技能以及自我效能感,即个体对自己能力的信心。
|
||||
- 社会环境:包括家庭、工作、社区和文化背景等外部因素,这些因素对个体的心理健康有着直接和间接的影响。
|
||||
- 生理健康:身体健康与心理健康紧密相关。良好的身体健康可以促进心理健康,反之亦然。
|
||||
- 心理韧性:指个体在面对逆境时的恢复力和适应能力。心理韧性强的人更能够从挑战中恢复,并从中学习和成长。
|
||||
- 预防和干预措施:心理健康大模型还包括预防心理问题和促进心理健康的策略,如心理教育、心理咨询、心理治疗和社会支持系统。
|
||||
- 评估和诊断工具:为了有效促进心理健康,需要有科学的工具来评估个体的心理状态,以及诊断可能存在的心理问题。
|
||||
|
||||
### 🎇最近更新
|
||||
|
||||
- 【2024.3.12】在百度飞浆平台发布[艾薇](https://aistudio.baidu.com/community/app/63335)
|
||||
- 【2024.3.11】 **EmoLLM V2.0 相比 EmoLLM V1.0 全面提升,已超越 Role-playing ChatGPT 在心理咨询任务上的能力!**[点击体验EmoLLM V2.0](https://openxlab.org.cn/apps/detail/Farewell1/EmoLLMV2.0),更新[数据集统计及详细信息](./datasets/)、[路线图](./assets/Roadmap_ZH.png)
|
||||
- 【2024.3.9】 新增并发功能加速 [QA 对生成](./scripts/qa_generation/)、[RAG pipeline](./rag/)
|
||||
- 【2024.3.3】 [基于InternLM2-7B-chat全量微调版本EmoLLM V2.0开源](https://openxlab.org.cn/models/detail/ajupyter/EmoLLM_internlm2_7b_full),需要两块A100*80G,更新专业评估,详见[evaluate](./evaluate/),更新基于PaddleOCR的PDF转txt工具脚本,详见[scripts](./scripts/)
|
||||
- 【2024.2.29】更新客观评估计算,详见[evaluate](./evaluate/),更新一系列数据集,详见[datasets](./datasets/)
|
||||
- 【2024.2.27】更新英文readme和一系列数据集(舔狗和单轮对话)
|
||||
- 【2024.2.23】推出基于InternLM2_7B_chat_qlora的 `温柔御姐心理医生艾薇`,[点击获取模型权重](https://openxlab.org.cn/models/detail/ajupyter/EmoLLM_aiwei),[配置文件](xtuner_config/aiwei-internlm2_chat_7b_qlora.py),[在线体验链接](https://openxlab.org.cn/apps/detail/ajupyter/EmoLLM-aiwei)
|
||||
- 【2024.2.23】更新[若干微调配置](/xtuner_config/),新增 [data_pro.json](/datasets/data_pro.json)(数量更多、场景更全、更丰富)和 [aiwei.json](/datasets/aiwei.json)(温柔御姐角色扮演专用,带有Emoji表情),即将推出 `温柔御姐心理医生艾薇`
|
||||
- 【2024.2.18】 [基于Qwen1_5-0_5B-Chat全量微调版本开源](https://www.modelscope.cn/models/aJupyter/EmoLLM_Qwen1_5-0_5B-Chat_full_sft/summary),算力有限的道友可以玩起来~
|
||||
|
||||
<details>
|
||||
<summary>查看更多</summary>
|
||||
|
||||
- 【2024.2.6】 EmoLLM在[**Openxlab** ](https://openxlab.org.cn/models/detail/jujimeizuo/EmoLLM_Model) 平台下载量高达18.7k,欢迎大家体验!
|
||||
|
||||
<p align="center">
|
||||
<img src="https://github.com/aJupyter/EmoLLM/assets/62385492/7e931682-c54d-4ded-bc67-79130c68d744" alt="模型下载量">
|
||||
</p>
|
||||
|
||||
- 【2024.2.5】 项目荣获公众号**NLP工程化**推文宣传[推文链接](https://mp.weixin.qq.com/s/78lrRl2tlXEKUfElnkVx4A),为博主推广一波,欢迎大家关注!!🥳🥳
|
||||
|
||||
<p align="center">
|
||||
<img src="https://github.com/aJupyter/EmoLLM/assets/62385492/47868d6a-2e91-4aa9-a630-e594c14295b4" alt="公众号二维码">
|
||||
</p>
|
||||
|
||||
- 【2024.2.3】 [项目宣传视频](https://www.bilibili.com/video/BV1N7421N76X/)完成 😊
|
||||
- 【2024.1.27】 完善数据构建文档、微调指南、部署指南、Readme等相关文档 👏
|
||||
- 【2024.1.25】 EmoLLM V1.0 已部署上线 https://openxlab.org.cn/apps/detail/jujimeizuo/EmoLLM 😀
|
||||
|
||||
</details>
|
||||
|
||||
### 🎯路线图
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/aJupyter/EmoLLM/">
|
||||
<img src="https://github.com/SmartFlowAI/EmoLLM/raw/main/assets/Roadmap_ZH.png" alt="Roadmap_ZH">
|
||||
</a>
|
||||
|
||||
## 目录
|
||||
|
||||
- [EmoLLM-心理健康大模型](#emollm-心理健康大模型)
|
||||
- [🎇最近更新](#最近更新)
|
||||
- [🎯路线图](#路线图)
|
||||
- [目录](#目录)
|
||||
- [开发前的配置要求](#开发前的配置要求)
|
||||
- [**使用指南**](#使用指南)
|
||||
- [数据构建](#数据构建)
|
||||
- [微调指南](#微调指南)
|
||||
- [部署指南](#部署指南)
|
||||
- [RAG(检索增强生成)Pipeline](#rag检索增强生成pipeline)
|
||||
- [使用到的框架](#使用到的框架)
|
||||
- [如何参与本项目](#如何参与本项目)
|
||||
- [作者(排名不分先后)](#作者排名不分先后)
|
||||
- [版权说明](#版权说明)
|
||||
- [特别鸣谢](#特别鸣谢)
|
||||
- [Star History](#star-history)
|
||||
- [🌟 Contributors](#-contributors)
|
||||
- [交流群](#交流群)
|
||||
|
||||
###### 开发前的配置要求
|
||||
|
||||
- 硬件:A100 40G(仅针对InternLM2_7B_chat+qlora微调+deepspeed zero2优化)
|
||||
|
||||
###### **使用指南**
|
||||
|
||||
1. Clone the repo
|
||||
|
||||
```sh
|
||||
git clone https://github.com/SmartFlowAI/EmoLLM.git
|
||||
```
|
||||
|
||||
2. 依次阅读或者选择感兴趣的部分阅读:
|
||||
- [数据构建](#数据构建)
|
||||
- [微调指南](#微调指南)
|
||||
- [部署指南](#部署指南)
|
||||
- [RAG](#rag检索增强生成pipeline)
|
||||
- 查看更多详情
|
||||
|
||||
### 数据构建
|
||||
|
||||
- 请阅读[数据构建指南](generate_data/tutorial.md)查阅
|
||||
|
||||
- 微调用到的数据集见[datasets](datasets/data.json)
|
||||
|
||||
### 微调指南
|
||||
|
||||
详见[微调指南](xtuner_config/README.md)
|
||||
|
||||
### 部署指南
|
||||
|
||||
- Demo部署:详见[部署指南](demo/README.md)
|
||||
- 基于[LMDeploy](https://github.com/InternLM/lmdeploy/)的量化部署:详见[deploy](./deploy/lmdeploy.md)
|
||||
|
||||
### RAG(检索增强生成)Pipeline
|
||||
|
||||
- 详见[RAG](./rag/)
|
||||
|
||||
<details>
|
||||
<summary>更多详情</summary>
|
||||
|
||||
### 使用到的框架
|
||||
|
||||
- [Xtuner](https://github.com/InternLM/xtuner):用于微调
|
||||
- [Transformers](https://github.com/huggingface/transformers)
|
||||
- [Pytorch](https://pytorch.org/)
|
||||
- [LMDeploy](https://github.com/InternLM/lmdeploy/):用于量化部署
|
||||
- [Stremlit](https://streamlit.io/):用于构建Demo
|
||||
- [DeepSpeed](https://github.com/microsoft/DeepSpeed):并行训练
|
||||
- …
|
||||
|
||||
#### 如何参与本项目
|
||||
|
||||
贡献使开源社区成为一个学习、激励和创造的绝佳场所。你所作的任何贡献都是**非常感谢**的。
|
||||
|
||||
1. Fork the Project
|
||||
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
||||
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
||||
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
||||
5. Open a Pull Request
|
||||
|
||||
</details>
|
||||
|
||||
### 作者(排名不分先后)
|
||||
|
||||
| 用户名 | 学校/组织 | 备注 | 贡献 |
|
||||
| :----------: | :--------------------: | :-------------------: | :----------: |
|
||||
| [aJupyter](https://github.com/aJupyter) | 南开大学在读硕士 | DataWhale成员 | 项目发起人 |
|
||||
| [jujimeizuo](https://github.com/jujimeizuo) | 江南大学在读硕士 | | |
|
||||
| [Smiling-Weeping-zhr](https://github.com/Smiling-Weeping-zhr) | 哈尔滨工业大学(威海)在读本科生 | | |
|
||||
| [8baby8](https://github.com/8baby8) | 飞桨领航团区域主管 | 文心大模型核心开发者 | |
|
||||
| [zxazys](https://github.com/zxazys) | 南开大学在读硕士 | | |
|
||||
| [MING-ZCH](https://github.com/MING-ZCH) | 华中科技大学在读本科生 | | |
|
||||
| [JasonLLLLLLLLLLL](https://github.com/JasonLLLLLLLLLLL) | swufe | | |
|
||||
| [MrCatAI](https://github.com/MrCatAI) | AI搬用工 | | |
|
||||
| [ZeyuBa](https://github.com/ZeyuBa) | 自动化所在读硕士 | | |
|
||||
| [aiyinyuedejustin](https://github.com/aiyinyuedejustin) | 宾夕法尼亚大学在读硕士 | | |
|
||||
| [Nobody-ML](https://github.com/Nobody-ML) | 中国石油大学(华东)在读本科生 | | |
|
||||
| [chg0901](https://github.com/chg0901) | [MiniSora](https://github.com/mini-sora/minisora/) |MiniSora主要维护|数据清洗、文档翻译|
|
||||
| [Mxoder](https://github.com/Mxoder) | 北京航空航天大学在读本科生 | | |
|
||||
| [Anooyman](https://github.com/Anooyman) | 南京理工大学硕士 | | |
|
||||
| [Vicky-3021](https://github.com/Vicky-3021) | 西安电子科技大学硕士(研0) | | |
|
||||
| [SantiagoTOP](https://github.com/santiagoTOP) | 太原理工大学在读硕士 | | |
|
||||
|
||||
### 版权说明
|
||||
|
||||
该项目签署了 MIT 授权许可,详情请参阅 [LICENSE](https://github.com/SmartFlowAI/EmoLLM/blob/main/LICENSE)
|
||||
|
||||
|
||||
### 引用
|
||||
如果本项目对您的工作有所帮助,请使用以下格式引用:
|
||||
|
||||
```bibtex
|
||||
@misc{EmoLLM,
|
||||
title={EmoLLM},
|
||||
author={EmoLLM},
|
||||
url={https://github.com/SmartFlowAI/EmoLLM/},
|
||||
year={2024}
|
||||
}
|
||||
```
|
||||
|
||||
### 特别鸣谢
|
||||
|
||||
- [Sanbu](https://github.com/sanbuphy)
|
||||
- [上海人工智能实验室](https://www.shlab.org.cn/)
|
||||
- [闻星大佬(小助手)](https://github.com/vansin)
|
||||
- [扫地升(公众号宣传)](https://mp.weixin.qq.com/s/78lrRl2tlXEKUfElnkVx4A)
|
||||
- 阿布(北大心理学硕士)
|
||||
|
||||
<!-- links -->
|
||||
|
||||
<!-- [linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555 -->
|
||||
|
||||
<!-- [linkedin-url]: https://linkedin.com/in/aJupyter -->
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://star-history.com/#SmartFlowAI/EmoLLM&Date)
|
||||
|
||||
## 🌟 Contributors
|
||||
|
||||
[](https://github.com/SmartFlowAI/EmoLLM/graphs/contributors)
|
||||
|
||||
[your-project-path]: SmartflowAI/EmoLLM
|
||||
[contributors-shield]: https://img.shields.io/github/contributors/SmartflowAI/EmoLLM.svg?style=flat-square
|
||||
[contributors-url]: https://github.com/SmartflowAI/EmoLLM/graphs/contributors
|
||||
[forks-shield]: https://img.shields.io/github/forks/SmartflowAI/EmoLLM.svg?style=flat-square
|
||||
[forks-url]: https://github.com/SmartflowAI/EmoLLM/network/members
|
||||
[stars-shield]: https://img.shields.io/github/stars/SmartflowAI/EmoLLM.svg?style=flat-square
|
||||
[stars-url]: https://github.com/SmartflowAI/EmoLLM/stargazers
|
||||
[issues-shield]: https://img.shields.io/github/issues/SmartflowAI/EmoLLM.svg?style=flat-square
|
||||
[issues-url]: https://img.shields.io/github/issues/SmartflowAI/EmoLLM.svg
|
||||
[license-shield]: https://img.shields.io/github/license/SmartflowAI/EmoLLM.svg?style=flat-square
|
||||
[license-url]: https://github.com/SmartFlowAI/EmoLLM/blob/main/LICENSE
|
||||
|
||||
[OpenXLab_App-image]: https://cdn-static.openxlab.org.cn/app-center/openxlab_app.svg
|
||||
[OpenXLab_Model-image]: https://cdn-static.openxlab.org.cn/header/openxlab_models.svg
|
||||
[OpenXLab_App-url]: https://openxlab.org.cn/apps/detail/Farewell1/EmoLLMV2.0
|
||||
[OpenXLab_Model-url]: https://openxlab.org.cn/models/detail/ajupyter/EmoLLM_internlm2_7b_full
|
||||
|
||||
|
||||
## 交流群
|
||||
|
||||
- 如果失效,请移步Issue区
|
||||
|
||||
<p align="center">
|
||||
<img width="30%" src="https://github.com/SmartFlowAI/EmoLLM/assets/62385492/55ecd0aa-4832-4269-ad57-4c26f9aa286b" alt="EmoLLM官方交流群">
|
||||
</p>
|
||||
37
config.json
Normal file
37
config.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"_name_or_path": "/root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat",
|
||||
"architectures": [
|
||||
"InternLM2ForCausalLM"
|
||||
],
|
||||
"attn_implementation": "flash_attention_2",
|
||||
"auto_map": {
|
||||
"AutoConfig": "configuration_internlm2.InternLM2Config",
|
||||
"AutoModel": "modeling_internlm2.InternLM2ForCausalLM",
|
||||
"AutoModelForCausalLM": "modeling_internlm2.InternLM2ForCausalLM"
|
||||
},
|
||||
"bias": false,
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": 2,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 4096,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 14336,
|
||||
"max_position_embeddings": 32768,
|
||||
"model_type": "internlm2",
|
||||
"num_attention_heads": 32,
|
||||
"num_hidden_layers": 32,
|
||||
"num_key_value_heads": 8,
|
||||
"pad_token_id": 2,
|
||||
"pretraining_tp": 1,
|
||||
"rms_norm_eps": 1e-05,
|
||||
"rope_scaling": {
|
||||
"factor": 2.0,
|
||||
"type": "dynamic"
|
||||
},
|
||||
"rope_theta": 1000000,
|
||||
"tie_word_embeddings": false,
|
||||
"torch_dtype": "float16",
|
||||
"transformers_version": "4.41.0",
|
||||
"use_cache": true,
|
||||
"vocab_size": 92544
|
||||
}
|
||||
37
configuration.json
Normal file
37
configuration.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"_name_or_path": "/root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat",
|
||||
"architectures": [
|
||||
"InternLM2ForCausalLM"
|
||||
],
|
||||
"attn_implementation": "flash_attention_2",
|
||||
"auto_map": {
|
||||
"AutoConfig": "configuration_internlm2.InternLM2Config",
|
||||
"AutoModel": "modeling_internlm2.InternLM2ForCausalLM",
|
||||
"AutoModelForCausalLM": "modeling_internlm2.InternLM2ForCausalLM"
|
||||
},
|
||||
"bias": false,
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": 2,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 4096,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 14336,
|
||||
"max_position_embeddings": 32768,
|
||||
"model_type": "internlm2",
|
||||
"num_attention_heads": 32,
|
||||
"num_hidden_layers": 32,
|
||||
"num_key_value_heads": 8,
|
||||
"pad_token_id": 2,
|
||||
"pretraining_tp": 1,
|
||||
"rms_norm_eps": 1e-05,
|
||||
"rope_scaling": {
|
||||
"factor": 2.0,
|
||||
"type": "dynamic"
|
||||
},
|
||||
"rope_theta": 1000000,
|
||||
"tie_word_embeddings": false,
|
||||
"torch_dtype": "float16",
|
||||
"transformers_version": "4.41.0",
|
||||
"use_cache": true,
|
||||
"vocab_size": 92544
|
||||
}
|
||||
180
configuration_internlm2.py
Normal file
180
configuration_internlm2.py
Normal file
@@ -0,0 +1,180 @@
|
||||
# coding=utf-8
|
||||
# Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
|
||||
#
|
||||
# This code is based on transformers/src/transformers/models/llama/configuration_llama.py
|
||||
#
|
||||
# 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.
|
||||
""" InternLM2 model configuration"""
|
||||
|
||||
from transformers.configuration_utils import PretrainedConfig
|
||||
from transformers.utils import logging
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
INTERNLM2_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
|
||||
|
||||
|
||||
# Modified from transformers.model.llama.configuration_llama.LlamaConfig
|
||||
class InternLM2Config(PretrainedConfig):
|
||||
r"""
|
||||
This is the configuration class to store the configuration of a [`InternLM2Model`]. It is used to instantiate
|
||||
an InternLM2 model according to the specified arguments, defining the model architecture. Instantiating a
|
||||
configuration with the defaults will yield a similar configuration to that of the InternLM2-7B.
|
||||
|
||||
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
||||
documentation from [`PretrainedConfig`] for more information.
|
||||
|
||||
|
||||
Args:
|
||||
vocab_size (`int`, *optional*, defaults to 32000):
|
||||
Vocabulary size of the InternLM2 model. Defines the number of different tokens that can be represented by the
|
||||
`inputs_ids` passed when calling [`InternLM2Model`]
|
||||
hidden_size (`int`, *optional*, defaults to 4096):
|
||||
Dimension of the hidden representations.
|
||||
intermediate_size (`int`, *optional*, defaults to 11008):
|
||||
Dimension of the MLP representations.
|
||||
num_hidden_layers (`int`, *optional*, defaults to 32):
|
||||
Number of hidden layers in the Transformer decoder.
|
||||
num_attention_heads (`int`, *optional*, defaults to 32):
|
||||
Number of attention heads for each attention layer in the Transformer decoder.
|
||||
num_key_value_heads (`int`, *optional*):
|
||||
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
||||
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
||||
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
||||
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
||||
by meanpooling all the original heads within that group. For more details checkout [this
|
||||
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
||||
`num_attention_heads`.
|
||||
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
||||
The non-linear activation function (function or string) in the decoder.
|
||||
max_position_embeddings (`int`, *optional*, defaults to 2048):
|
||||
The maximum sequence length that this model might ever be used with. InternLM2 supports up to 32768 tokens.
|
||||
initializer_range (`float`, *optional*, defaults to 0.02):
|
||||
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
||||
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
||||
The epsilon used by the rms normalization layers.
|
||||
use_cache (`bool`, *optional*, defaults to `True`):
|
||||
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
||||
relevant if `config.is_decoder=True`.
|
||||
pad_token_id (`int`, *optional*):
|
||||
Padding token id.
|
||||
bos_token_id (`int`, *optional*, defaults to 1):
|
||||
Beginning of stream token id.
|
||||
eos_token_id (`int`, *optional*, defaults to 2):
|
||||
End of stream token id.
|
||||
pretraining_tp (`int`, *optional*, defaults to 1):
|
||||
Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
|
||||
document](https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism)
|
||||
to understand more about it. This value is necessary to ensure exact reproducibility
|
||||
of the pretraining results. Please refer to [this
|
||||
issue](https://github.com/pytorch/pytorch/issues/76232).
|
||||
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
||||
Whether to tie weight embeddings
|
||||
rope_theta (`float`, *optional*, defaults to 10000.0):
|
||||
The base period of the RoPE embeddings.
|
||||
rope_scaling (`Dict`, *optional*):
|
||||
Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
|
||||
strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
|
||||
`{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
|
||||
`max_position_embeddings` to the expected new maximum. See the following thread for more information on how
|
||||
these scaling strategies behave:
|
||||
https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
|
||||
experimental feature, subject to breaking API changes in future versions.
|
||||
"""
|
||||
_auto_class = "AutoConfig"
|
||||
model_type = "internlm2"
|
||||
keys_to_ignore_at_inference = ["past_key_values"]
|
||||
|
||||
def __init__( # pylint: disable=W0102
|
||||
self,
|
||||
vocab_size=103168,
|
||||
hidden_size=4096,
|
||||
intermediate_size=11008,
|
||||
num_hidden_layers=32,
|
||||
num_attention_heads=32,
|
||||
num_key_value_heads=None,
|
||||
hidden_act="silu",
|
||||
max_position_embeddings=2048,
|
||||
initializer_range=0.02,
|
||||
rms_norm_eps=1e-6,
|
||||
use_cache=True,
|
||||
pad_token_id=0,
|
||||
bos_token_id=1,
|
||||
eos_token_id=2,
|
||||
pretraining_tp=1,
|
||||
tie_word_embeddings=False,
|
||||
bias=True,
|
||||
rope_theta=10000,
|
||||
rope_scaling=None,
|
||||
attn_implementation=None,
|
||||
**kwargs,
|
||||
):
|
||||
self.vocab_size = vocab_size
|
||||
self.max_position_embeddings = max_position_embeddings
|
||||
self.hidden_size = hidden_size
|
||||
self.intermediate_size = intermediate_size
|
||||
self.num_hidden_layers = num_hidden_layers
|
||||
self.num_attention_heads = num_attention_heads
|
||||
self.bias = bias
|
||||
|
||||
if num_key_value_heads is None:
|
||||
num_key_value_heads = num_attention_heads
|
||||
self.num_key_value_heads = num_key_value_heads
|
||||
|
||||
self.hidden_act = hidden_act
|
||||
self.initializer_range = initializer_range
|
||||
self.rms_norm_eps = rms_norm_eps
|
||||
self.pretraining_tp = pretraining_tp
|
||||
self.use_cache = use_cache
|
||||
self.rope_theta = rope_theta
|
||||
self.rope_scaling = rope_scaling
|
||||
self._rope_scaling_validation()
|
||||
self.attn_implementation = attn_implementation
|
||||
if self.attn_implementation is None:
|
||||
self.attn_implementation = "eager"
|
||||
|
||||
super().__init__(
|
||||
pad_token_id=pad_token_id,
|
||||
bos_token_id=bos_token_id,
|
||||
eos_token_id=eos_token_id,
|
||||
tie_word_embeddings=tie_word_embeddings,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def _rope_scaling_validation(self):
|
||||
"""
|
||||
Validate the `rope_scaling` configuration.
|
||||
"""
|
||||
if self.rope_scaling is None:
|
||||
return
|
||||
|
||||
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
|
||||
raise ValueError(
|
||||
"`rope_scaling` must be a dictionary with with two fields, `type` and `factor`, "
|
||||
f"got {self.rope_scaling}"
|
||||
)
|
||||
rope_scaling_type = self.rope_scaling.get("type", None)
|
||||
rope_scaling_factor = self.rope_scaling.get("factor", None)
|
||||
if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
|
||||
raise ValueError(
|
||||
f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
|
||||
)
|
||||
if (
|
||||
rope_scaling_factor is None
|
||||
or not isinstance(rope_scaling_factor, (float, int))
|
||||
or rope_scaling_factor < 1.0
|
||||
):
|
||||
raise ValueError(
|
||||
f"`rope_scaling`'s factor field must be a number >= 1, got {rope_scaling_factor} "
|
||||
f"of type {type(rope_scaling_factor)}"
|
||||
)
|
||||
9
generation_config.json
Normal file
9
generation_config.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": [
|
||||
2,
|
||||
92542
|
||||
],
|
||||
"pad_token_id": 2,
|
||||
"transformers_version": "4.41.0"
|
||||
}
|
||||
3
model-00001-of-00008.safetensors
Normal file
3
model-00001-of-00008.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7e97992f50fef7308346db63be9a333acc71685fa942134cb35de0c353707cd0
|
||||
size 1949337688
|
||||
3
model-00002-of-00008.safetensors
Normal file
3
model-00002-of-00008.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7195af4f5a0e3bf1a388cf733775181f083ff3cc3fe258390a052a2d96242413
|
||||
size 1946242664
|
||||
3
model-00003-of-00008.safetensors
Normal file
3
model-00003-of-00008.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4a315a52b4c9e60df75adee91f75cc84e2da118efb0b84e7f815e573cbecaab2
|
||||
size 1979780408
|
||||
3
model-00004-of-00008.safetensors
Normal file
3
model-00004-of-00008.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:9a9cb4485636a3e2af84c328a5f18f8ce08ebf4453984cfc27a2a17214f9ce38
|
||||
size 1946242696
|
||||
3
model-00005-of-00008.safetensors
Normal file
3
model-00005-of-00008.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:841d8fe632f8913328a542155edb86a27703f524f0deac42a1ebe18925548cb0
|
||||
size 1979780424
|
||||
3
model-00006-of-00008.safetensors
Normal file
3
model-00006-of-00008.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:da527ee8de0b5eecf80d2aa3b40a9f481d51906ce3429625bc0e6bfa86bdfdf9
|
||||
size 1946242696
|
||||
3
model-00007-of-00008.safetensors
Normal file
3
model-00007-of-00008.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:614ed8960c770af96c521cde3e2579715727fc867671b3a4a092a22a40b5bdf7
|
||||
size 1979780424
|
||||
3
model-00008-of-00008.safetensors
Normal file
3
model-00008-of-00008.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b3c8df646886777b64d24367c84f3792e3a597bdcb3e400566d5d6275c1f9689
|
||||
size 1748035624
|
||||
234
model.safetensors.index.json
Normal file
234
model.safetensors.index.json
Normal file
@@ -0,0 +1,234 @@
|
||||
{
|
||||
"metadata": {
|
||||
"total_size": 15475417088
|
||||
},
|
||||
"weight_map": {
|
||||
"model.layers.0.attention.wo.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.0.attention.wqkv.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.0.attention_norm.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.0.feed_forward.w1.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.0.feed_forward.w2.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.0.feed_forward.w3.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.0.ffn_norm.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.1.attention.wo.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.1.attention.wqkv.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.1.attention_norm.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.1.feed_forward.w1.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.1.feed_forward.w2.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.1.feed_forward.w3.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.1.ffn_norm.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.10.attention.wo.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.10.attention.wqkv.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.10.attention_norm.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.10.feed_forward.w1.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.10.feed_forward.w2.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.10.feed_forward.w3.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.10.ffn_norm.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.11.attention.wo.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.11.attention.wqkv.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.11.attention_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.11.feed_forward.w1.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.11.feed_forward.w2.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.11.feed_forward.w3.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.11.ffn_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.12.attention.wo.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.12.attention.wqkv.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.12.attention_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.12.feed_forward.w1.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.12.feed_forward.w2.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.12.feed_forward.w3.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.12.ffn_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.13.attention.wo.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.13.attention.wqkv.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.13.attention_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.13.feed_forward.w1.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.13.feed_forward.w2.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.13.feed_forward.w3.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.13.ffn_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.14.attention.wo.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.14.attention.wqkv.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.14.attention_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.14.feed_forward.w1.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.14.feed_forward.w2.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.14.feed_forward.w3.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.14.ffn_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.15.attention.wo.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.15.attention.wqkv.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.15.attention_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.15.feed_forward.w1.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.15.feed_forward.w2.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.15.feed_forward.w3.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.15.ffn_norm.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.16.attention.wo.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.16.attention.wqkv.weight": "model-00004-of-00008.safetensors",
|
||||
"model.layers.16.attention_norm.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.16.feed_forward.w1.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.16.feed_forward.w2.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.16.feed_forward.w3.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.16.ffn_norm.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.17.attention.wo.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.17.attention.wqkv.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.17.attention_norm.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.17.feed_forward.w1.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.17.feed_forward.w2.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.17.feed_forward.w3.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.17.ffn_norm.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.18.attention.wo.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.18.attention.wqkv.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.18.attention_norm.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.18.feed_forward.w1.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.18.feed_forward.w2.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.18.feed_forward.w3.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.18.ffn_norm.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.19.attention.wo.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.19.attention.wqkv.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.19.attention_norm.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.19.feed_forward.w1.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.19.feed_forward.w2.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.19.feed_forward.w3.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.19.ffn_norm.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.2.attention.wo.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.2.attention.wqkv.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.2.attention_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.2.feed_forward.w1.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.2.feed_forward.w2.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.2.feed_forward.w3.weight": "model-00001-of-00008.safetensors",
|
||||
"model.layers.2.ffn_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.20.attention.wo.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.20.attention.wqkv.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.20.attention_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.20.feed_forward.w1.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.20.feed_forward.w2.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.20.feed_forward.w3.weight": "model-00005-of-00008.safetensors",
|
||||
"model.layers.20.ffn_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.21.attention.wo.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.21.attention.wqkv.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.21.attention_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.21.feed_forward.w1.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.21.feed_forward.w2.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.21.feed_forward.w3.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.21.ffn_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.22.attention.wo.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.22.attention.wqkv.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.22.attention_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.22.feed_forward.w1.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.22.feed_forward.w2.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.22.feed_forward.w3.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.22.ffn_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.23.attention.wo.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.23.attention.wqkv.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.23.attention_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.23.feed_forward.w1.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.23.feed_forward.w2.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.23.feed_forward.w3.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.23.ffn_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.24.attention.wo.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.24.attention.wqkv.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.24.attention_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.24.feed_forward.w1.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.24.feed_forward.w2.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.24.feed_forward.w3.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.24.ffn_norm.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.25.attention.wo.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.25.attention.wqkv.weight": "model-00006-of-00008.safetensors",
|
||||
"model.layers.25.attention_norm.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.25.feed_forward.w1.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.25.feed_forward.w2.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.25.feed_forward.w3.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.25.ffn_norm.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.26.attention.wo.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.26.attention.wqkv.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.26.attention_norm.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.26.feed_forward.w1.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.26.feed_forward.w2.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.26.feed_forward.w3.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.26.ffn_norm.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.27.attention.wo.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.27.attention.wqkv.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.27.attention_norm.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.27.feed_forward.w1.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.27.feed_forward.w2.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.27.feed_forward.w3.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.27.ffn_norm.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.28.attention.wo.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.28.attention.wqkv.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.28.attention_norm.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.28.feed_forward.w1.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.28.feed_forward.w2.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.28.feed_forward.w3.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.28.ffn_norm.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.29.attention.wo.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.29.attention.wqkv.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.29.attention_norm.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.29.feed_forward.w1.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.29.feed_forward.w2.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.29.feed_forward.w3.weight": "model-00007-of-00008.safetensors",
|
||||
"model.layers.29.ffn_norm.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.3.attention.wo.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.3.attention.wqkv.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.3.attention_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.3.feed_forward.w1.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.3.feed_forward.w2.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.3.feed_forward.w3.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.3.ffn_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.30.attention.wo.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.30.attention.wqkv.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.30.attention_norm.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.30.feed_forward.w1.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.30.feed_forward.w2.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.30.feed_forward.w3.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.30.ffn_norm.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.31.attention.wo.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.31.attention.wqkv.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.31.attention_norm.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.31.feed_forward.w1.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.31.feed_forward.w2.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.31.feed_forward.w3.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.31.ffn_norm.weight": "model-00008-of-00008.safetensors",
|
||||
"model.layers.4.attention.wo.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.4.attention.wqkv.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.4.attention_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.4.feed_forward.w1.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.4.feed_forward.w2.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.4.feed_forward.w3.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.4.ffn_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.5.attention.wo.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.5.attention.wqkv.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.5.attention_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.5.feed_forward.w1.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.5.feed_forward.w2.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.5.feed_forward.w3.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.5.ffn_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.6.attention.wo.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.6.attention.wqkv.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.6.attention_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.6.feed_forward.w1.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.6.feed_forward.w2.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.6.feed_forward.w3.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.6.ffn_norm.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.7.attention.wo.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.7.attention.wqkv.weight": "model-00002-of-00008.safetensors",
|
||||
"model.layers.7.attention_norm.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.7.feed_forward.w1.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.7.feed_forward.w2.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.7.feed_forward.w3.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.7.ffn_norm.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.8.attention.wo.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.8.attention.wqkv.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.8.attention_norm.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.8.feed_forward.w1.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.8.feed_forward.w2.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.8.feed_forward.w3.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.8.ffn_norm.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.9.attention.wo.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.9.attention.wqkv.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.9.attention_norm.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.9.feed_forward.w1.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.9.feed_forward.w2.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.9.feed_forward.w3.weight": "model-00003-of-00008.safetensors",
|
||||
"model.layers.9.ffn_norm.weight": "model-00003-of-00008.safetensors",
|
||||
"model.norm.weight": "model-00008-of-00008.safetensors",
|
||||
"model.tok_embeddings.weight": "model-00001-of-00008.safetensors",
|
||||
"output.weight": "model-00008-of-00008.safetensors"
|
||||
}
|
||||
}
|
||||
1800
modeling_internlm2.py
Normal file
1800
modeling_internlm2.py
Normal file
File diff suppressed because it is too large
Load Diff
38
special_tokens_map.json
Normal file
38
special_tokens_map.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"additional_special_tokens": [
|
||||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
"<|action_start|>",
|
||||
"<|action_end|>",
|
||||
"<|interpreter|>",
|
||||
"<|plugin|>"
|
||||
],
|
||||
"bos_token": {
|
||||
"content": "<s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"eos_token": {
|
||||
"content": "</s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"pad_token": {
|
||||
"content": "</s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"unk_token": {
|
||||
"content": "<unk>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
}
|
||||
}
|
||||
236
tokenization_internlm2.py
Normal file
236
tokenization_internlm2.py
Normal file
@@ -0,0 +1,236 @@
|
||||
# coding=utf-8
|
||||
# Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
|
||||
#
|
||||
# This code is based on transformers/src/transformers/models/llama/tokenization_llama.py
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""Tokenization classes for InternLM."""
|
||||
import os
|
||||
from shutil import copyfile
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
import sentencepiece as spm
|
||||
from transformers.tokenization_utils import PreTrainedTokenizer
|
||||
from transformers.utils import logging
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
VOCAB_FILES_NAMES = {"vocab_file": "./tokenizer.model"}
|
||||
|
||||
PRETRAINED_VOCAB_FILES_MAP = {}
|
||||
|
||||
|
||||
# Modified from transformers.model.llama.tokenization_llama.LlamaTokenizer
|
||||
class InternLM2Tokenizer(PreTrainedTokenizer):
|
||||
"""
|
||||
Construct a InternLM2 tokenizer. Based on byte-level Byte-Pair-Encoding.
|
||||
|
||||
Args:
|
||||
vocab_file (`str`):
|
||||
Path to the vocabulary file.
|
||||
"""
|
||||
|
||||
vocab_files_names = VOCAB_FILES_NAMES
|
||||
pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
|
||||
model_input_names = ["input_ids", "attention_mask"]
|
||||
_auto_class = "AutoTokenizer"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vocab_file,
|
||||
unk_token="<unk>",
|
||||
bos_token="<s>",
|
||||
eos_token="</s>",
|
||||
pad_token="</s>",
|
||||
sp_model_kwargs: Optional[Dict[str, Any]] = None,
|
||||
add_bos_token=True,
|
||||
add_eos_token=False,
|
||||
decode_with_prefix_space=False,
|
||||
clean_up_tokenization_spaces=False,
|
||||
**kwargs,
|
||||
):
|
||||
self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
|
||||
self.vocab_file = vocab_file
|
||||
self.add_bos_token = add_bos_token
|
||||
self.add_eos_token = add_eos_token
|
||||
self.decode_with_prefix_space = decode_with_prefix_space
|
||||
self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
|
||||
self.sp_model.Load(vocab_file)
|
||||
self._no_prefix_space_tokens = None
|
||||
super().__init__(
|
||||
bos_token=bos_token,
|
||||
eos_token=eos_token,
|
||||
unk_token=unk_token,
|
||||
pad_token=pad_token,
|
||||
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
@property
|
||||
def no_prefix_space_tokens(self):
|
||||
if self._no_prefix_space_tokens is None:
|
||||
vocab = self.convert_ids_to_tokens(list(range(self.vocab_size)))
|
||||
self._no_prefix_space_tokens = {i for i, tok in enumerate(vocab) if not tok.startswith("▁")}
|
||||
return self._no_prefix_space_tokens
|
||||
|
||||
@property
|
||||
def vocab_size(self):
|
||||
"""Returns vocab size"""
|
||||
return self.sp_model.get_piece_size()
|
||||
|
||||
@property
|
||||
def bos_token_id(self) -> Optional[int]:
|
||||
return self.sp_model.bos_id()
|
||||
|
||||
@property
|
||||
def eos_token_id(self) -> Optional[int]:
|
||||
return self.sp_model.eos_id()
|
||||
|
||||
def get_vocab(self):
|
||||
"""Returns vocab as a dict"""
|
||||
vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
|
||||
vocab.update(self.added_tokens_encoder)
|
||||
return vocab
|
||||
|
||||
def _tokenize(self, text):
|
||||
"""Returns a tokenized string."""
|
||||
return self.sp_model.encode(text, out_type=str)
|
||||
|
||||
def _convert_token_to_id(self, token):
|
||||
"""Converts a token (str) in an id using the vocab."""
|
||||
return self.sp_model.piece_to_id(token)
|
||||
|
||||
def _convert_id_to_token(self, index):
|
||||
"""Converts an index (integer) in a token (str) using the vocab."""
|
||||
token = self.sp_model.IdToPiece(index)
|
||||
return token
|
||||
|
||||
def _maybe_add_prefix_space(self, tokens, decoded):
|
||||
if tokens and tokens[0] not in self.no_prefix_space_tokens:
|
||||
return " " + decoded
|
||||
else:
|
||||
return decoded
|
||||
|
||||
def convert_tokens_to_string(self, tokens):
|
||||
"""Converts a sequence of tokens (string) in a single string."""
|
||||
current_sub_tokens = []
|
||||
out_string = ""
|
||||
prev_is_special = False
|
||||
for token in tokens:
|
||||
# make sure that special tokens are not decoded using sentencepiece model
|
||||
if token in self.all_special_tokens:
|
||||
if not prev_is_special:
|
||||
out_string += " "
|
||||
out_string += self.sp_model.decode(current_sub_tokens) + token
|
||||
prev_is_special = True
|
||||
current_sub_tokens = []
|
||||
else:
|
||||
current_sub_tokens.append(token)
|
||||
prev_is_special = False
|
||||
out_string += self.sp_model.decode(current_sub_tokens)
|
||||
out_string = self.clean_up_tokenization(out_string)
|
||||
out_string = self._maybe_add_prefix_space(tokens=tokens, decoded=out_string)
|
||||
return out_string[1:]
|
||||
|
||||
def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
|
||||
"""
|
||||
Save the vocabulary and special tokens file to a directory.
|
||||
|
||||
Args:
|
||||
save_directory (`str`):
|
||||
The directory in which to save the vocabulary.
|
||||
|
||||
Returns:
|
||||
`Tuple(str)`: Paths to the files saved.
|
||||
"""
|
||||
if not os.path.isdir(save_directory):
|
||||
logger.error(f"Vocabulary path ({save_directory}) should be a directory")
|
||||
return
|
||||
out_vocab_file = os.path.join(
|
||||
save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
|
||||
)
|
||||
|
||||
if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
|
||||
copyfile(self.vocab_file, out_vocab_file)
|
||||
elif not os.path.isfile(self.vocab_file):
|
||||
with open(out_vocab_file, "wb") as fi:
|
||||
content_spiece_model = self.sp_model.serialized_model_proto()
|
||||
fi.write(content_spiece_model)
|
||||
|
||||
return (out_vocab_file,)
|
||||
|
||||
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
|
||||
if self.add_bos_token:
|
||||
bos_token_ids = [self.bos_token_id]
|
||||
else:
|
||||
bos_token_ids = []
|
||||
|
||||
output = bos_token_ids + token_ids_0
|
||||
|
||||
if token_ids_1 is not None:
|
||||
output = output + token_ids_1
|
||||
|
||||
if self.add_eos_token:
|
||||
output = output + [self.eos_token_id]
|
||||
|
||||
return output
|
||||
|
||||
def get_special_tokens_mask(
|
||||
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
|
||||
) -> List[int]:
|
||||
"""
|
||||
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
|
||||
special tokens using the tokenizer `prepare_for_model` method.
|
||||
|
||||
Args:
|
||||
token_ids_0 (`List[int]`):
|
||||
List of IDs.
|
||||
token_ids_1 (`List[int]`, *optional*):
|
||||
Optional second list of IDs for sequence pairs.
|
||||
already_has_special_tokens (`bool`, *optional*, defaults to `False`):
|
||||
Whether or not the token list is already formatted with special tokens for the model.
|
||||
|
||||
Returns:
|
||||
`List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
|
||||
"""
|
||||
if already_has_special_tokens:
|
||||
return super().get_special_tokens_mask(
|
||||
token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
|
||||
)
|
||||
|
||||
if token_ids_1 is None:
|
||||
return [1] + ([0] * len(token_ids_0)) + [1]
|
||||
return [1] + ([0] * len(token_ids_0)) + [1, 1] + ([0] * len(token_ids_1)) + [1]
|
||||
|
||||
def create_token_type_ids_from_sequences(
|
||||
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
|
||||
) -> List[int]:
|
||||
"""
|
||||
Create a mask from the two sequences passed to be used in a sequence-pair classification task. T5 does not make
|
||||
use of token type ids, therefore a list of zeros is returned.
|
||||
|
||||
Args:
|
||||
token_ids_0 (`List[int]`):
|
||||
List of IDs.
|
||||
token_ids_1 (`List[int]`, *optional*):
|
||||
Optional second list of IDs for sequence pairs.
|
||||
|
||||
Returns:
|
||||
`List[int]`: List of zeros.
|
||||
"""
|
||||
eos = [self.eos_token_id]
|
||||
|
||||
if token_ids_1 is None:
|
||||
return len(token_ids_0 + eos) * [0]
|
||||
return len(token_ids_0 + eos + token_ids_1 + eos) * [0]
|
||||
214
tokenization_internlm2_fast.py
Normal file
214
tokenization_internlm2_fast.py
Normal file
@@ -0,0 +1,214 @@
|
||||
# coding=utf-8
|
||||
# Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
|
||||
#
|
||||
# This code is based on transformers/src/transformers/models/llama/tokenization_llama_fast.py
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""Tokenization Fast class for InternLM."""
|
||||
import os
|
||||
from shutil import copyfile
|
||||
from typing import Any, Dict, Optional, Tuple
|
||||
|
||||
from tokenizers import processors, decoders, Tokenizer, normalizers
|
||||
from tokenizers.models import BPE
|
||||
|
||||
from transformers.tokenization_utils_fast import PreTrainedTokenizerFast
|
||||
from transformers.utils import logging
|
||||
|
||||
from transformers.convert_slow_tokenizer import (
|
||||
SLOW_TO_FAST_CONVERTERS,
|
||||
SpmConverter,
|
||||
SentencePieceExtractor,
|
||||
)
|
||||
|
||||
from .tokenization_internlm2 import InternLM2Tokenizer
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
VOCAB_FILES_NAMES = {"vocab_file": "./tokenizer.model"}
|
||||
|
||||
# Modified from transformers.convert_slow_tokenizer.LlamaConverter
|
||||
class InternLM2Converter(SpmConverter):
|
||||
handle_byte_fallback = True
|
||||
|
||||
def vocab(self, proto):
|
||||
vocab = [
|
||||
("<unk>", 0.0),
|
||||
("<s>", 0.0),
|
||||
("</s>", 0.0),
|
||||
]
|
||||
vocab += [(piece.piece, piece.score) for piece in proto.pieces[3:]]
|
||||
return vocab
|
||||
|
||||
def unk_id(self, proto):
|
||||
unk_id = 0
|
||||
return unk_id
|
||||
|
||||
def decoder(self, replacement, add_prefix_space):
|
||||
decoders_sequence = [
|
||||
decoders.Replace("▁", " "),
|
||||
decoders.ByteFallback(),
|
||||
decoders.Fuse(),
|
||||
]
|
||||
if self.proto.normalizer_spec.add_dummy_prefix:
|
||||
decoders_sequence.append(decoders.Strip(content=" ", left=1))
|
||||
return decoders.Sequence(decoders_sequence)
|
||||
|
||||
def tokenizer(self, proto):
|
||||
model_type = proto.trainer_spec.model_type
|
||||
vocab_scores = self.vocab(proto)
|
||||
# special tokens
|
||||
added_tokens = self.original_tokenizer.added_tokens_decoder
|
||||
for i in range(len(vocab_scores)):
|
||||
piece, score = vocab_scores[i]
|
||||
if i in added_tokens:
|
||||
vocab_scores[i] = (added_tokens[i].content, score)
|
||||
if model_type == 1:
|
||||
raise RuntimeError("InternLM2 is supposed to be a BPE model!")
|
||||
|
||||
elif model_type == 2:
|
||||
_, merges = SentencePieceExtractor(self.original_tokenizer.vocab_file).extract(vocab_scores)
|
||||
bpe_vocab = {word: i for i, (word, _score) in enumerate(vocab_scores)}
|
||||
tokenizer = Tokenizer(
|
||||
BPE(bpe_vocab, merges, unk_token=proto.trainer_spec.unk_piece, fuse_unk=True, byte_fallback=True)
|
||||
)
|
||||
tokenizer.add_special_tokens(
|
||||
[ added_token for index, added_token in added_tokens.items()]
|
||||
)
|
||||
else:
|
||||
raise Exception(
|
||||
"You're trying to run a `Unigram` model but you're file was trained with a different algorithm"
|
||||
)
|
||||
|
||||
return tokenizer
|
||||
|
||||
def normalizer(self, proto):
|
||||
normalizers_list = []
|
||||
if proto.normalizer_spec.add_dummy_prefix:
|
||||
normalizers_list.append(normalizers.Prepend(prepend="▁"))
|
||||
normalizers_list.append(normalizers.Replace(pattern=" ", content="▁"))
|
||||
return normalizers.Sequence(normalizers_list)
|
||||
|
||||
def pre_tokenizer(self, replacement, add_prefix_space):
|
||||
return None
|
||||
|
||||
SLOW_TO_FAST_CONVERTERS["InternLM2Tokenizer"] = InternLM2Converter
|
||||
|
||||
|
||||
# Modified from transformers.model.llama.tokenization_llama_fast.LlamaTokenizerFast -> InternLM2TokenizerFast
|
||||
class InternLM2TokenizerFast(PreTrainedTokenizerFast):
|
||||
vocab_files_names = VOCAB_FILES_NAMES
|
||||
slow_tokenizer_class = InternLM2Tokenizer
|
||||
padding_side = "left"
|
||||
model_input_names = ["input_ids", "attention_mask"]
|
||||
_auto_class = "AutoTokenizer"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vocab_file,
|
||||
unk_token="<unk>",
|
||||
bos_token="<s>",
|
||||
eos_token="</s>",
|
||||
pad_token="</s>",
|
||||
sp_model_kwargs: Optional[Dict[str, Any]] = None,
|
||||
add_bos_token=True,
|
||||
add_eos_token=False,
|
||||
decode_with_prefix_space=False,
|
||||
clean_up_tokenization_spaces=False,
|
||||
**kwargs,
|
||||
):
|
||||
super().__init__(
|
||||
vocab_file=vocab_file,
|
||||
unk_token=unk_token,
|
||||
bos_token=bos_token,
|
||||
eos_token=eos_token,
|
||||
pad_token=pad_token,
|
||||
sp_model_kwargs=sp_model_kwargs,
|
||||
add_bos_token=add_bos_token,
|
||||
add_eos_token=add_eos_token,
|
||||
decode_with_prefix_space=decode_with_prefix_space,
|
||||
clean_up_tokenization_spaces=clean_up_tokenization_spaces,
|
||||
**kwargs,
|
||||
)
|
||||
self._add_bos_token = add_bos_token
|
||||
self._add_eos_token = add_eos_token
|
||||
self.update_post_processor()
|
||||
self.vocab_file = vocab_file
|
||||
|
||||
@property
|
||||
def can_save_slow_tokenizer(self) -> bool:
|
||||
return os.path.isfile(self.vocab_file) if self.vocab_file else False
|
||||
|
||||
def update_post_processor(self):
|
||||
"""
|
||||
Updates the underlying post processor with the current `bos_token` and `eos_token`.
|
||||
"""
|
||||
bos = self.bos_token
|
||||
bos_token_id = self.bos_token_id
|
||||
if bos is None and self.add_bos_token:
|
||||
raise ValueError("add_bos_token = True but bos_token = None")
|
||||
|
||||
eos = self.eos_token
|
||||
eos_token_id = self.eos_token_id
|
||||
if eos is None and self.add_eos_token:
|
||||
raise ValueError("add_eos_token = True but eos_token = None")
|
||||
|
||||
single = f"{(bos+':0 ') if self.add_bos_token else ''}$A:0{(' '+eos+':0') if self.add_eos_token else ''}"
|
||||
pair = f"{single}{(' '+bos+':1') if self.add_bos_token else ''} $B:1{(' '+eos+':1') if self.add_eos_token else ''}"
|
||||
|
||||
special_tokens = []
|
||||
if self.add_bos_token:
|
||||
special_tokens.append((bos, bos_token_id))
|
||||
if self.add_eos_token:
|
||||
special_tokens.append((eos, eos_token_id))
|
||||
self._tokenizer.post_processor = processors.TemplateProcessing(
|
||||
single=single, pair=pair, special_tokens=special_tokens
|
||||
)
|
||||
|
||||
@property
|
||||
def add_eos_token(self):
|
||||
return self._add_eos_token
|
||||
|
||||
@property
|
||||
def add_bos_token(self):
|
||||
return self._add_bos_token
|
||||
|
||||
@add_eos_token.setter
|
||||
def add_eos_token(self, value):
|
||||
self._add_eos_token = value
|
||||
self.update_post_processor()
|
||||
|
||||
@add_bos_token.setter
|
||||
def add_bos_token(self, value):
|
||||
self._add_bos_token = value
|
||||
self.update_post_processor()
|
||||
|
||||
def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
|
||||
if not self.can_save_slow_tokenizer:
|
||||
raise ValueError(
|
||||
"Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
|
||||
"tokenizer."
|
||||
)
|
||||
|
||||
if not os.path.isdir(save_directory):
|
||||
logger.error(f"Vocabulary path ({save_directory}) should be a directory")
|
||||
return
|
||||
out_vocab_file = os.path.join(
|
||||
save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
|
||||
)
|
||||
|
||||
if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file):
|
||||
copyfile(self.vocab_file, out_vocab_file)
|
||||
|
||||
return (out_vocab_file,)
|
||||
257843
tokenizer.json
Normal file
257843
tokenizer.json
Normal file
File diff suppressed because it is too large
Load Diff
3
tokenizer.model
Normal file
3
tokenizer.model
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f868398fc4e05ee1e8aeba95ddf18ddcc45b8bce55d5093bead5bbf80429b48b
|
||||
size 1477754
|
||||
103
tokenizer_config.json
Normal file
103
tokenizer_config.json
Normal file
@@ -0,0 +1,103 @@
|
||||
{
|
||||
"add_bos_token": true,
|
||||
"add_eos_token": false,
|
||||
"added_tokens_decoder": {
|
||||
"0": {
|
||||
"content": "<unk>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"1": {
|
||||
"content": "<s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"2": {
|
||||
"content": "</s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"92538": {
|
||||
"content": "<|plugin|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"92539": {
|
||||
"content": "<|interpreter|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"92540": {
|
||||
"content": "<|action_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"92541": {
|
||||
"content": "<|action_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"92542": {
|
||||
"content": "<|im_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"92543": {
|
||||
"content": "<|im_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
}
|
||||
},
|
||||
"additional_special_tokens": [
|
||||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
"<|action_start|>",
|
||||
"<|action_end|>",
|
||||
"<|interpreter|>",
|
||||
"<|plugin|>"
|
||||
],
|
||||
"auto_map": {
|
||||
"AutoTokenizer": [
|
||||
"tokenization_internlm2.InternLM2Tokenizer",
|
||||
"tokenization_internlm2_fast.InternLM2TokenizerFast"
|
||||
]
|
||||
},
|
||||
"bos_token": "<s>",
|
||||
"chat_template": "{{ bos_token }}{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"decode_with_prefix_space": false,
|
||||
"eos_token": "</s>",
|
||||
"model_max_length": 1000000000000000019884624838656,
|
||||
"pad_token": "</s>",
|
||||
"padding_side": "right",
|
||||
"sp_model_kwargs": null,
|
||||
"tokenizer_class": "InternLM2Tokenizer",
|
||||
"unk_token": "<unk>"
|
||||
}
|
||||
243
xtuner_config.py
Normal file
243
xtuner_config.py
Normal file
@@ -0,0 +1,243 @@
|
||||
# Copyright (c) OpenMMLab. All rights reserved.
|
||||
"""
|
||||
Ref: https://github.com/InternLM/xtuner/edit/main/xtuner/configs/internlm/internlm2_5_chat_7b/internlm2_5_chat_7b_full_finetune_custom_dataset_e1.py
|
||||
|
||||
Data format:
|
||||
[
|
||||
{
|
||||
"conversation": [
|
||||
{
|
||||
"system": "",
|
||||
"input": "xxx",
|
||||
"output": "xxx"
|
||||
},
|
||||
{
|
||||
"input": "xxx",
|
||||
"output": "xxx"
|
||||
}
|
||||
]
|
||||
},
|
||||
...
|
||||
]
|
||||
Please refer to https://github.com/InternLM/xtuner/blob/main/docs/en/user_guides/dataset_format.md for details.
|
||||
""" # noqa: E501
|
||||
from datasets import load_dataset
|
||||
from mmengine.hooks import (CheckpointHook, DistSamplerSeedHook, IterTimerHook,
|
||||
LoggerHook, ParamSchedulerHook)
|
||||
from mmengine.optim import AmpOptimWrapper, CosineAnnealingLR
|
||||
from torch.optim import AdamW
|
||||
from torch.utils.data import BatchSampler
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
|
||||
from xtuner.dataset import process_hf_dataset
|
||||
from xtuner.dataset.collate_fns import default_collate_fn
|
||||
from xtuner.dataset.map_fns import template_map_fn_factory
|
||||
from xtuner.dataset.samplers import InternRepoSampler
|
||||
from xtuner.engine import (DatasetInfoHook, EvaluateChatHook, ThroughputHook,
|
||||
VarlenAttnArgsToMessageHubHook)
|
||||
from xtuner.engine.runner import TrainLoop
|
||||
from xtuner.model import SupervisedFinetune
|
||||
from xtuner.utils import PROMPT_TEMPLATE
|
||||
|
||||
#######################################################################
|
||||
# PART 1 Settings #
|
||||
#######################################################################
|
||||
# Model
|
||||
pretrained_model_name_or_path = '/root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat'
|
||||
use_varlen_attn = True
|
||||
|
||||
# Data
|
||||
data_files = ['/root/EmoLLM/datasets/multi_turn_dataset_2.json']
|
||||
prompt_template = PROMPT_TEMPLATE.internlm2_chat
|
||||
# max_length = 32768
|
||||
max_length = int(32768/4) ## A100*2
|
||||
pack_to_max_length = True
|
||||
|
||||
# parallel
|
||||
sequence_parallel_size = 1
|
||||
|
||||
# Scheduler & Optimizer
|
||||
# batch size per device, set to 1 if `use_varlen_attn` = True
|
||||
# To clarify, enlarging the batch size essentially enlarges the `max_length`.
|
||||
# For example, doubling the max length is tantamount to doubling the batch size
|
||||
batch_size = 1
|
||||
accumulative_counts = 1 # 1bs * 1acc * 64gpu = 64 batchsize
|
||||
accumulative_counts *= sequence_parallel_size
|
||||
dataloader_num_workers = 4
|
||||
max_epochs = 3
|
||||
|
||||
optim_type = AdamW
|
||||
lr = 4e-5
|
||||
betas = (0.9, 0.95)
|
||||
weight_decay = 0.01
|
||||
max_norm = 1 # grad clip
|
||||
warm_up_ratio = 0.025
|
||||
|
||||
# Save
|
||||
save_steps = 500
|
||||
save_total_limit = 2 # Maximum checkpoints to keep (-1 means unlimited)
|
||||
|
||||
# Evaluate the generation performance during the training
|
||||
evaluation_freq = 500
|
||||
SYSTEM = "你由EmoLLM团队打造的中文领域心理健康助手, 是一个研究过无数具有心理健康问题的病人与心理健康医生对话的心理专家, 在心理方面拥有广博的知识储备和丰富的研究咨询经验,你旨在通过专业心理咨询, 协助来访者完成心理诊断。请充分利用专业心理学知识与咨询技术, 一步步帮助来访者解决心理问题, 接下来你将只使用中文来回答和咨询问题。"
|
||||
evaluation_inputs = [
|
||||
# '躲在云朵下面就不怕淋雨了', # ruozhi train
|
||||
# '李白如果告语文书侵权的话能赔不少钱吧', # ruozhi test
|
||||
# '雨天,我走进水坑里,不小心踩碎了天空。', # ruozhi test
|
||||
'请介绍你自己', # self cognition
|
||||
'你好',
|
||||
'我今天心情不好,感觉不开心,很烦。',
|
||||
'我最近总是感到很焦虑,尤其是在学业上。我有个特别崇拜的同学,他好像在各方面都比我优秀,我总觉得自己怎么努力也追不上他,这让我压力特别大。',
|
||||
]
|
||||
|
||||
# "这是一句富有想象力和幽默感的表达。在现实生活中,躲在云朵下面并不能避免淋雨,因为云朵实际上是由水蒸气凝结形成的,而雨就是由这些水滴凝结而成的。\n\n这样的表达可能是在夸张和幽默的语境中,通过一种天马行空的方式来表达逃避现实或者寻找避难的愿望。在文学或口语表达中,常常会运用夸张和幽默来传达情感或者引起共鸣。",
|
||||
|
||||
# "如果李白(701年2月28日—762年12月)真的能就侵权诉讼获得赔偿,那确实可能是一笔不小的金额。然而,这种想法主要是一种有趣的假设,因为现实中有几个关键因素使这种情况不可能发生:\n\n1. **时间差异**:李白生活在唐朝,距今大约1200多年前。那 个时代的法律体系与现代的知识产权法律截然不同,当时没有现代意义上的版权法。\n\n2. **版权法的适用范围**:即使在现代,版权 法也有一定的时效限制。在大多数国家,版权保护通常在作者去世后一定年数内有效(如我国是作者去世后50年)。李白去世已超过1250年,因此其作品已经进入公共领域,任何人都可以自由使用而无需支付版权费用。\n\n3. **历史与现实的区别**:历史人物无法在现代 法律体系中提起诉讼,因为他们不再是活跃的法律主体。\n\n所以,虽然这是一个有趣的想法,但在现实中,李白或其他古代作者无法因其作品被现代出版物使用而获得赔偿。",
|
||||
|
||||
# "这个描述似乎是一个修辞手法,比喻性地描述了雨天的场景。在这个描述中,说“我走进水坑里,不小心踩碎了天空”,实际上并非字面意义上的发生,而是一种用词语来比喻雨天的场景。\n\n通常情况下,当雨水落在水坑或者蓄水池时,水面会泛起涟漪或者波纹,可能会反射天空的颜色或者天空的倒影。因此,这句话可能是通过“踩碎了天空”的说法来比喻雨天时踩进水坑的情景,描述雨水落在水坑中形成的波纹或者涟漪,产生了一种倒映天空的效果。\n\n这种形象化的表达方式可能是为了更生动地描述一个平常的场景,赋予它一些诗意或者意境。",
|
||||
|
||||
#######################################################################
|
||||
# PART 2 Model & Tokenizer #
|
||||
#######################################################################
|
||||
tokenizer = dict(
|
||||
type=AutoTokenizer.from_pretrained,
|
||||
pretrained_model_name_or_path=pretrained_model_name_or_path,
|
||||
trust_remote_code=True,
|
||||
padding_side='right')
|
||||
|
||||
model = dict(
|
||||
type=SupervisedFinetune,
|
||||
use_varlen_attn=use_varlen_attn,
|
||||
llm=dict(
|
||||
type=AutoModelForCausalLM.from_pretrained,
|
||||
pretrained_model_name_or_path=pretrained_model_name_or_path,
|
||||
trust_remote_code=True))
|
||||
|
||||
#######################################################################
|
||||
# PART 3 Dataset & Dataloader #
|
||||
#######################################################################
|
||||
train_dataset = dict(
|
||||
type=process_hf_dataset,
|
||||
use_varlen_attn=use_varlen_attn,
|
||||
dataset=dict(type=load_dataset, path='json', data_files=data_files),
|
||||
tokenizer=tokenizer,
|
||||
max_length=max_length,
|
||||
dataset_map_fn=None,
|
||||
template_map_fn=dict(
|
||||
type=template_map_fn_factory, template=prompt_template),
|
||||
remove_unused_columns=True,
|
||||
shuffle_before_pack=True,
|
||||
pack_to_max_length=pack_to_max_length)
|
||||
|
||||
train_dataloader = dict(
|
||||
batch_size=batch_size,
|
||||
num_workers=dataloader_num_workers,
|
||||
dataset=train_dataset,
|
||||
sampler=dict(type=InternRepoSampler, shuffle=True, seed=1024),
|
||||
batch_sampler=dict(
|
||||
type=BatchSampler, drop_last=True, batch_size=batch_size),
|
||||
collate_fn=dict(type=default_collate_fn, use_varlen_attn=use_varlen_attn))
|
||||
|
||||
#######################################################################
|
||||
# PART 4 Scheduler & Optimizer #
|
||||
#######################################################################
|
||||
# optimizer
|
||||
optim_wrapper = dict(
|
||||
type=AmpOptimWrapper,
|
||||
optimizer=dict(
|
||||
type=optim_type, lr=lr, betas=betas, weight_decay=weight_decay),
|
||||
clip_grad=dict(max_norm=max_norm, error_if_nonfinite=False),
|
||||
accumulative_counts=accumulative_counts,
|
||||
loss_scale='dynamic',
|
||||
)
|
||||
|
||||
# learning policy
|
||||
# More information: https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/param_scheduler.md # noqa: E501
|
||||
param_scheduler = [
|
||||
dict(
|
||||
type='LinearLR',
|
||||
start_factor=1 / 40,
|
||||
by_epoch=True,
|
||||
begin=0,
|
||||
end=warm_up_ratio * max_epochs,
|
||||
convert_to_iter_based=True),
|
||||
dict(
|
||||
type=CosineAnnealingLR,
|
||||
eta_min=lr * 0.15,
|
||||
by_epoch=True,
|
||||
begin=warm_up_ratio * max_epochs,
|
||||
end=max_epochs,
|
||||
convert_to_iter_based=True)
|
||||
]
|
||||
|
||||
# train, val, test setting
|
||||
train_cfg = dict(type=TrainLoop, max_epochs=max_epochs)
|
||||
|
||||
#######################################################################
|
||||
# PART 5 Runtime #
|
||||
#######################################################################
|
||||
# Log the dialogue periodically during the training process, optional
|
||||
custom_hooks = [
|
||||
dict(
|
||||
type=DatasetInfoHook, tokenizer=tokenizer,
|
||||
is_intern_repo_dataset=True),
|
||||
dict(
|
||||
type=EvaluateChatHook,
|
||||
tokenizer=tokenizer,
|
||||
every_n_iters=evaluation_freq,
|
||||
evaluation_inputs=evaluation_inputs,
|
||||
system=SYSTEM,
|
||||
prompt_template=prompt_template),
|
||||
dict(type=ThroughputHook)
|
||||
]
|
||||
|
||||
if use_varlen_attn:
|
||||
custom_hooks += [dict(type=VarlenAttnArgsToMessageHubHook)]
|
||||
|
||||
# configure default hooks
|
||||
default_hooks = dict(
|
||||
# record the time of every iteration.
|
||||
timer=dict(type=IterTimerHook),
|
||||
# print log every 100 iterations.
|
||||
logger=dict(type=LoggerHook, log_metric_by_epoch=False, interval=1),
|
||||
# enable the parameter scheduler.
|
||||
param_scheduler=dict(type=ParamSchedulerHook),
|
||||
# save checkpoint per `save_steps`.
|
||||
checkpoint=dict(
|
||||
type=CheckpointHook,
|
||||
by_epoch=False,
|
||||
interval=save_steps,
|
||||
max_keep_ckpts=save_total_limit),
|
||||
# set sampler seed in distributed evrionment.
|
||||
sampler_seed=dict(type=DistSamplerSeedHook),
|
||||
)
|
||||
|
||||
# configure environment
|
||||
env_cfg = dict(
|
||||
# whether to enable cudnn benchmark
|
||||
cudnn_benchmark=False,
|
||||
# set multi process parameters
|
||||
mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0),
|
||||
# set distributed parameters
|
||||
dist_cfg=dict(backend='nccl'),
|
||||
)
|
||||
|
||||
# set visualizer
|
||||
visualizer = None
|
||||
|
||||
# set log level
|
||||
log_level = 'INFO'
|
||||
|
||||
# load from which checkpoint
|
||||
load_from = None
|
||||
|
||||
# whether to resume training from the loaded checkpoint
|
||||
resume = False
|
||||
|
||||
# Defaults to use random seed and disable `deterministic`
|
||||
randomness = dict(seed=None, deterministic=False)
|
||||
|
||||
log_processor = dict(
|
||||
by_epoch=False,
|
||||
window_size=1,
|
||||
mean_pattern=r'.*(loss|time|data_time|grad_norm|tflops).*')
|
||||
Reference in New Issue
Block a user