-
Notifications
You must be signed in to change notification settings - Fork 35
【开源实习】基于MindSpore NLP实现language modeling应用案例开发 #26
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
base: dev
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR introduces a comprehensive Jupyter notebook tutorial demonstrating language model fine-tuning using MindSpore 2.7.0 and MindNLP 0.5.1. The tutorial adapts HuggingFace's language modeling example to the MindSpore ecosystem, showcasing GPT-2 fine-tuning on the Wikitext-2 dataset.
Key changes:
- Complete implementation of GPT-2 Causal Language Model fine-tuning workflow
- Custom training loop using MindSpore's native APIs with MindNLP Trainer integration
- Text generation capabilities demonstrating the fine-tuned model's performance
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
已经在Ascend硬件中finetune过了,已经更新pr了 |
|
使用mindspore2.7.0和mindnlp0.5.1可以运行,但是需要修改diffusers版本,pip install diffusers==0.35.2 |
是的,diffuser的版本在mindnlp有一个issue有提到过这个问题。 |
您好,已经修改格式了,请您检查一下 |
|
notebook的中间运行结果产物也需要删除,原因如下: 考虑到不同人运行 Notebook 会产生不同的execution_count、输出结果,提交后容易导致 Git 冲突;且Notebook 的输出(如图片、大段文本)会让文件体积变大,建议提交notebook前,通过nbstripout剔除运行时产生的动态数据,仅保留代码、Markdown 文本结构,让文件更干净 具体操作: 也可以去此链接中查看全部的操作过程:https://github.com/mindspore-lab/applications/wiki/Contributing-Guidelines |
|
244fa04 to
d95f76e
Compare
已经删除输出结果了 |
已经将markdown中不影响导入安装的部分改成MindSpore NLP了,以及文件位置以及移动到llm/distilgpt2/finetune_distilgpt2_language_modeling.ipynb下了 |
|
不过还是要重点夸夸,能用AI辅助代码检查,同时还能rebase head保证只有一次commit,优秀! |
|
README辛苦同步更新下案例信息,其他的没有了,辛苦辛苦 |
|
@moyu026 登金辛苦也同步验收下动态图下运行是否没问题 |
|
动态图可以运行 |
|
目前我这边看没什么问题了,辛苦 @wang-hua-2019 把把关 |
基于 MindSpore MindNLP 的语言模型微调实战(DistilGPT-2 Causal LM)
本 Notebook 演示如何在 MindSpore 2.7.0 和 MindNLP (Mindhf) 0.5.1 环境下,参考 HuggingFace 官方
language_modeling流程,对 DistilGPT-2 模型进行微调,并完成文本生成推理。与官方示例不同的是,本项目针对 MindSpore 静态图/动态图特性,对
Trainer进行了轻量级适配,使其既能享受 HF 风格的 API 便利性,又能稳定运行于 Ascend/GPU 环境。主要内容
load_dataset接口从 HuggingFace Datasets 镜像源加载 Wikitext-2-raw-v1 数据集。AutoTokenizer和AutoModelForCausalLM加载轻量级的 DistilGPT-2 预训练模型。pad_token设为eos_token)。input_ids与labels同步偏移)。MSMapDataset类,将 MindSpore 的流式 Dataset 封装为 Map-style 格式,并配合passthrough_collator,解决 Trainer 内部 DataLoader 的兼容性问题。NoJitTrainer。training_step,移除默认的 JIT 编译依赖,采用显式.backward()方式更新梯度。这解决了value_and_grad在部分复杂控制流下的兼容性报错,同时保留了TrainingArguments的便捷配置(如logging_steps、gradient_accumulation等)。model.generate接口进行 Temperature 采样与 Top-P 解码,实现高质量的文本自动续写。