# qwen_1.8B-SFT 此模型是基于qwen_1.8B-base模型进行SFT训练的一个chat模型,由于SFT训练语料较少,约为172万条,并且max_seq_len为512,因此具有一定的局限性,目的主要是测试此模型SFT的可行性。 其中要求与依赖项与qwen官网相同,这里不做过多的详细描述。 ## 要求(Requirements) * python 3.8及以上版本 * pytorch 1.12及以上版本,推荐2.0及以上版本 * 建议使用CUDA 11.4及以上(GPU用户、flash-attention用户等需考虑此选项) * python 3.8 and above * pytorch 1.12 and above, 2.0 and above are recommended * CUDA 11.4 and above are recommended (this is for GPU users, flash-attention users, etc.) ## 依赖项(Dependency) 运行qwen_1.8B-SFT,请确保满足上述要求,再执行以下pip命令安装依赖库 ```bash pip install transformers==4.32.0 accelerate tiktoken einops scipy transformers_stream_generator==0.0.4 peft deepspeed ``` 另外,推荐安装`flash-attention`库(**当前已支持flash attention 2**),以实现更高的效率和更低的显存占用。 ```bash git clone https://github.com/Dao-AILab/flash-attention cd flash-attention && pip install . # 下方安装可选,安装可能比较缓慢。 # pip install csrc/layer_norm # pip install csrc/rotary ```
## 快速使用(Quickstart) ```python from modelscope import AutoModelForCausalLM, AutoTokenizer, GenerationConfig tokenizer = AutoTokenizer.from_pretrained("Ndlcwx/qwen_1.8B-SFT", revision='master', trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("Ndlcwx/qwen_1.8B-SFT", revision='master', device_map="auto", trust_remote_code=True).eval() response, history = model.chat(tokenizer, "你好", history=None) print(response) response, history = model.chat(tokenizer, "给我讲一个年轻人奋斗创业最终取得成功的故事。", history=history) print(response) response, history = model.chat(tokenizer, "给这个故事起一个标题", history=history) print(response) response, history = model.chat(tokenizer, "请写一段Python代码", history=history) print(response) ``` 这里仅展示部分问题的回答效果: ![](./assets/qwen_1.8_sft_chat1.png) ![](./assets/qwen_1.8_sft_chat2.png) ![](./assets/qwen_1.8_sft_chat3.png) ![](./assets/qwen_1.8_sft_chat4.png) ![](./assets/qwen_1.8_sft_chat5.png) ![](./assets/qwen_1.8_sft_chat6.png) **可以看出Qwen-1.8B-SFT的效果还是不错的,毕竟预训练模型得到了充分的训练,拥有一个足够“聪明”的大脑**