-
Notifications
You must be signed in to change notification settings - Fork 95
issue/890 - 为nn.module添加to函数 #891
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: main
Are you sure you want to change the base?
Conversation
78c0706 to
dfb1e8d
Compare
| if (param.shape == input_param.shape) and ( | ||
| param.dtype == input_param.dtype | ||
| ): | ||
| param.copy_(input_param) |
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.
因为,infinicore的两个tensor之间的copy操作,是支持从 cpu直接拷贝到gpu的。
现在的权重加载判断是: 模型weight和权重文件,二者shape和dtype同一样时,可以拷贝数据,否则报错。
| pass | ||
| raise KeyError("not support") | ||
|
|
||
| def _apply(self, fn, recurse=True): |
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.
to函数的部分参考了torch的写法
| raise KeyError("not support") | ||
| for key, param in self._parameters.items(): | ||
| if param is not None: | ||
| setattr(self, key, fn(param)) |
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.
使用=符号,赋值不成功,不知为何。
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.
最后用了setattr(self, key, fn(param))
目标版本
main
功能描述
python的nn.Module中添加 to函数:
实现将model权重to到gpu上的操作
model.to("cuda")
测试结果

该功能的测试脚本,测试通过
修改后infinilm中的llama模型,测试通过
