Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3ed2c497
Unverified
提交
3ed2c497
authored
5月 13, 2024
作者:
Adrian Seyboldt
提交者:
GitHub
5月 13, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable no-cpython-wrapper in numba where possible (#765)
* Enable no-cpython-wrapper in numba where possible * Fix test with no_cpython_wrapper * Add docstring to numba_funcify
上级
15b90be8
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
28 行增加
和
5 行删除
+28
-5
basic.py
pytensor/link/numba/dispatch/basic.py
+8
-1
elemwise.py
pytensor/link/numba/dispatch/elemwise.py
+11
-2
linker.py
pytensor/link/numba/linker.py
+1
-1
test_tensor_basic.py
tests/link/numba/test_tensor_basic.py
+8
-1
没有找到文件。
pytensor/link/numba/dispatch/basic.py
浏览文件 @
3ed2c497
...
...
@@ -59,6 +59,8 @@ def global_numba_func(func):
def
numba_njit
(
*
args
,
**
kwargs
):
kwargs
.
setdefault
(
"cache"
,
config
.
numba__cache
)
kwargs
.
setdefault
(
"no_cpython_wrapper"
,
True
)
kwargs
.
setdefault
(
"no_cfunc_wrapper"
,
True
)
# Supress caching warnings
warnings
.
filterwarnings
(
...
...
@@ -419,7 +421,12 @@ def generate_fallback_impl(op, node=None, storage_map=None, **kwargs):
@singledispatch
def
numba_funcify
(
op
,
node
=
None
,
storage_map
=
None
,
**
kwargs
):
"""Generate a numba function for a given op and apply node."""
"""Generate a numba function for a given op and apply node.
The resulting function will usually use the `no_cpython_wrapper`
argument in numba, so it can not be called directly from python,
but only from other jit functions.
"""
return
generate_fallback_impl
(
op
,
node
,
storage_map
,
**
kwargs
)
...
...
pytensor/link/numba/dispatch/elemwise.py
浏览文件 @
3ed2c497
...
...
@@ -470,7 +470,9 @@ _jit_options = {
"afn"
,
# Approximate functions
"reassoc"
,
"nsz"
,
# TODO Do we want this one?
}
},
"no_cpython_wrapper"
:
True
,
"no_cfunc_wrapper"
:
True
,
}
...
...
@@ -698,7 +700,14 @@ def numba_funcify_Elemwise(op, node, **kwargs):
return
tuple
(
outputs_summed
)
return
outputs_summed
[
0
]
@overload
(
elemwise
)
@overload
(
elemwise
,
jit_options
=
{
"fastmath"
:
flags
,
"no_cpython_wrapper"
:
True
,
"no_cfunc_wrapper"
:
True
,
},
)
def
ov_elemwise
(
*
inputs
):
return
elemwise_wrapper
...
...
pytensor/link/numba/linker.py
浏览文件 @
3ed2c497
...
...
@@ -29,7 +29,7 @@ class NumbaLinker(JITLinker):
def
jit_compile
(
self
,
fn
):
from
pytensor.link.numba.dispatch.basic
import
numba_njit
jitted_fn
=
numba_njit
(
fn
)
jitted_fn
=
numba_njit
(
fn
,
no_cpython_wrapper
=
False
,
no_cfunc_wrapper
=
False
)
return
jitted_fn
def
create_thunk_inputs
(
self
,
storage_map
):
...
...
tests/link/numba/test_tensor_basic.py
浏览文件 @
3ed2c497
...
...
@@ -386,6 +386,8 @@ def test_ExtractDiag(val, offset):
)
@pytest.mark.parametrize
(
"reverse_axis"
,
(
False
,
True
))
def
test_ExtractDiag_exhaustive
(
k
,
axis1
,
axis2
,
reverse_axis
):
from
pytensor.link.numba.dispatch.basic
import
numba_njit
if
reverse_axis
:
axis1
,
axis2
=
axis2
,
axis1
...
...
@@ -394,7 +396,12 @@ def test_ExtractDiag_exhaustive(k, axis1, axis2, reverse_axis):
x_test
=
np
.
arange
(
np
.
prod
(
x_shape
))
.
reshape
(
x_shape
)
out
=
pt
.
diagonal
(
x
,
k
,
axis1
,
axis2
)
numba_fn
=
numba_funcify
(
out
.
owner
.
op
,
out
.
owner
)
np
.
testing
.
assert_allclose
(
numba_fn
(
x_test
),
np
.
diagonal
(
x_test
,
k
,
axis1
,
axis2
))
@numba_njit
(
no_cpython_wrapper
=
False
)
def
wrap
(
x
):
return
numba_fn
(
x
)
np
.
testing
.
assert_allclose
(
wrap
(
x_test
),
np
.
diagonal
(
x_test
,
k
,
axis1
,
axis2
))
@pytest.mark.parametrize
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论