Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4efbd193
提交
4efbd193
authored
9月 12, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
9月 12, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor SoftmaxGrad numba patch
上级
da66c2ef
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
14 行增加
和
8 行删除
+14
-8
elemwise.py
pytensor/link/numba/dispatch/elemwise.py
+14
-8
没有找到文件。
pytensor/link/numba/dispatch/elemwise.py
浏览文件 @
4efbd193
...
@@ -402,7 +402,9 @@ def {careduce_fn_name}({input_name}):
...
@@ -402,7 +402,9 @@ def {careduce_fn_name}({input_name}):
return
careduce_fn
return
careduce_fn
def
jit_compile_reducer
(
node
,
fn
,
*
,
reduce_to_scalar
=
False
,
**
kwds
):
def
jit_compile_reducer
(
node
,
fn
,
*
,
reduce_to_scalar
=
False
,
infer_signature
=
True
,
**
kwds
):
"""Compile Python source for reduction loops using additional optimizations.
"""Compile Python source for reduction loops using additional optimizations.
Parameters
Parameters
...
@@ -411,6 +413,10 @@ def jit_compile_reducer(node, fn, *, reduce_to_scalar=False, **kwds):
...
@@ -411,6 +413,10 @@ def jit_compile_reducer(node, fn, *, reduce_to_scalar=False, **kwds):
An node from which the signature can be derived.
An node from which the signature can be derived.
fn
fn
The Python function object to compile.
The Python function object to compile.
reduce_to_scalar: bool, default False
Whether to reduce output to a scalar (instead of 0d array)
infer_signature: bool: default True
Whether to try and infer the function signature from the Apply node.
kwds
kwds
Extra keywords to be added to the :func:`numba.njit` function.
Extra keywords to be added to the :func:`numba.njit` function.
...
@@ -419,13 +425,17 @@ def jit_compile_reducer(node, fn, *, reduce_to_scalar=False, **kwds):
...
@@ -419,13 +425,17 @@ def jit_compile_reducer(node, fn, *, reduce_to_scalar=False, **kwds):
A :func:`numba.njit`-compiled function.
A :func:`numba.njit`-compiled function.
"""
"""
signature
=
create_numba_signature
(
node
,
reduce_to_scalar
=
reduce_to_scalar
)
if
infer_signature
:
signature
=
create_numba_signature
(
node
,
reduce_to_scalar
=
reduce_to_scalar
)
args
=
(
signature
,)
else
:
args
=
()
# Eagerly compile the function using increased optimizations. This should
# Eagerly compile the function using increased optimizations. This should
# help improve nested loop reductions.
# help improve nested loop reductions.
with
use_optimized_cheap_pass
():
with
use_optimized_cheap_pass
():
res
=
numba_basic
.
numba_njit
(
res
=
numba_basic
.
numba_njit
(
signature
,
*
args
,
boundscheck
=
False
,
boundscheck
=
False
,
fastmath
=
config
.
numba__fastmath
,
fastmath
=
config
.
numba__fastmath
,
**
kwds
,
**
kwds
,
...
@@ -926,11 +936,7 @@ def numba_funcify_SoftmaxGrad(op, node, **kwargs):
...
@@ -926,11 +936,7 @@ def numba_funcify_SoftmaxGrad(op, node, **kwargs):
return
dx
return
dx
# The signature inferred by jit_compile_reducer is wrong when dy is a constant (readonly=True)
# The signature inferred by jit_compile_reducer is wrong when dy is a constant (readonly=True)
# softmax_grad = jit_compile_reducer(node, softmax_grad_py_fn)
softmax_grad
=
jit_compile_reducer
(
node
,
softmax_grad_py_fn
,
infer_signature
=
False
)
softmax_grad
=
numba_njit
(
boundscheck
=
False
,
fastmath
=
config
.
numba__fastmath
,
)(
softmax_grad_py_fn
)
return
softmax_grad
return
softmax_grad
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论