Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2f4cbc39
提交
2f4cbc39
authored
1月 02, 2026
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
1月 02, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused Composite casting logic
上级
6bf3878d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
2 行增加
和
131 行删除
+2
-131
basic.py
pytensor/scalar/basic.py
+2
-90
test_basic.py
tests/scalar/test_basic.py
+0
-41
没有找到文件。
pytensor/scalar/basic.py
浏览文件 @
2f4cbc39
...
@@ -4300,14 +4300,8 @@ class Composite(ScalarInnerGraphOp):
...
@@ -4300,14 +4300,8 @@ class Composite(ScalarInnerGraphOp):
self
.
_fgraph
=
fgraph
self
.
_fgraph
=
fgraph
return
self
.
_fgraph
return
self
.
_fgraph
def
clone_float32
(
self
):
# This will not modify the fgraph or the nodes
new_ins
,
new_outs
=
composite_f32
.
apply
(
self
.
fgraph
)
return
Composite
(
new_ins
,
new_outs
)
def
clone
(
self
):
def
clone
(
self
):
new_ins
,
new_outs
=
composite_f32
.
apply
(
self
.
fgraph
)
return
Composite
(
self
.
fgraph
.
inputs
,
self
.
fgraph
.
outputs
)
return
Composite
(
new_ins
,
new_outs
)
def
output_types
(
self
,
input_types
):
def
output_types
(
self
,
input_types
):
if
tuple
(
input_types
)
!=
self
.
inputs_type
:
if
tuple
(
input_types
)
!=
self
.
inputs_type
:
...
@@ -4423,86 +4417,4 @@ class Composite(ScalarInnerGraphOp):
...
@@ -4423,86 +4417,4 @@ class Composite(ScalarInnerGraphOp):
return
self
.
c_code_template
%
d
return
self
.
c_code_template
%
d
def
c_code_cache_version_outer
(
self
)
->
tuple
[
int
,
...
]:
def
c_code_cache_version_outer
(
self
)
->
tuple
[
int
,
...
]:
return
(
6
,)
return
(
7
,)
class
Compositef32
:
# This is a dict of scalar op classes that need special handling
special
:
dict
=
{}
def
apply
(
self
,
fgraph
):
mapping
=
{}
topo
=
fgraph
.
toposort
()
for
i
in
fgraph
.
inputs
:
if
i
.
dtype
==
"float16"
:
mapping
[
i
]
=
get_scalar_type
(
"float32"
)()
if
hasattr
(
i
.
tag
,
"test_value"
):
mapping
[
i
]
.
tag
.
test_value
=
i
.
tag
.
test_value
else
:
mapping
[
i
]
=
i
for
node
in
topo
:
# Patch up for constants
for
i
in
node
.
inputs
:
if
i
not
in
mapping
:
assert
type
(
i
)
is
ScalarConstant
if
i
.
type
==
float16
:
ni
=
ScalarConstant
(
float32
,
i
.
data
)
else
:
ni
=
i
mapping
[
i
]
=
ni
if
isinstance
(
node
.
op
,
tuple
(
self
.
special
)):
self
.
special
[
type
(
node
.
op
)](
node
,
mapping
)
continue
new_node
=
node
.
clone_with_new_inputs
(
[
mapping
[
inp
]
for
inp
in
node
.
inputs
],
strict
=
False
)
# make sure we don't produce any float16.
assert
not
any
(
o
.
dtype
==
"float16"
for
o
in
new_node
.
outputs
)
mapping
.
update
(
zip
(
node
.
outputs
,
new_node
.
outputs
,
strict
=
True
))
new_ins
=
[
mapping
[
inp
]
for
inp
in
fgraph
.
inputs
]
new_outs
=
[
mapping
[
out
]
for
out
in
fgraph
.
outputs
]
return
new_ins
,
new_outs
composite_f32
=
Compositef32
()
def
handle_cast
(
node
,
mapping
):
inp
=
mapping
[
node
.
inputs
[
0
]]
out
=
node
.
outputs
[
0
]
node_ok
=
False
if
node
.
op
.
o_type
==
float16
:
if
node
.
inputs
[
0
]
.
type
==
float32
:
# cast f32 -> f16, remove
mapping
[
out
]
=
inp
return
else
:
# cast to f16, convert to f32
new_out
=
cast
(
inp
,
"float32"
)
# change the node for the following if
node
=
new_out
.
owner
mapping
[
out
]
=
new_out
node_ok
=
True
if
node
.
inputs
[
0
]
.
type
==
float16
:
if
node
.
op
.
o_type
==
inp
.
type
:
# cast f16 to new input type, remove
mapping
[
out
]
=
inp
return
if
not
node_ok
:
new_node
=
node
.
clone_with_new_inputs
([
inp
],
strict
=
False
)
mapping
[
out
]
=
new_node
.
outputs
[
0
]
Compositef32
.
special
[
Cast
]
=
handle_cast
def
handle_composite
(
node
,
mapping
):
new_op
=
node
.
op
.
clone_float32
()
new_outs
=
new_op
(
*
[
mapping
[
i
]
for
i
in
node
.
inputs
],
return_list
=
True
)
assert
len
(
new_outs
)
==
len
(
node
.
outputs
)
for
o
,
no
in
zip
(
node
.
outputs
,
new_outs
,
strict
=
True
):
mapping
[
o
]
=
no
Compositef32
.
special
[
Composite
]
=
handle_composite
tests/scalar/test_basic.py
浏览文件 @
2f4cbc39
...
@@ -23,7 +23,6 @@ from pytensor.scalar.basic import (
...
@@ -23,7 +23,6 @@ from pytensor.scalar.basic import (
arctan
,
arctan
,
arctan2
,
arctan2
,
arctanh
,
arctanh
,
cast
,
complex64
,
complex64
,
constant
,
constant
,
cos
,
cos
,
...
@@ -33,7 +32,6 @@ from pytensor.scalar.basic import (
...
@@ -33,7 +32,6 @@ from pytensor.scalar.basic import (
exp
,
exp
,
exp2
,
exp2
,
expm1
,
expm1
,
float16
,
float32
,
float32
,
floats
,
floats
,
int8
,
int8
,
...
@@ -53,11 +51,9 @@ from pytensor.scalar.basic import (
...
@@ -53,11 +51,9 @@ from pytensor.scalar.basic import (
sin
,
sin
,
sinh
,
sinh
,
sqrt
,
sqrt
,
switch
,
tan
,
tan
,
tanh
,
tanh
,
true_div
,
true_div
,
uint8
,
)
)
from
pytensor.tensor.type
import
fscalar
,
imatrix
,
matrix
from
pytensor.tensor.type
import
fscalar
,
imatrix
,
matrix
from
tests.link.test_link
import
make_function
from
tests.link.test_link
import
make_function
...
@@ -72,43 +68,6 @@ def test_mul_add_true():
...
@@ -72,43 +68,6 @@ def test_mul_add_true():
class
TestComposite
:
class
TestComposite
:
def
test_composite_clone_float32
(
self
):
def
has_f16
(
comp
):
if
any
(
v
.
type
==
float16
for
v
in
comp
.
fgraph
.
variables
):
return
True
return
False
w
=
int8
()
x
=
float16
()
y
=
float32
()
cz
=
Composite
([
x
,
y
],
[
tanh
(
x
+
cast
(
y
,
"float16"
))])
c
=
Composite
(
[
w
,
x
,
y
],
[
cz
(
x
,
y
)
-
cz
(
x
,
y
)
**
2
+
cast
(
x
,
"int16"
)
+
cast
(
x
,
"float32"
)
+
cast
(
w
,
"float16"
)
-
constant
(
np
.
float16
(
1.0
))
],
)
assert
has_f16
(
c
)
nc
=
c
.
clone_float32
()
assert
not
has_f16
(
nc
)
v
=
uint8
()
w
=
float16
()
x
=
float16
()
y
=
float16
()
z
=
float16
()
c
=
Composite
([
v
,
w
,
x
,
y
,
z
],
[
switch
(
v
,
mul
(
w
,
x
,
y
),
z
)])
assert
has_f16
(
c
)
nc
=
c
.
clone_float32
()
assert
not
has_f16
(
nc
)
def
test_straightforward
(
self
):
def
test_straightforward
(
self
):
x
,
y
,
_z
=
floats
(
"xyz"
)
x
,
y
,
_z
=
floats
(
"xyz"
)
e
=
mul
(
add
(
x
,
y
),
true_div
(
x
,
y
))
e
=
mul
(
add
(
x
,
y
),
true_div
(
x
,
y
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论