Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
be358ed2
提交
be358ed2
authored
10月 09, 2024
作者:
ricardoV94
提交者:
Thomas Wiecki
10月 10, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement Cast in PyTorch backend
上级
be6a0322
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
0 行删除
+24
-0
scalar.py
pytensor/link/pytorch/dispatch/scalar.py
+11
-0
test_elemwise.py
tests/link/pytorch/test_elemwise.py
+13
-0
没有找到文件。
pytensor/link/pytorch/dispatch/scalar.py
浏览文件 @
be358ed2
...
@@ -2,6 +2,7 @@ import torch
...
@@ -2,6 +2,7 @@ import torch
from
pytensor.link.pytorch.dispatch.basic
import
pytorch_funcify
from
pytensor.link.pytorch.dispatch.basic
import
pytorch_funcify
from
pytensor.scalar.basic
import
(
from
pytensor.scalar.basic
import
(
Cast
,
ScalarOp
,
ScalarOp
,
)
)
...
@@ -38,3 +39,13 @@ def pytorch_funcify_ScalarOp(op, node, **kwargs):
...
@@ -38,3 +39,13 @@ def pytorch_funcify_ScalarOp(op, node, **kwargs):
)
)
return
pytorch_func
return
pytorch_func
@pytorch_funcify.register
(
Cast
)
def
pytorch_funcify_Cast
(
op
:
Cast
,
node
,
**
kwargs
):
dtype
=
getattr
(
torch
,
op
.
o_type
.
dtype
)
def
cast
(
x
):
return
x
.
to
(
dtype
=
dtype
)
return
cast
tests/link/pytorch/test_elemwise.py
浏览文件 @
be358ed2
...
@@ -10,6 +10,9 @@ from pytensor.tensor.type import matrix, tensor, tensor3, vector
...
@@ -10,6 +10,9 @@ from pytensor.tensor.type import matrix, tensor, tensor3, vector
from
tests.link.pytorch.test_basic
import
compare_pytorch_and_py
from
tests.link.pytorch.test_basic
import
compare_pytorch_and_py
torch
=
pytest
.
importorskip
(
"torch"
)
def
test_pytorch_Dimshuffle
():
def
test_pytorch_Dimshuffle
():
a_pt
=
matrix
(
"a"
)
a_pt
=
matrix
(
"a"
)
...
@@ -137,3 +140,13 @@ def test_softmax_grad(axis):
...
@@ -137,3 +140,13 @@ def test_softmax_grad(axis):
out
=
SoftmaxGrad
(
axis
=
axis
)(
dy
,
sm
)
out
=
SoftmaxGrad
(
axis
=
axis
)(
dy
,
sm
)
fgraph
=
FunctionGraph
([
dy
,
sm
],
[
out
])
fgraph
=
FunctionGraph
([
dy
,
sm
],
[
out
])
compare_pytorch_and_py
(
fgraph
,
[
dy_value
,
sm_value
])
compare_pytorch_and_py
(
fgraph
,
[
dy_value
,
sm_value
])
def
test_cast
():
x
=
matrix
(
"x"
,
dtype
=
"float32"
)
out
=
pt
.
cast
(
x
,
"int32"
)
fgraph
=
FunctionGraph
([
x
],
[
out
])
_
,
[
res
]
=
compare_pytorch_and_py
(
fgraph
,
[
np
.
arange
(
6
,
dtype
=
"float32"
)
.
reshape
(
2
,
3
)]
)
assert
res
.
dtype
==
torch
.
int32
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论