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

转换规则 torch.hub.load_state_dict_from_url #226

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

LokeZhou
Copy link
Contributor

@LokeZhou LokeZhou commented Aug 9, 2023

PR Docs

PaddlePaddle/docs#6090

PR APIs

torch.hub.load_state_dict_from_url
image

@paddle-bot
Copy link

paddle-bot bot commented Aug 9, 2023

Thanks for your contribution!

@LokeZhou
Copy link
Contributor Author

LokeZhou commented Aug 9, 2023

torch.utils.model_zoo.load_url _test_alias_case_1()在ci上的pytorch版本已去掉,运行ci会报错,因此单测加_跳过,提供本地运行截图

Copy link
Collaborator

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个API的功能上是一致的不

@LokeZhou
Copy link
Contributor Author

这两个API的功能上是一致的不

在支持转换的参数中,是一致的

"unsupport_args": [
"model_dir",
"map_location",
"progress",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些不重要的参数可以直接删除,避免影响转换效果,一般一些只关乎性能的、调试的、输入校验的,对计算结果都没有影响,可以采取这种描述方式,代码里写法是对应一个空字符串,文档记得同步更新
infoflow 2023-08-18 12-21-07
这里的progress、check_hash应该不关键

pytorch_code = textwrap.dedent(
"""
import torch
state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看了下这两个API的返回结果不同,torch返回的是一个Layer的state_dict结果,paddle返回的是一个路径,所以是不是paddle的还需要包装下,比如加一个load之类的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加load之后还是不能实现直接转换,原因是:torch 的.pth权重文件,paddle直接load .pth可能会报错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants