Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
yuanz 9a5978aba9 | 1 year ago | |
---|---|---|
.. | ||
images | 1 year ago | |
thuglm | 1 year ago | |
MyTrainer.py | 1 year ago | |
readme.md | 1 year ago | |
train_model_all.py | 1 year ago |
模型并行
方式训练thu/chatglm6b
模型v1
simple_thu_chatglm6b的基础上,添加了单机多卡的训练代码 :lora
算法、fp16
精度、使用checkpoint
等方法,可以在文本长度为1024
、batchsize=4
的情况下,在两个T4显卡上跑的很快乐(显卡的显存最大为16G,但是实际上卡1用了8G,卡2用了11G),甚至batchsize还可以提高。thu/chatglm6b
也给了基于p-tuning
的微调代码,但是和我这个单机多卡比起来,dddd(懂得都懂),各取所需吧。为了有条理性,我把这个模型的所有代码全部都放在📁thuglm
文件夹下。
但是,你在从github上下载我这个仓库后,是看不到这几个文件的:
pytorch_model-00001-of-00008.bin
、pytorch_model-00002-of-00008.bin
、pytorch_model-00003-of-00008.bin
、pytorch_model-00004-of-00008.bin
、pytorch_model-00005-of-00008.bin
、pytorch_model-00006-of-00008.bin
、pytorch_model-00007-of-00008.bin
、pytorch_model-00008-of-00008.bin
、ice_text.model
你需要从https://huggingface.co/THUDM/chatglm-6b/tree/main 这里把上面列举的文件下载下来。
下载后,把下载的文件都放在thuglm
文件夹下面,然后和我的截图比对一下,是不是有什么出入。
到这里,模型部分就解决了。
git clone https://github.com/hikariming/alpaca_chinese_dataset.git
train_model_all.py
这个代码主要分下面几个部分
数据准备
:主要是对数据做转换。和v1
一样的模型加载和转换
:注意这里有个device_map_dict
字典,你需要手动映射cuda
序号。数据加载
:没啥好说的训练
v1
版本的代码差不多,就是在模型加载和转换
部分,和v1
不一样。modeling_chatglm.py
代码写的有问题,还是在加载模型的时候出现bug
,反正就是很奇怪,只能让你手动分配。pytorch
的模型并行
思路,还对modeling_chatglm.py
里面的模型的forward
方法,做了调整,让每个网络层的input
数据自动切换到该网络层所在的设备上。模型加载和转换
的device_map_dict
字典的值,值的顺序从低到高升序。cuda
序号只是为0
、1
,如果你设备更多,你自己添加。os.environ["CUDA_VISIBLE_DEVICES"] = "0,1,2"
部分了。loss
部分,所以,在分配的时候,最后一个卡最好不要分配太多的网络层。v1
版本一样,这个不再细聊v1
,基本上也都没问题了。No Description
CSV Jupyter Notebook Python
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》