Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wjd2002
Ncnn
提交
e13fbe2a
N
Ncnn
项目概览
wjd2002
/
Ncnn
10 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Ncnn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
e13fbe2a
编写于
8月 03, 2023
作者:
N
nihui
提交者:
GitHub
8月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pnnx add missing Tensor.to pattern (#4908)
上级
759d55d5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
7 deletion
+33
-7
tools/pnnx/src/pass_level2/Tensor_to.cpp
tools/pnnx/src/pass_level2/Tensor_to.cpp
+31
-6
tools/pnnx/tests/test_Tensor_to.py
tools/pnnx/tests/test_Tensor_to.py
+2
-1
未找到文件。
tools/pnnx/src/pass_level2/Tensor_to.cpp
浏览文件 @
e13fbe2a
...
...
@@ -55,12 +55,15 @@ pnnx.Output output 1 0 out
op
->
params
[
"copy"
]
=
captured_params
.
at
(
"copy"
);
if
(
captured_params
.
at
(
"memory_format"
).
i
==
0
)
op
->
params
[
"memory_format"
]
=
"torch.contiguous_format"
;
if
(
captured_params
.
at
(
"memory_format"
).
i
==
1
)
op
->
params
[
"memory_format"
]
=
"torch.preserve_format"
;
if
(
captured_params
.
at
(
"memory_format"
).
i
==
2
)
op
->
params
[
"memory_format"
]
=
"torch.channels_last"
;
if
(
captured_params
.
at
(
"memory_format"
).
type
==
2
)
{
if
(
captured_params
.
at
(
"memory_format"
).
i
==
0
)
op
->
params
[
"memory_format"
]
=
"torch.contiguous_format"
;
if
(
captured_params
.
at
(
"memory_format"
).
i
==
1
)
op
->
params
[
"memory_format"
]
=
"torch.preserve_format"
;
if
(
captured_params
.
at
(
"memory_format"
).
i
==
2
)
op
->
params
[
"memory_format"
]
=
"torch.channels_last"
;
}
}
};
...
...
@@ -83,7 +86,29 @@ pnnx.Output output 1 0 out
}
};
class
Tensor_to_2
:
public
Tensor_to
{
public:
const
char
*
match_pattern_graph
()
const
{
return
R"PNNXIR(7767517
10 9
pnnx.Input input_0 0 1 input
prim::Constant op_0 0 1 dtype value=%dtype
prim::Constant op_1 0 1 layout value=*
prim::Constant op_2 0 1 device value=*
prim::Constant op_3 0 1 pin_memory value=*
prim::Constant op_4 0 1 non_blocking value=*
prim::Constant op_5 0 1 copy value=%copy
prim::Constant op_6 0 1 memory_format value=%memory_format
aten::to op_7 8 1 input dtype layout device pin_memory non_blocking copy memory_format out
pnnx.Output output 1 0 out
)PNNXIR"
;
}
};
REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS
(
Tensor_to
,
20
)
REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS
(
Tensor_to_1
,
20
)
REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS
(
Tensor_to_2
,
20
)
}
// namespace pnnx
tools/pnnx/tests/test_Tensor_to.py
浏览文件 @
e13fbe2a
...
...
@@ -27,7 +27,8 @@ class Model(nn.Module):
x
=
x
.
to
(
device
=
'cpu'
,
dtype
=
torch
.
int
,
copy
=
True
)
x
=
x
+
1
y
=
y
-
2
return
x
,
y
z
=
x
.
to
(
y
.
device
)
return
x
,
y
,
z
def
test
():
net
=
Model
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录