Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b6fb55d5
提交
b6fb55d5
authored
12月 13, 2022
作者:
Maxim Kochurov
提交者:
Maxim Kochurov
12月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove deprecated config api
上级
0013aea5
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
3 行增加
和
181 行删除
+3
-181
configdefaults.py
pytensor/configdefaults.py
+3
-29
configparser.py
pytensor/configparser.py
+0
-106
test_config.py
tests/test_config.py
+0
-46
没有找到文件。
pytensor/configdefaults.py
浏览文件 @
b6fb55d5
...
@@ -11,7 +11,6 @@ import numpy as np
...
@@ -11,7 +11,6 @@ import numpy as np
from
setuptools._distutils.spawn
import
find_executable
from
setuptools._distutils.spawn
import
find_executable
import
pytensor
import
pytensor
import
pytensor.configparser
from
pytensor.configparser
import
(
from
pytensor.configparser
import
(
BoolParam
,
BoolParam
,
ConfigParam
,
ConfigParam
,
...
@@ -20,6 +19,7 @@ from pytensor.configparser import (
...
@@ -20,6 +19,7 @@ from pytensor.configparser import (
FloatParam
,
FloatParam
,
IntParam
,
IntParam
,
StrParam
,
StrParam
,
_create_default_config
,
)
)
from
pytensor.utils
import
(
from
pytensor.utils
import
(
LOCAL_BITWIDTH
,
LOCAL_BITWIDTH
,
...
@@ -1195,27 +1195,6 @@ def add_vm_configvars():
...
@@ -1195,27 +1195,6 @@ def add_vm_configvars():
)
)
def
add_deprecated_configvars
():
# TODO: remove this?
config
.
add
(
"unittests__rseed"
,
"Seed to use for randomized unit tests. "
"Special value 'random' means using a seed of None."
,
StrParam
(
666
,
validate
=
_good_seem_param
),
in_c_key
=
False
,
)
config
.
add
(
"warn__round"
,
"Warn when using `tensor.round` with the default mode. "
"Round changed its default from `half_away_from_zero` to "
"`half_to_even` to have the same default as NumPy."
,
BoolParam
(
_warn_default
(
"0.9"
)),
in_c_key
=
False
,
)
def
add_scan_configvars
():
def
add_scan_configvars
():
config
.
add
(
config
.
add
(
"scan__allow_gc"
,
"scan__allow_gc"
,
...
@@ -1444,12 +1423,8 @@ SUPPORTED_DNN_CONV_PRECISION = (
...
@@ -1444,12 +1423,8 @@ SUPPORTED_DNN_CONV_PRECISION = (
)
)
# Eventually, the instance of `PyTensorConfigParser` should be created right here,
# Eventually, the instance of `PyTensorConfigParser` should be created right here,
# where it is also populated with settings. But for a transition period, it
# where it is also populated with settings.
# remains as `configparser._config`, while everybody accessing it through
config
=
_create_default_config
()
# `configparser.config` is flooded with deprecation warnings. These warnings
# instruct one to use `pytensor.config`, which is an alias for
# `pytensor.configdefaults.config`.
config
=
pytensor
.
configparser
.
_config
# The functions below register config variables into the config instance above.
# The functions below register config variables into the config instance above.
add_basic_configvars
()
add_basic_configvars
()
...
@@ -1467,7 +1442,6 @@ add_optimizer_configvars()
...
@@ -1467,7 +1442,6 @@ add_optimizer_configvars()
# that module, which introduces a circular dependency!
# that module, which introduces a circular dependency!
add_metaopt_configvars
()
add_metaopt_configvars
()
add_vm_configvars
()
add_vm_configvars
()
add_deprecated_configvars
()
add_numba_configvars
()
add_numba_configvars
()
# TODO: `gcc_version_str` is used by other modules.. Should it become an immutable config var?
# TODO: `gcc_version_str` is used by other modules.. Should it become an immutable config var?
...
...
pytensor/configparser.py
浏览文件 @
b6fb55d5
...
@@ -65,27 +65,6 @@ class _ChangeFlagsDecorator:
...
@@ -65,27 +65,6 @@ class _ChangeFlagsDecorator:
v
.
__set__
(
self
.
_root
,
self
.
old_vals
[
k
])
v
.
__set__
(
self
.
_root
,
self
.
old_vals
[
k
])
class
_SectionRedirect
:
"""Functions as a mock property on the PyTensorConfigParser.
It redirects attribute access (to config subsectinos) to the
new config variable properties that use "__" in their name.
"""
def
__init__
(
self
,
root
,
section_name
):
self
.
_root
=
root
self
.
_section_name
=
section_name
super
()
.
__init__
()
def
__getattr__
(
self
,
attr
):
warnings
.
warn
(
f
"Accessing section '{attr}' through old .-based API. "
f
"This will be removed. Use 'config.{self._section_name}__{attr}' instead."
,
DeprecationWarning
,
)
return
getattr
(
self
.
_root
,
f
"{self._section_name}__{attr}"
)
class
PyTensorConfigParser
:
class
PyTensorConfigParser
:
"""Object that holds configuration settings."""
"""Object that holds configuration settings."""
...
@@ -189,18 +168,6 @@ class PyTensorConfigParser:
...
@@ -189,18 +168,6 @@ class PyTensorConfigParser:
# the ConfigParam implements __get__/__set__, enabling us to create a property:
# the ConfigParam implements __get__/__set__, enabling us to create a property:
setattr
(
self
.
__class__
,
name
,
configparam
)
setattr
(
self
.
__class__
,
name
,
configparam
)
# The old API used dots for accessing a hierarchy of sections.
# The following code adds redirects that spill DeprecationWarnings
# while allowing backwards-compatible access to dot-based subsections.
# Because the subsectioning is recursive, redirects must be added for
# all levels. For example: ".test", ".test.subsection".
sections
=
name
.
split
(
"__"
)
for
s
in
range
(
1
,
len
(
sections
)):
section_name
=
"__"
.
join
(
sections
[:
s
])
if
not
hasattr
(
self
,
section_name
):
redirect
=
_SectionRedirect
(
self
,
section_name
)
setattr
(
self
.
__class__
,
section_name
,
redirect
)
def
fetch_val_for_key
(
self
,
key
,
delete_key
=
False
):
def
fetch_val_for_key
(
self
,
key
,
delete_key
=
False
):
"""Return the overriding config value for a key.
"""Return the overriding config value for a key.
A successful search returns a string value.
A successful search returns a string value.
...
@@ -565,76 +532,3 @@ def _create_default_config():
...
@@ -565,76 +532,3 @@ def _create_default_config():
pytensor_raw_cfg
=
pytensor_raw_cfg
,
pytensor_raw_cfg
=
pytensor_raw_cfg
,
)
)
return
config
return
config
class
_ConfigProxy
:
"""Like _SectionRedirect this class enables backwards-compatible access to the
config settings, but raises DeprecationWarnings with instructions to use `pytensor.config`.
"""
def
__init__
(
self
,
actual
):
_ConfigProxy
.
_actual
=
actual
def
__getattr__
(
self
,
attr
):
if
attr
==
"_actual"
:
return
_ConfigProxy
.
_actual
warnings
.
warn
(
"`pytensor.configparser.config` is deprecated; use `pytensor.config` instead."
,
DeprecationWarning
,
stacklevel
=
2
,
)
return
getattr
(
self
.
_actual
,
attr
)
def
__setattr__
(
self
,
attr
,
value
):
if
attr
==
"_actual"
:
return
setattr
(
_ConfigProxy
.
_actual
,
attr
,
value
)
warnings
.
warn
(
"`pytensor.configparser.config` is deprecated; use `pytensor.config` instead."
,
DeprecationWarning
,
stacklevel
=
2
,
)
return
setattr
(
self
.
_actual
,
attr
,
value
)
# Create the actual instance of the config. This one should eventually move to
# `configdefaults`:
_config
=
_create_default_config
()
# The old API often imported the default config object from `configparser`.
# These imports/accesses should be replaced with `pytensor.config`, so this wraps
# it with warnings:
config
=
_ConfigProxy
(
_config
)
DEPRECATED_NAMES
=
[
(
"change_flags"
,
"`change_flags` is deprecated; use `pytensor.config.change_flags` instead."
,
_config
.
change_flags
,
),
(
"_change_flags"
,
"`_change_flags` is deprecated; use `pytensor.config.change_flags` instead."
,
_config
.
change_flags
,
),
(
"_config_print"
,
"`_config_print` is deprecated; use `pytensor.config.config_print` instead."
,
_config
.
config_print
,
),
]
def
__getattr__
(
name
):
"""Intercept module-level attribute access of deprecated symbols.
Adapted from https://stackoverflow.com/a/55139609/3006474.
"""
from
warnings
import
warn
for
old_name
,
msg
,
old_object
in
DEPRECATED_NAMES
:
if
name
==
old_name
:
warn
(
msg
,
DeprecationWarning
,
stacklevel
=
2
)
return
old_object
raise
AttributeError
(
f
"module {__name__} has no attribute {name}"
)
tests/test_config.py
浏览文件 @
b6fb55d5
...
@@ -18,52 +18,6 @@ def _create_test_config():
...
@@ -18,52 +18,6 @@ def _create_test_config():
)
)
def
test_api_deprecation_warning
():
# accessing through configdefaults.config is the new best practice
with
pytest
.
warns
(
None
):
root
=
configdefaults
.
config
assert
isinstance
(
str
(
root
),
str
)
# accessing through configparser.config is discouraged
root
=
configparser
.
config
with
pytest
.
warns
(
DeprecationWarning
,
match
=
"instead"
):
root
.
add
(
"test_deprecationwarning"
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default"
),
)
with
pytest
.
warns
(
DeprecationWarning
,
match
=
"instead"
):
with
root
.
change_flags
(
test_deprecationwarning
=
"new_value"
):
pass
def
test_api_redirect
():
root
=
_create_test_config
()
# one section level
root
.
add
(
"test__section_redirect"
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default"
),
)
assert
hasattr
(
root
,
"test__section_redirect"
)
assert
root
.
test__section_redirect
==
"test_default"
assert
hasattr
(
root
,
"test"
)
assert
isinstance
(
root
.
test
,
configparser
.
_SectionRedirect
)
with
pytest
.
warns
(
DeprecationWarning
):
assert
root
.
test
.
section_redirect
==
"test_default"
# two section levels
root
.
add
(
"test__subsection__redirect"
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default2"
),
)
assert
hasattr
(
root
,
"test__subsection__redirect"
)
assert
root
.
test__subsection__redirect
==
"test_default2"
with
pytest
.
warns
(
DeprecationWarning
):
assert
root
.
test
.
subsection
.
redirect
==
"test_default2"
def
test_invalid_default
():
def
test_invalid_default
():
# Ensure an invalid default value found in the PyTensor code only causes
# Ensure an invalid default value found in the PyTensor code only causes
# a crash if it is not overridden by the user.
# a crash if it is not overridden by the user.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论