Skip to content
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

mindnlp官方文档(https://mindnlp.cqu.ai/)示例代码错误反馈 #1794

Open
Helloyouth2022 opened this issue Oct 31, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@Helloyouth2022
Copy link
Contributor

##错误1
https://mindnlp.cqu.ai/tutorials/quick_start/#load-the-model
image

改正:from mindnlp.core.optim import AdamW

##错误2
https://mindnlp.cqu.ai/tutorials/quick_start/#prepare-a-dataset
image

https://mindnlp.cqu.ai/tutorials/data_preprocess/
image

改正:from mindnlp.dataset import load_dataset

##错误3
https://mindnlp.cqu.ai/tutorials/peft/#train-the-model
image

改正:import mindnlp.core.optim as optim
@Helloyouth2022 Helloyouth2022 added the bug Something isn't working label Oct 31, 2024
@lvyufeng
Copy link
Collaborator

lvyufeng commented Nov 1, 2024

ok

@LmYjQ
Copy link

LmYjQ commented Nov 13, 2024

@Helloyouth2022 错误1的下面我还遇到报错了。下面这一行会报错optimizer没有parameters属性

grad_fn = value_and_grad(forward_fn, None, optimizer.parameters)

@Helloyouth2022
Copy link
Contributor Author

@Helloyouth2022 错误1的下面我还遇到报错了。下面这一行会报错optimizer没有parameters属性

grad_fn = value_and_grad(forward_fn, None, optimizer.parameters)

下面也是需要更新的,mindnlp的optimizer不同于mindspore,应该通过model直接传进去:grad_fn = value_and_grad(forward_fn, None, model.trainable_params())
建议先学习一下mindnlp的优化器的基本用法,和pytorch类似的,可以看看github源码或者更直接的:通过help(optimizer)打印帮助文档,optimizer是你创建的优化器对象

@Helloyouth2022
Copy link
Contributor Author

https://mindnlp.cqu.ai/tutorials/peft/#training-step
image

optimizer(grads)相应地改为:optimizer.step(grads)

@LmYjQ
Copy link

LmYjQ commented Nov 18, 2024

@Helloyouth2022 请问mindnlp在训练过程中是否需要手动执行zero grad?我在910B上用sgd训练longformer,训练过程中HBM会不断增加直到OOM

@Helloyouth2022
Copy link
Contributor Author

@Helloyouth2022 请问mindnlp在训练过程中是否需要手动执行zero grad?我在910B上用sgd训练longformer,训练过程中HBM会不断增加直到OOM

目前了解到的是:mindspore的训练过程无需显示调用zero grad操作;
mindnlp 训练过程的封装整体上还是和mindspore一样的(mindnlp本来就是基于mindspore的),只是因为优化器的做了自己的接口,可能在调用时调用方式变了一点。

其实如果了解mindspore和pytorch在“获取模型梯度并使用梯度更新”操作上的差异,也很容易理解为什么在mindspore 上不用 梯度清零这个操作;
提示:pytorch中更新模型参数是通过损失函数值(是一个Tensor)执行backward操作,而mindspore中不是:
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants