Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3adaa82f
提交
3adaa82f
authored
2月 16, 2016
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4042 from adbrebs/warn_flags
[WIP] Move flags declarations and warn user if unknown flags
上级
666b86b3
9b0c950a
隐藏空白字符变更
内嵌
并排
正在显示
29 个修改的文件
包含
621 行增加
和
638 行删除
+621
-638
__init__.py
theano/__init__.py
+2
-2
debugmode.py
theano/compile/debugmode.py
+1
-35
mode.py
theano/compile/mode.py
+1
-17
nanguardmode.py
theano/compile/nanguardmode.py
+1
-22
profilemode.py
theano/compile/profilemode.py
+1
-23
profiling.py
theano/compile/profiling.py
+0
-45
test_pfunc.py
theano/compile/tests/test_pfunc.py
+1
-1
test_shared.py
theano/compile/tests/test_shared.py
+1
-1
configdefaults.py
theano/configdefaults.py
+581
-4
configparser.py
theano/configparser.py
+8
-5
__init__.py
theano/gof/__init__.py
+0
-4
cc.py
theano/gof/cc.py
+0
-9
cmodule.py
theano/gof/cmodule.py
+1
-33
compiledir.py
theano/gof/compiledir.py
+1
-258
compilelock.py
theano/gof/compilelock.py
+0
-20
opt.py
theano/gof/opt.py
+0
-7
optdb.py
theano/gof/optdb.py
+0
-13
test_compiledir.py
theano/gof/tests/test_compiledir.py
+1
-1
vm.py
theano/gof/vm.py
+1
-35
__init__.py
theano/sandbox/cuda/__init__.py
+0
-30
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+1
-1
nvcc_compiler.py
theano/sandbox/cuda/nvcc_compiler.py
+1
-1
scan_op.py
theano/scan_module/scan_op.py
+0
-9
extra_ops.py
theano/tensor/extra_ops.py
+3
-3
sigm.py
theano/tensor/nnet/sigm.py
+0
-9
opt.py
theano/tensor/opt.py
+0
-33
test_basic.py
theano/tensor/tests/test_basic.py
+1
-1
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+3
-3
test_config.py
theano/tests/test_config.py
+11
-13
没有找到文件。
theano/__init__.py
浏览文件 @
3adaa82f
...
...
@@ -36,11 +36,11 @@ logging_default_handler.setFormatter(logging_default_formatter)
theano_logger
.
addHandler
(
logging_default_handler
)
theano_logger
.
setLevel
(
logging
.
WARNING
)
from
theano.configdefaults
import
config
# Version information.
from
theano.version
import
version
as
__version__
from
theano.configdefaults
import
config
# This is the api version for ops that generate C code. External ops
# might need manual changes if this number goes up. An undefined
# __api_version__ can be understood to mean api version 0.
...
...
theano/compile/debugmode.py
浏览文件 @
3adaa82f
...
...
@@ -23,8 +23,7 @@ from six import string_types, iteritems, itervalues
from
six.moves
import
StringIO
,
xrange
from
theano.gof
import
(
graph
,
utils
,
link
,
ops_with_inner_function
)
from
theano.gof.link
import
raise_with_op
from
theano.configparser
import
(
config
,
AddConfigVar
,
BoolParam
,
IntParam
,
StrParam
)
from
theano.configparser
import
(
config
,
AddConfigVar
,
IntParam
,
StrParam
)
from
theano.compile.function_module
import
(
FunctionMaker
,
Function
,
infer_reuse_pattern
,
SymbolicInputKit
,
SymbolicOutput
,
Supervisor
,
std_fgraph
)
...
...
@@ -33,39 +32,6 @@ from theano.compile.ops import OutputGuard
__docformat__
=
"restructuredtext en"
AddConfigVar
(
'DebugMode.patience'
,
"Optimize graph this many times to detect inconsistency"
,
IntParam
(
10
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.check_c'
,
"Run C implementations where possible"
,
BoolParam
(
bool
(
theano
.
config
.
cxx
)),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.check_py'
,
"Run Python implementations where possible"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.check_finite'
,
"True -> complain about NaN/Inf results"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.check_strides'
,
(
"Check that Python- and C-produced ndarrays have same strides. "
"On difference: (0) - ignore, (1) warn, or (2) raise error"
),
IntParam
(
0
,
lambda
i
:
i
in
(
0
,
1
,
2
)),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.warn_input_not_reused'
,
(
"Generate a warning when destroy_map or view_map says that an "
"op works inplace, but the op did not reuse the input for its "
"output."
),
BoolParam
(
True
),
in_c_key
=
False
)
def
is_valid_check_preallocated_output_param
(
param
):
if
not
isinstance
(
param
,
string_types
):
...
...
theano/compile/mode.py
浏览文件 @
3adaa82f
...
...
@@ -10,29 +10,13 @@ import numpy
import
theano
from
theano
import
gof
import
theano.gof.vm
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
from
theano.configparser
import
config
from
theano.compile.ops
import
_output_guard
from
six
import
string_types
_logger
=
logging
.
getLogger
(
'theano.compile.mode'
)
AddConfigVar
(
'optimizer_excluding'
,
(
"When using the default mode, we will remove optimizer with "
"these tags. Separate tags with ':'."
),
StrParam
(
""
,
allow_override
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'optimizer_including'
,
(
"When using the default mode, we will add optimizer with "
"these tags. Separate tags with ':'."
),
StrParam
(
""
,
allow_override
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'optimizer_requiring'
,
(
"When using the default mode, we will require optimizer with "
"these tags. Separate tags with ':'."
),
StrParam
(
""
,
allow_override
=
False
),
in_c_key
=
False
)
def
check_equal
(
x
,
y
):
"""
...
...
theano/compile/nanguardmode.py
浏览文件 @
3adaa82f
...
...
@@ -6,32 +6,11 @@ from six.moves import StringIO
import
numpy
as
np
import
theano
from
theano.configparser
import
config
,
AddConfigVar
,
BoolParam
,
EnumStr
from
theano.configparser
import
config
import
theano.tensor
as
T
import
theano.sandbox.cuda
as
cuda
from
theano.compile
import
Mode
AddConfigVar
(
'NanGuardMode.nan_is_error'
,
"Default value for nan_is_error"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'NanGuardMode.inf_is_error'
,
"Default value for inf_is_error"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'NanGuardMode.big_is_error'
,
"Default value for big_is_error"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'NanGuardMode.action'
,
"What NanGuardMode does when it finds a problem"
,
EnumStr
(
'raise'
,
'warn'
,
'pdb'
),
in_c_key
=
False
)
logger
=
logging
.
getLogger
(
"theano.compile.nanguardmode"
)
...
...
theano/compile/profilemode.py
浏览文件 @
3adaa82f
...
...
@@ -11,7 +11,7 @@ from six import string_types, iteritems, itervalues
from
theano.compile.mode
import
(
Mode
,
register_mode
,
predefined_modes
,
predefined_linkers
,
predefined_optimizers
)
from
theano.configparser
import
config
,
AddConfigVar
,
IntParam
,
BoolParam
from
theano.configparser
import
config
from
theano.compile.function_module
import
FunctionMaker
from
.profiling
import
ProfileStats
...
...
@@ -20,28 +20,6 @@ run_cthunk = None # Will be imported only when needed.
import_time
=
time
.
time
()
AddConfigVar
(
'ProfileMode.n_apply_to_print'
,
"Number of apply instances to print by default"
,
IntParam
(
15
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'ProfileMode.n_ops_to_print'
,
"Number of ops to print by default"
,
IntParam
(
20
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'ProfileMode.min_memory_size'
,
"For the memory profile, do not print apply nodes if the size "
"of their outputs (in bytes) is lower then this threshold"
,
IntParam
(
1024
,
lambda
i
:
i
>=
0
),
in_c_key
=
False
)
AddConfigVar
(
'ProfileMode.profile_memory'
,
"""Enable profiling of memory used by Theano functions"""
,
BoolParam
(
False
),
in_c_key
=
False
)
class
Profile_Maker
(
FunctionMaker
):
def
create
(
self
,
input_storage
=
None
,
trustme
=
False
,
storage_map
=
None
):
ret
=
super
(
Profile_Maker
,
self
)
.
create
(
input_storage
,
trustme
,
...
...
theano/compile/profiling.py
浏览文件 @
3adaa82f
...
...
@@ -37,51 +37,6 @@ config = theano.config
_atexit_print_list
=
[]
_atexit_registered
=
False
AddConfigVar
(
'profiling.time_thunks'
,
"""Time individual thunks when profiling"""
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.n_apply'
,
"Number of Apply instances to print by default"
,
IntParam
(
20
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.n_ops'
,
"Number of Ops to print by default"
,
IntParam
(
20
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.output_line_width'
,
"Max line width for the profiling output"
,
IntParam
(
512
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.min_memory_size'
,
"""For the memory profile, do not print Apply nodes if the size
of their outputs (in bytes) is lower than this threshold"""
,
IntParam
(
1024
,
lambda
i
:
i
>=
0
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.min_peak_memory'
,
"""The min peak memory usage of the order"""
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.destination'
,
"""
File destination of the profiling output
"""
,
StrParam
(
'stderr'
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.debugprint'
,
"""
Do a debugprint of the profiled functions
"""
,
BoolParam
(
False
),
in_c_key
=
False
)
def
_atexit_print_fn
():
"""
...
...
theano/compile/tests/test_pfunc.py
浏览文件 @
3adaa82f
...
...
@@ -549,7 +549,7 @@ class Test_pfunc(unittest.TestCase):
def
test_default_updates_input
(
self
):
x
=
shared
(
0
)
y
=
shared
(
1
)
if
theano
.
gof
.
python_int_bitwidth
()
==
32
:
if
theano
.
configdefaults
.
python_int_bitwidth
()
==
32
:
a
=
iscalar
(
'a'
)
else
:
a
=
lscalar
(
'a'
)
...
...
theano/compile/tests/test_shared.py
浏览文件 @
3adaa82f
...
...
@@ -18,7 +18,7 @@ class Test_SharedVariable(unittest.TestCase):
assert
shared
(
7
,
dtype
=
'float64'
)
.
type
==
Scalar
(
'float64'
)
else
:
if
theano
.
gof
.
python_int_bitwidth
()
==
32
:
if
theano
.
configdefaults
.
python_int_bitwidth
()
==
32
:
assert
shared
(
7
)
.
type
==
theano
.
tensor
.
iscalar
,
shared
(
7
)
.
type
else
:
assert
shared
(
7
)
.
type
==
theano
.
tensor
.
lscalar
,
shared
(
7
)
.
type
...
...
theano/configdefaults.py
浏览文件 @
3adaa82f
import
errno
import
os
import
sys
import
logging
import
numpy
import
platform
import
textwrap
import
re
import
socket
import
struct
import
warnings
import
theano
from
theano.configparser
import
(
AddConfigVar
,
BoolParam
,
ConfigParam
,
EnumStr
,
FloatParam
,
IntParam
,
StrParam
,
TheanoConfigParser
)
TheanoConfigParser
,
THEANO_FLAGS_DICT
)
from
theano.misc.cpucount
import
cpuCount
from
theano.misc.windows
import
call_subprocess_Popen
from
theano.misc.windows
import
call_subprocess_Popen
,
output_subprocess_Popen
_logger
=
logging
.
getLogger
(
'theano.configdefaults'
)
...
...
@@ -316,9 +325,9 @@ AddConfigVar('dnn.conv.precision',
def
default_dnn_path
(
suffix
):
def
f
(
suffix
=
suffix
):
if
config
.
cuda
.
root
==
''
:
if
theano
.
config
.
cuda
.
root
==
''
:
return
''
return
os
.
path
.
join
(
config
.
cuda
.
root
,
suffix
)
return
os
.
path
.
join
(
theano
.
config
.
cuda
.
root
,
suffix
)
return
f
AddConfigVar
(
'dnn.include_path'
,
...
...
@@ -860,3 +869,571 @@ AddConfigVar('unittests.rseed',
"Special value 'random' means using a seed of None."
,
StrParam
(
666
,
is_valid
=
good_seed_param
),
in_c_key
=
False
)
AddConfigVar
(
'NanGuardMode.nan_is_error'
,
"Default value for nan_is_error"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'NanGuardMode.inf_is_error'
,
"Default value for inf_is_error"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'NanGuardMode.big_is_error'
,
"Default value for big_is_error"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'NanGuardMode.action'
,
"What NanGuardMode does when it finds a problem"
,
EnumStr
(
'raise'
,
'warn'
,
'pdb'
),
in_c_key
=
False
)
AddConfigVar
(
'ProfileMode.n_apply_to_print'
,
"Number of apply instances to print by default"
,
IntParam
(
15
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'ProfileMode.n_ops_to_print'
,
"Number of ops to print by default"
,
IntParam
(
20
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'ProfileMode.min_memory_size'
,
"For the memory profile, do not print apply nodes if the size "
"of their outputs (in bytes) is lower then this threshold"
,
IntParam
(
1024
,
lambda
i
:
i
>=
0
),
in_c_key
=
False
)
AddConfigVar
(
'ProfileMode.profile_memory'
,
"""Enable profiling of memory used by Theano functions"""
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'optimizer_excluding'
,
(
"When using the default mode, we will remove optimizer with "
"these tags. Separate tags with ':'."
),
StrParam
(
""
,
allow_override
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'optimizer_including'
,
(
"When using the default mode, we will add optimizer with "
"these tags. Separate tags with ':'."
),
StrParam
(
""
,
allow_override
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'optimizer_requiring'
,
(
"When using the default mode, we will require optimizer with "
"these tags. Separate tags with ':'."
),
StrParam
(
""
,
allow_override
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.patience'
,
"Optimize graph this many times to detect inconsistency"
,
IntParam
(
10
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.check_c'
,
"Run C implementations where possible"
,
BoolParam
(
lambda
:
bool
(
theano
.
config
.
cxx
)),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.check_py'
,
"Run Python implementations where possible"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.check_finite'
,
"True -> complain about NaN/Inf results"
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.check_strides'
,
(
"Check that Python- and C-produced ndarrays have same strides. "
"On difference: (0) - ignore, (1) warn, or (2) raise error"
),
IntParam
(
0
,
lambda
i
:
i
in
(
0
,
1
,
2
)),
in_c_key
=
False
)
AddConfigVar
(
'DebugMode.warn_input_not_reused'
,
(
"Generate a warning when destroy_map or view_map says that an "
"op works inplace, but the op did not reuse the input for its "
"output."
),
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.time_thunks'
,
"""Time individual thunks when profiling"""
,
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.n_apply'
,
"Number of Apply instances to print by default"
,
IntParam
(
20
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.n_ops'
,
"Number of Ops to print by default"
,
IntParam
(
20
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.output_line_width'
,
"Max line width for the profiling output"
,
IntParam
(
512
,
lambda
i
:
i
>
0
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.min_memory_size'
,
"""For the memory profile, do not print Apply nodes if the size
of their outputs (in bytes) is lower than this threshold"""
,
IntParam
(
1024
,
lambda
i
:
i
>=
0
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.min_peak_memory'
,
"""The min peak memory usage of the order"""
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.destination'
,
"""
File destination of the profiling output
"""
,
StrParam
(
'stderr'
),
in_c_key
=
False
)
AddConfigVar
(
'profiling.debugprint'
,
"""
Do a debugprint of the profiled functions
"""
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'optdb.position_cutoff'
,
'Where to stop eariler during optimization. It represent the'
' position of the optimizer where to stop.'
,
FloatParam
(
numpy
.
inf
),
in_c_key
=
False
)
AddConfigVar
(
'optdb.max_use_ratio'
,
'A ratio that prevent infinite loop in EquilibriumOptimizer.'
,
FloatParam
(
5
),
in_c_key
=
False
)
AddConfigVar
(
'gcc.cxxflags'
,
"Extra compiler flags for gcc"
,
StrParam
(
""
))
AddConfigVar
(
'cmodule.mac_framework_link'
,
"If set to True, breaks certain MacOS installations with the infamous "
"Bus Error"
,
BoolParam
(
False
))
AddConfigVar
(
'cmodule.warn_no_version'
,
"If True, will print a warning when compiling one or more Op "
"with C code that can't be cached because there is no "
"c_code_cache_version() function associated to at least one of "
"those Ops."
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'cmodule.remove_gxx_opt'
,
"If True, will remove the -O* parameter passed to g++."
"This is useful to debug in gdb modules compiled by Theano."
"The parameter -g is passed by default to g++"
,
BoolParam
(
False
))
AddConfigVar
(
'cmodule.compilation_warning'
,
"If True, will print compilation warnings."
,
BoolParam
(
False
))
AddConfigVar
(
'cmodule.preload_cache'
,
"If set to True, will preload the C module cache at import time"
,
BoolParam
(
False
,
allow_override
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'metaopt.verbose'
,
"Enable verbose output for meta optimizers"
,
theano
.
configparser
.
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'profile'
,
"If VM should collect profile information"
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'profile_optimizer'
,
"If VM should collect optimizer profile information"
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'profile_memory'
,
"If VM should collect memory profile information and print it"
,
BoolParam
(
False
),
in_c_key
=
False
)
def
filter_vm_lazy
(
val
):
if
val
==
'False'
or
val
is
False
:
return
False
elif
val
==
'True'
or
val
is
True
:
return
True
elif
val
==
'None'
or
val
is
None
:
return
None
else
:
raise
ValueError
(
'Valid values for an vm.lazy parameter '
'should be None, False or True, not `
%
s`.'
%
val
)
AddConfigVar
(
'vm.lazy'
,
"Useful only for the vm linkers. When lazy is None,"
" auto detect if lazy evaluation is needed and use the apropriate"
" version. If lazy is True/False, force the version used between"
" Loop/LoopGC and Stack."
,
ConfigParam
(
'None'
,
filter_vm_lazy
),
in_c_key
=
False
)
AddConfigVar
(
'warn.identify_1pexp_bug'
,
'Warn if Theano versions prior to 7987b51 (2011-12-18) could have '
'yielded a wrong result due to a bug in the is_1pexp function'
,
BoolParam
(
warn_default
(
'0.4.1'
)),
in_c_key
=
False
)
AddConfigVar
(
'on_shape_error'
,
"warn: print a warning and use the default"
" value. raise: raise an error"
,
theano
.
configparser
.
EnumStr
(
"warn"
,
"raise"
),
in_c_key
=
False
)
AddConfigVar
(
'tensor.insert_inplace_optimizer_validate_nb'
,
"-1: auto, if graph have less then 500 nodes 1, else 10"
,
theano
.
configparser
.
IntParam
(
-
1
),
in_c_key
=
False
)
AddConfigVar
(
'experimental.local_alloc_elemwise'
,
"DEPRECATED: If True, enable the experimental"
" optimization local_alloc_elemwise."
" Generates error if not True. Use"
" optimizer_excluding=local_alloc_elemwise"
" to dsiable."
,
theano
.
configparser
.
BoolParam
(
True
,
is_valid
=
lambda
x
:
x
),
in_c_key
=
False
)
# False could make the graph faster but not as safe.
AddConfigVar
(
'experimental.local_alloc_elemwise_assert'
,
"When the local_alloc_elemwise is applied, add"
" an assert to highlight shape errors."
,
theano
.
configparser
.
BoolParam
(
True
),
in_c_key
=
False
)
AddConfigVar
(
'scan.allow_gc'
,
"Allow/disallow gc inside of Scan (default: False)"
,
BoolParam
(
False
))
AddConfigVar
(
'scan.allow_output_prealloc'
,
"Allow/disallow memory preallocation for outputs inside of scan "
"(default: True)"
,
BoolParam
(
True
))
AddConfigVar
(
'pycuda.init'
,
"""If True, always initialize PyCUDA when Theano want to
initilize the GPU. Currently, we must always initialize
PyCUDA before Theano do it. Setting this flag to True,
ensure that, but always import PyCUDA. It can be done
manually by importing theano.misc.pycuda_init before theano
initialize the GPU device.
"""
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'cublas.lib'
,
"""Name of the cuda blas library for the linker."""
,
StrParam
(
'cublas'
))
AddConfigVar
(
'lib.cnmem'
,
"""Do we enable CNMeM or not (a faster CUDA memory allocator).
The parameter represent the start size (in MB or
%
of
total GPU memory) of the memory pool.
0: not enabled.
0 < N <= 1:
%
of the total GPU memory (clipped to .985 for driver memory)
> 0: use that number of MB of memory.
"""
,
# We should not mix both allocator, so we can't override
FloatParam
(
0
,
lambda
i
:
i
>=
0
,
allow_override
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'compile.wait'
,
"""Time to wait before retrying to aquire the compile lock."""
,
IntParam
(
5
,
lambda
i
:
i
>
0
,
allow_override
=
False
),
in_c_key
=
False
)
def
_timeout_default
():
return
theano
.
config
.
compile
.
wait
*
24
AddConfigVar
(
'compile.timeout'
,
"""In seconds, time that a process will wait before deciding to
override an existing lock. An override only happens when the existing
lock is held by the same owner *and* has not been 'refreshed' by this
owner for more than this period. Refreshes are done every half timeout
period for running processes."""
,
IntParam
(
_timeout_default
,
lambda
i
:
i
>=
0
,
allow_override
=
False
),
in_c_key
=
False
)
try
:
p_out
=
output_subprocess_Popen
([
config
.
cxx
,
'-dumpversion'
])
gcc_version_str
=
p_out
[
0
]
.
strip
()
.
decode
()
except
OSError
:
# Typically means gcc cannot be found.
gcc_version_str
=
'GCC_NOT_FOUND'
def
local_bitwidth
():
"""
Return 32 for 32bit arch, 64 for 64bit arch.
By "architecture", we mean the size of memory pointers (size_t in C),
*not* the size of long int, as it can be different.
"""
# Note that according to Python documentation, `platform.architecture()` is
# not reliable on OS X with universal binaries.
# Also, sys.maxsize does not exist in Python < 2.6.
# 'P' denotes a void*, and the size is expressed in bytes.
return
struct
.
calcsize
(
'P'
)
*
8
def
python_int_bitwidth
():
"""
Return the bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
return
struct
.
calcsize
(
'l'
)
*
8
compiledir_format_dict
=
{
"platform"
:
platform
.
platform
(),
"processor"
:
platform
.
processor
(),
"python_version"
:
platform
.
python_version
(),
"python_bitwidth"
:
local_bitwidth
(),
"python_int_bitwidth"
:
python_int_bitwidth
(),
"theano_version"
:
theano
.
__version__
,
"numpy_version"
:
numpy
.
__version__
,
"gxx_version"
:
gcc_version_str
.
replace
(
" "
,
"_"
),
"hostname"
:
socket
.
gethostname
()}
def
short_platform
(
r
=
None
,
p
=
None
):
"""
Return a safe shorter version of platform.platform().
The old default Theano compiledir used platform.platform in
it. This use the platform.version() as a substring. This is too
specific as it contain the full kernel number and package
version. This cause the compiledir to change each time there is a
new linux kernel update. This function remove the part of platform
that are too precise.
If we have something else then expected, we do nothing. So this
should be safe on other OS.
Some example if we use platform.platform() direction. On the same
OS, with just some kernel updates.
compiledir_Linux-2.6.32-504.el6.x86_64-x86_64-with-redhat-6.6-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.29.2.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.23.3.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.20.3.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.17.1.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.11.2.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.23.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.6.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.6.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.2.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.5.2.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.7.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.4.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
We suppose the version are ``X.Y[.*]-(digit)*(anything)*``. We keep ``X.Y``
and don't keep less important digit in the part before ``-`` and we remove
the leading digit after the first ``-``.
If the information don't fit that pattern, we do not modify platform.
"""
if
r
is
None
:
r
=
platform
.
release
()
if
p
is
None
:
p
=
platform
.
platform
()
sp
=
r
.
split
(
'-'
)
if
len
(
sp
)
<
2
:
return
p
# For the split before the first -, we remove all learning digit:
kernel_version
=
sp
[
0
]
.
split
(
'.'
)
if
len
(
kernel_version
)
<=
2
:
# kernel version should always have at least 3 number.
# If not, it use another semantic, so don't change it.
return
p
sp
[
0
]
=
'.'
.
join
(
kernel_version
[:
2
])
# For the split after the first -, we remove leading non-digit value.
rest
=
sp
[
1
]
.
split
(
'.'
)
while
len
(
rest
):
if
rest
[
0
]
.
isdigit
():
del
rest
[
0
]
else
:
break
sp
[
1
]
=
'.'
.
join
(
rest
)
# For sp[2:], we don't change anything.
sr
=
'-'
.
join
(
sp
)
p
=
p
.
replace
(
r
,
sr
)
return
p
compiledir_format_dict
[
'short_platform'
]
=
short_platform
()
compiledir_format_keys
=
", "
.
join
(
sorted
(
compiledir_format_dict
.
keys
()))
default_compiledir_format
=
(
"compiledir_
%(short_platform)
s-
%(processor)
s-"
"
%(python_version)
s-
%(python_bitwidth)
s"
)
AddConfigVar
(
"compiledir_format"
,
textwrap
.
fill
(
textwrap
.
dedent
(
"""
\
Format string for platform-dependent compiled
module subdirectory (relative to base_compiledir).
Available keys:
%
s. Defaults to
%
r.
"""
%
(
compiledir_format_keys
,
default_compiledir_format
))),
StrParam
(
default_compiledir_format
,
allow_override
=
False
),
in_c_key
=
False
)
def
default_compiledirname
():
formatted
=
theano
.
config
.
compiledir_format
%
compiledir_format_dict
safe
=
re
.
sub
(
"[
\
(
\
)
\
s,]+"
,
"_"
,
formatted
)
return
safe
def
filter_base_compiledir
(
path
):
# Expand '~' in path
return
os
.
path
.
expanduser
(
str
(
path
))
def
filter_compiledir
(
path
):
# Expand '~' in path
path
=
os
.
path
.
expanduser
(
path
)
# Turn path into the 'real' path. This ensures that:
# 1. There is no relative path, which would fail e.g. when trying to
# import modules from the compile dir.
# 2. The path is stable w.r.t. e.g. symlinks (which makes it easier
# to re-use compiled modules).
path
=
os
.
path
.
realpath
(
path
)
if
os
.
access
(
path
,
os
.
F_OK
):
# Do it exist?
if
not
os
.
access
(
path
,
os
.
R_OK
|
os
.
W_OK
|
os
.
X_OK
):
# If it exist we need read, write and listing access
raise
ValueError
(
"compiledir '
%
s' exists but you don't have read, write"
" or listing permissions."
%
path
)
else
:
try
:
os
.
makedirs
(
path
,
0
o770
)
# read-write-execute for user and group
except
OSError
as
e
:
# Maybe another parallel execution of theano was trying to create
# the same directory at the same time.
if
e
.
errno
!=
errno
.
EEXIST
:
raise
ValueError
(
"Unable to create the compiledir directory"
" '
%
s'. Check the permissions."
%
path
)
# PROBLEM: sometimes the initial approach based on
# os.system('touch') returned -1 for an unknown reason; the
# alternate approach here worked in all cases... it was weird.
# No error should happen as we checked the permissions.
init_file
=
os
.
path
.
join
(
path
,
'__init__.py'
)
if
not
os
.
path
.
exists
(
init_file
):
try
:
open
(
init_file
,
'w'
)
.
close
()
except
IOError
as
e
:
if
os
.
path
.
exists
(
init_file
):
pass
# has already been created
else
:
e
.
args
+=
(
'
%
s exist?
%
s'
%
(
path
,
os
.
path
.
exists
(
path
)),)
raise
return
path
def
get_home_dir
():
"""
Return location of the user's home directory.
"""
home
=
os
.
getenv
(
'HOME'
)
if
home
is
None
:
# This expanduser usually works on Windows (see discussion on
# theano-users, July 13 2010).
home
=
os
.
path
.
expanduser
(
'~'
)
if
home
==
'~'
:
# This might happen when expanduser fails. Although the cause of
# failure is a mystery, it has been seen on some Windows system.
home
=
os
.
getenv
(
'USERPROFILE'
)
assert
home
is
not
None
return
home
# On Windows we should avoid writing temporary files to a directory that is
# part of the roaming part of the user profile. Instead we use the local part
# of the user profile, when available.
if
sys
.
platform
==
'win32'
and
os
.
getenv
(
'LOCALAPPDATA'
)
is
not
None
:
default_base_compiledir
=
os
.
path
.
join
(
os
.
getenv
(
'LOCALAPPDATA'
),
'Theano'
)
else
:
default_base_compiledir
=
os
.
path
.
join
(
get_home_dir
(),
'.theano'
)
AddConfigVar
(
'base_compiledir'
,
"platform-independent root directory for compiled modules"
,
ConfigParam
(
default_base_compiledir
,
filter
=
filter_base_compiledir
,
allow_override
=
False
),
in_c_key
=
False
)
def
default_compiledir
():
return
os
.
path
.
join
(
theano
.
config
.
base_compiledir
,
default_compiledirname
())
AddConfigVar
(
'compiledir'
,
"platform-dependent cache directory for compiled modules"
,
ConfigParam
(
default_compiledir
,
filter
=
filter_compiledir
,
allow_override
=
False
),
in_c_key
=
False
)
# Check if there are remaining flags provided by the user through THEANO_FLAGS.
for
key
in
THEANO_FLAGS_DICT
.
keys
():
warnings
.
warn
(
'Theano does not recognise this flag: {}'
.
format
(
key
))
theano/configparser.py
浏览文件 @
3adaa82f
...
...
@@ -124,7 +124,7 @@ def change_flags(**kwargs):
return
change_flags_exec
def
fetch_val_for_key
(
key
):
def
fetch_val_for_key
(
key
,
delete_key
=
False
):
"""Return the overriding config value for a key.
A successful search returns a string value.
An unsuccessful search raises a KeyError
...
...
@@ -137,6 +137,8 @@ def fetch_val_for_key(key):
# first try to find it in the FLAGS
try
:
if
delete_key
:
return
THEANO_FLAGS_DICT
.
pop
(
key
)
return
THEANO_FLAGS_DICT
[
key
]
except
KeyError
:
pass
...
...
@@ -270,14 +272,14 @@ def AddConfigVar(name, doc, configparam, root=config, in_c_key=True):
# Trigger a read of the value from config files and env vars
# This allow to filter wrong value from the user.
if
not
callable
(
configparam
.
default
):
configparam
.
__get__
(
root
,
type
(
root
))
configparam
.
__get__
(
root
,
type
(
root
)
,
delete_key
=
True
)
else
:
# We do not want to evaluate now the default value
# when it is a callable.
try
:
fetch_val_for_key
(
configparam
.
fullname
)
# The user provided a value, filter it now.
configparam
.
__get__
(
root
,
type
(
root
))
configparam
.
__get__
(
root
,
type
(
root
)
,
delete_key
=
True
)
except
KeyError
:
pass
setattr
(
root
.
__class__
,
sections
[
0
],
configparam
)
...
...
@@ -305,12 +307,13 @@ class ConfigParam(object):
# Calling `filter` here may actually be harmful if the default value is
# invalid and causes a crash or has unwanted side effects.
def
__get__
(
self
,
cls
,
type_
):
def
__get__
(
self
,
cls
,
type_
,
delete_key
=
False
):
if
cls
is
None
:
return
self
if
not
hasattr
(
self
,
'val'
):
try
:
val_str
=
fetch_val_for_key
(
self
.
fullname
)
val_str
=
fetch_val_for_key
(
self
.
fullname
,
delete_key
=
delete_key
)
self
.
is_default
=
False
except
KeyError
:
if
callable
(
self
.
default
):
...
...
theano/gof/__init__.py
浏览文件 @
3adaa82f
...
...
@@ -38,10 +38,6 @@ e-mail thread "What is gof?".
from
theano.gof.cc
import
\
CLinker
,
OpWiseCLinker
,
DualLinker
,
HideC
# Also adds config vars
from
theano.gof.compiledir
import
\
local_bitwidth
,
python_int_bitwidth
from
theano.gof.fg
import
\
CachedConstantError
,
InconsistencyError
,
MissingInputError
,
FunctionGraph
...
...
theano/gof/cc.py
浏览文件 @
3adaa82f
...
...
@@ -20,11 +20,6 @@ from theano.compat import izip
from
six
import
string_types
,
reraise
from
six.moves
import
StringIO
,
xrange
# Note that we need to do this before importing cutils, since when there is
# no theano cache dir initialized yet, importing cutils may require compilation
# of cutils_ext.
from
theano.configparser
import
AddConfigVar
,
StrParam
# gof imports
from
theano.gof
import
graph
from
theano.gof
import
link
...
...
@@ -33,10 +28,6 @@ from theano.gof import cmodule
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.gof.callcache
import
CallCache
AddConfigVar
(
'gcc.cxxflags'
,
"Extra compiler flags for gcc"
,
StrParam
(
""
))
_logger
=
logging
.
getLogger
(
"theano.gof.cc"
)
...
...
theano/gof/cmodule.py
浏览文件 @
3adaa82f
...
...
@@ -32,9 +32,7 @@ from theano.misc.windows import (subprocess_Popen,
# we will abuse the lockfile mechanism when reading and writing the registry
from
theano.gof
import
compilelock
from
theano.gof.compiledir
import
gcc_version_str
,
local_bitwidth
from
theano.configparser
import
AddConfigVar
,
BoolParam
from
theano.configdefaults
import
gcc_version_str
,
local_bitwidth
importlib
=
None
try
:
...
...
@@ -42,36 +40,6 @@ try:
except
ImportError
:
pass
AddConfigVar
(
'cmodule.mac_framework_link'
,
"If set to True, breaks certain MacOS installations with the infamous "
"Bus Error"
,
BoolParam
(
False
))
AddConfigVar
(
'cmodule.warn_no_version'
,
"If True, will print a warning when compiling one or more Op "
"with C code that can't be cached because there is no "
"c_code_cache_version() function associated to at least one of "
"those Ops."
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'cmodule.remove_gxx_opt'
,
"If True, will remove the -O* parameter passed to g++."
"This is useful to debug in gdb modules compiled by Theano."
"The parameter -g is passed by default to g++"
,
BoolParam
(
False
))
AddConfigVar
(
'cmodule.compilation_warning'
,
"If True, will print compilation warnings."
,
BoolParam
(
False
))
AddConfigVar
(
'cmodule.preload_cache'
,
"If set to True, will preload the C module cache at import time"
,
BoolParam
(
False
,
allow_override
=
False
),
in_c_key
=
False
)
_logger
=
logging
.
getLogger
(
"theano.gof.cmodule"
)
METH_VARARGS
=
"METH_VARARGS"
...
...
theano/gof/compiledir.py
浏览文件 @
3adaa82f
from
__future__
import
print_function
import
six.moves.cPickle
as
pickle
import
errno
import
logging
import
os
import
platform
import
re
import
shutil
import
struct
import
socket
import
sys
import
textwrap
import
numpy
import
theano
from
six
import
string_types
,
iteritems
from
theano.configparser
import
config
,
AddConfigVar
,
ConfigParam
,
StrParam
from
theano.configparser
import
config
from
theano.gof.utils
import
flatten
from
theano.misc.windows
import
output_subprocess_Popen
_logger
=
logging
.
getLogger
(
"theano.gof.compiledir"
)
try
:
p_out
=
output_subprocess_Popen
([
theano
.
config
.
cxx
,
'-dumpversion'
])
gcc_version_str
=
p_out
[
0
]
.
strip
()
.
decode
()
except
OSError
:
# Typically means gcc cannot be found.
gcc_version_str
=
'GCC_NOT_FOUND'
def
local_bitwidth
():
"""
Return 32 for 32bit arch, 64 for 64bit arch.
By "architecture", we mean the size of memory pointers (size_t in C),
*not* the size of long int, as it can be different.
"""
# Note that according to Python documentation, `platform.architecture()` is
# not reliable on OS X with universal binaries.
# Also, sys.maxsize does not exist in Python < 2.6.
# 'P' denotes a void*, and the size is expressed in bytes.
return
struct
.
calcsize
(
'P'
)
*
8
def
python_int_bitwidth
():
"""
Return the bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
return
struct
.
calcsize
(
'l'
)
*
8
compiledir_format_dict
=
{
"platform"
:
platform
.
platform
(),
"processor"
:
platform
.
processor
(),
"python_version"
:
platform
.
python_version
(),
"python_bitwidth"
:
local_bitwidth
(),
"python_int_bitwidth"
:
python_int_bitwidth
(),
"theano_version"
:
theano
.
__version__
,
"numpy_version"
:
numpy
.
__version__
,
"gxx_version"
:
gcc_version_str
.
replace
(
" "
,
"_"
),
"hostname"
:
socket
.
gethostname
()}
def
short_platform
(
r
=
None
,
p
=
None
):
"""
Return a safe shorter version of platform.platform().
The old default Theano compiledir used platform.platform in
it. This use the platform.version() as a substring. This is too
specific as it contain the full kernel number and package
version. This cause the compiledir to change each time there is a
new linux kernel update. This function remove the part of platform
that are too precise.
If we have something else then expected, we do nothing. So this
should be safe on other OS.
Some example if we use platform.platform() direction. On the same
OS, with just some kernel updates.
compiledir_Linux-2.6.32-504.el6.x86_64-x86_64-with-redhat-6.6-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.29.2.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.23.3.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.20.3.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.17.1.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.11.2.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.23.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.6.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.6.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.2.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.5.2.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.7.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.4.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
We suppose the version are ``X.Y[.*]-(digit)*(anything)*``. We keep ``X.Y``
and don't keep less important digit in the part before ``-`` and we remove
the leading digit after the first ``-``.
If the information don't fit that pattern, we do not modify platform.
"""
if
r
is
None
:
r
=
platform
.
release
()
if
p
is
None
:
p
=
platform
.
platform
()
sp
=
r
.
split
(
'-'
)
if
len
(
sp
)
<
2
:
return
p
# For the split before the first -, we remove all learning digit:
kernel_version
=
sp
[
0
]
.
split
(
'.'
)
if
len
(
kernel_version
)
<=
2
:
# kernel version should always have at least 3 number.
# If not, it use another semantic, so don't change it.
return
p
sp
[
0
]
=
'.'
.
join
(
kernel_version
[:
2
])
# For the split after the first -, we remove leading non-digit value.
rest
=
sp
[
1
]
.
split
(
'.'
)
while
len
(
rest
):
if
rest
[
0
]
.
isdigit
():
del
rest
[
0
]
else
:
break
sp
[
1
]
=
'.'
.
join
(
rest
)
# For sp[2:], we don't change anything.
sr
=
'-'
.
join
(
sp
)
p
=
p
.
replace
(
r
,
sr
)
p
=
p
.
replace
(
':'
,
'-'
)
p
=
p
.
replace
(
'?'
,
'-'
)
p
=
p
.
replace
(
'*'
,
'-'
)
p
=
p
.
replace
(
'/'
,
'-'
)
return
p
compiledir_format_dict
[
'short_platform'
]
=
short_platform
()
compiledir_format_keys
=
", "
.
join
(
sorted
(
compiledir_format_dict
.
keys
()))
default_compiledir_format
=
(
"compiledir_
%(short_platform)
s-
%(processor)
s-"
"
%(python_version)
s-
%(python_bitwidth)
s"
)
AddConfigVar
(
"compiledir_format"
,
textwrap
.
fill
(
textwrap
.
dedent
(
"""
\
Format string for platform-dependent compiled
module subdirectory (relative to base_compiledir).
Available keys:
%
s. Defaults to
%
r.
"""
%
(
compiledir_format_keys
,
default_compiledir_format
))),
StrParam
(
default_compiledir_format
,
allow_override
=
False
),
in_c_key
=
False
)
def
default_compiledirname
():
formatted
=
config
.
compiledir_format
%
compiledir_format_dict
safe
=
re
.
sub
(
"[
\
(
\
)
\
s,]+"
,
"_"
,
formatted
)
return
safe
def
filter_base_compiledir
(
path
):
# Expand '~' in path
return
os
.
path
.
expanduser
(
str
(
path
))
def
filter_compiledir
(
path
):
# Expand '~' in path
path
=
os
.
path
.
expanduser
(
path
)
# Turn path into the 'real' path. This ensures that:
# 1. There is no relative path, which would fail e.g. when trying to
# import modules from the compile dir.
# 2. The path is stable w.r.t. e.g. symlinks (which makes it easier
# to re-use compiled modules).
path
=
os
.
path
.
realpath
(
path
)
if
os
.
access
(
path
,
os
.
F_OK
):
# Do it exist?
if
not
os
.
access
(
path
,
os
.
R_OK
|
os
.
W_OK
|
os
.
X_OK
):
# If it exist we need read, write and listing access
raise
ValueError
(
"compiledir '
%
s' exists but you don't have read, write"
" or listing permissions."
%
path
)
else
:
try
:
os
.
makedirs
(
path
,
0
o770
)
# read-write-execute for user and group
except
OSError
as
e
:
# Maybe another parallel execution of theano was trying to create
# the same directory at the same time.
if
e
.
errno
!=
errno
.
EEXIST
:
raise
ValueError
(
"Unable to create the compiledir directory"
" '
%
s'. Check the permissions."
%
path
)
# PROBLEM: sometimes the initial approach based on
# os.system('touch') returned -1 for an unknown reason; the
# alternate approach here worked in all cases... it was weird.
# No error should happen as we checked the permissions.
init_file
=
os
.
path
.
join
(
path
,
'__init__.py'
)
if
not
os
.
path
.
exists
(
init_file
):
try
:
open
(
init_file
,
'w'
)
.
close
()
except
IOError
as
e
:
if
os
.
path
.
exists
(
init_file
):
pass
# has already been created
else
:
e
.
args
+=
(
'
%
s exist?
%
s'
%
(
path
,
os
.
path
.
exists
(
path
)),)
raise
return
path
def
get_home_dir
():
"""
Return location of the user's home directory.
"""
home
=
os
.
getenv
(
'HOME'
)
if
home
is
None
:
# This expanduser usually works on Windows (see discussion on
# theano-users, July 13 2010).
home
=
os
.
path
.
expanduser
(
'~'
)
if
home
==
'~'
:
# This might happen when expanduser fails. Although the cause of
# failure is a mystery, it has been seen on some Windows system.
home
=
os
.
getenv
(
'USERPROFILE'
)
assert
home
is
not
None
return
home
# On Windows we should avoid writing temporary files to a directory that is
# part of the roaming part of the user profile. Instead we use the local part
# of the user profile, when available.
if
sys
.
platform
==
'win32'
and
os
.
getenv
(
'LOCALAPPDATA'
)
is
not
None
:
default_base_compiledir
=
os
.
path
.
join
(
os
.
getenv
(
'LOCALAPPDATA'
),
'Theano'
)
else
:
home_dir
=
get_home_dir
()
if
not
os
.
access
(
home_dir
,
os
.
W_OK
):
home_dir
=
'/tmp'
user
=
os
.
getenv
(
'USER'
)
if
user
is
not
None
:
home_dir
=
os
.
path
.
join
(
home_dir
,
user
)
default_base_compiledir
=
os
.
path
.
join
(
home_dir
,
'.theano'
)
AddConfigVar
(
'base_compiledir'
,
"platform-independent root directory for compiled modules"
,
ConfigParam
(
default_base_compiledir
,
filter
=
filter_base_compiledir
,
allow_override
=
False
),
in_c_key
=
False
)
AddConfigVar
(
'compiledir'
,
"platform-dependent cache directory for compiled modules"
,
ConfigParam
(
os
.
path
.
join
(
config
.
base_compiledir
,
default_compiledirname
()),
filter
=
filter_compiledir
,
allow_override
=
False
),
in_c_key
=
False
)
def
cleanup
():
"""
...
...
theano/gof/compilelock.py
浏览文件 @
3adaa82f
...
...
@@ -12,7 +12,6 @@ from contextlib import contextmanager
import
numpy
as
np
from
theano
import
config
from
theano.configparser
import
AddConfigVar
,
IntParam
random
=
np
.
random
.
RandomState
([
2015
,
8
,
2
])
...
...
@@ -22,25 +21,6 @@ if _logger.level == logging.NOTSET:
# INFO will show the "Refreshing lock" messages
_logger
.
setLevel
(
logging
.
INFO
)
AddConfigVar
(
'compile.wait'
,
"""Time to wait before retrying to aquire the compile lock."""
,
IntParam
(
5
,
lambda
i
:
i
>
0
,
allow_override
=
False
),
in_c_key
=
False
)
def
_timeout_default
():
return
config
.
compile
.
wait
*
24
AddConfigVar
(
'compile.timeout'
,
"""In seconds, time that a process will wait before deciding to
override an existing lock. An override only happens when the existing
lock is held by the same owner *and* has not been 'refreshed' by this
owner for more than this period. Refreshes are done every half timeout
period for running processes."""
,
IntParam
(
_timeout_default
,
lambda
i
:
i
>=
0
,
allow_override
=
False
),
in_c_key
=
False
)
hostname
=
socket
.
gethostname
()
...
...
theano/gof/opt.py
浏览文件 @
3adaa82f
...
...
@@ -1042,13 +1042,6 @@ class LocalOptimizer(object):
(
' '
*
level
),
self
.
__class__
.
__name__
,
id
(
self
)),
file
=
stream
)
theano
.
configparser
.
AddConfigVar
(
'metaopt.verbose'
,
"Enable verbose output for meta optimizers"
,
theano
.
configparser
.
BoolParam
(
False
),
in_c_key
=
False
)
class
LocalMetaOptimizer
(
LocalOptimizer
):
"""
Base class for meta-optimizers that try a set of LocalOptimizers
...
...
theano/gof/optdb.py
浏览文件 @
3adaa82f
...
...
@@ -2,25 +2,12 @@ from __future__ import print_function
import
copy
import
sys
import
numpy
from
theano.compat
import
DefaultOrderedDict
from
theano.misc.ordered_set
import
OrderedSet
from
six
import
StringIO
from
theano.gof
import
opt
from
theano.configparser
import
AddConfigVar
,
FloatParam
from
theano
import
config
AddConfigVar
(
'optdb.position_cutoff'
,
'Where to stop eariler during optimization. It represent the'
' position of the optimizer where to stop.'
,
FloatParam
(
numpy
.
inf
),
in_c_key
=
False
)
AddConfigVar
(
'optdb.max_use_ratio'
,
'A ratio that prevent infinite loop in EquilibriumOptimizer.'
,
FloatParam
(
5
),
in_c_key
=
False
)
class
DB
(
object
):
def
__hash__
(
self
):
...
...
theano/gof/tests/test_compiledir.py
浏览文件 @
3adaa82f
from
theano.
gof.compiledir
import
short_platform
from
theano.
configdefaults
import
short_platform
def
test_short_platform
():
...
...
theano/gof/vm.py
浏览文件 @
3adaa82f
...
...
@@ -13,8 +13,7 @@ import sys
import
time
import
warnings
from
theano.configparser
import
(
config
,
AddConfigVar
,
BoolParam
,
ConfigParam
,
_config_var_list
)
from
theano.configparser
import
(
config
,
_config_var_list
)
import
theano.gof.cmodule
...
...
@@ -23,39 +22,6 @@ from six.moves import xrange
logger
=
logging
.
getLogger
(
__name__
)
AddConfigVar
(
'profile'
,
"If VM should collect profile information"
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'profile_optimizer'
,
"If VM should collect optimizer profile information"
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'profile_memory'
,
"If VM should collect memory profile information and print it"
,
BoolParam
(
False
),
in_c_key
=
False
)
def
filter_vm_lazy
(
val
):
if
val
==
'False'
or
val
is
False
:
return
False
elif
val
==
'True'
or
val
is
True
:
return
True
elif
val
==
'None'
or
val
is
None
:
return
None
else
:
raise
ValueError
(
'Valid values for an vm.lazy parameter '
'should be None, False or True, not `
%
s`.'
%
val
)
AddConfigVar
(
'vm.lazy'
,
"Useful only for the vm linkers. When lazy is None,"
" auto detect if lazy evaluation is needed and use the apropriate"
" version. If lazy is True/False, force the version used between"
" Loop/LoopGC and Stack."
,
ConfigParam
(
'None'
,
filter_vm_lazy
),
in_c_key
=
False
)
def
calculate_reallocate_info
(
order
,
fgraph
,
storage_map
,
compute_map_re
,
dependencies
):
...
...
theano/sandbox/cuda/__init__.py
浏览文件 @
3adaa82f
...
...
@@ -43,36 +43,6 @@ def register_opt(*tags, **kwargs):
_logger_name
=
'theano.sandbox.cuda'
_logger
=
logging
.
getLogger
(
_logger_name
)
AddConfigVar
(
'pycuda.init'
,
"""If True, always initialize PyCUDA when Theano want to
initilize the GPU. Currently, we must always initialize
PyCUDA before Theano do it. Setting this flag to True,
ensure that, but always import PyCUDA. It can be done
manually by importing theano.misc.pycuda_init before theano
initialize the GPU device.
"""
,
BoolParam
(
False
),
in_c_key
=
False
)
AddConfigVar
(
'cublas.lib'
,
"""Name of the cuda blas library for the linker."""
,
StrParam
(
'cublas'
))
AddConfigVar
(
'lib.cnmem'
,
"""Do we enable CNMeM or not (a faster CUDA memory allocator).
The parameter represent the start size (in MB or
%
of
total GPU memory) of the memory pool.
0: not enabled.
0 < N <= 1:
%
of the total GPU memory (clipped to .985 for driver memory)
> 0: use that number of MB of memory.
"""
,
# We should not mix both allocator, so we can't override
FloatParam
(
0
,
lambda
i
:
i
>=
0
,
allow_override
=
False
),
in_c_key
=
False
)
# is_nvcc_available called here to initialize global vars in
# nvcc_compiler module
nvcc_compiler
.
is_nvcc_available
()
...
...
theano/sandbox/cuda/basic_ops.py
浏览文件 @
3adaa82f
...
...
@@ -3008,7 +3008,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
32
:
tensor
.
basic
.
_convert_to_int32
,
64
:
tensor
.
basic
.
_convert_to_int64
}
intwidth
=
theano
.
gof
.
compiledir
.
python_int_bitwidth
()
intwidth
=
theano
.
configdefaults
.
python_int_bitwidth
()
ilist_
=
convert_map
[
intwidth
](
ilist_
)
assert
x_
.
type
.
dtype
==
y_
.
type
.
dtype
...
...
theano/sandbox/cuda/nvcc_compiler.py
浏览文件 @
3adaa82f
...
...
@@ -10,7 +10,7 @@ import numpy
from
theano
import
config
from
theano.compat
import
decode
,
decode_iter
from
theano.
gof
import
local_bitwidth
from
theano.
configdefaults
import
local_bitwidth
from
theano.gof.utils
import
hash_from_file
from
theano.gof.cmodule
import
(
std_libs
,
std_lib_dirs
,
std_include_dirs
,
dlimport
,
...
...
theano/scan_module/scan_op.py
浏览文件 @
3adaa82f
...
...
@@ -89,15 +89,6 @@ _logger = logging.getLogger('theano.scan_module.scan_op')
from
theano.configparser
import
AddConfigVar
,
BoolParam
AddConfigVar
(
'scan.allow_gc'
,
"Allow/disallow gc inside of Scan (default: False)"
,
BoolParam
(
False
))
AddConfigVar
(
'scan.allow_output_prealloc'
,
"Allow/disallow memory preallocation for outputs inside of scan "
"(default: True)"
,
BoolParam
(
True
))
class
Scan
(
PureOp
):
"""
...
...
theano/tensor/extra_ops.py
浏览文件 @
3adaa82f
...
...
@@ -416,12 +416,12 @@ class BinCountOp(theano.Op):
# Some dtypes are not supported by numpy's implementation of bincount.
# Until another one is available, we should fail at graph construction
# time, not wait for execution.
int_bitwidth
=
theano
.
gof
.
python_int_bitwidth
()
int_bitwidth
=
theano
.
configdefaults
.
python_int_bitwidth
()
if
int_bitwidth
==
64
:
numpy_unsupported_dtypes
=
(
'uint64'
,)
if
int_bitwidth
==
32
:
numpy_unsupported_dtypes
=
(
'uint32'
,
'int64'
,
'uint64'
)
intp_bitwidth
=
theano
.
gof
.
local_bitwidth
()
intp_bitwidth
=
theano
.
configdefaults
.
local_bitwidth
()
if
intp_bitwidth
==
32
:
out_type
=
basic
.
ivector
()
elif
intp_bitwidth
==
64
:
...
...
@@ -598,7 +598,7 @@ class RepeatOp(theano.Op):
# Some dtypes are not supported by numpy's implementation of repeat.
# Until another one is available, we should fail at graph construction
# time, not wait for execution.
ptr_bitwidth
=
theano
.
gof
.
local_bitwidth
()
ptr_bitwidth
=
theano
.
configdefaults
.
local_bitwidth
()
if
ptr_bitwidth
==
64
:
numpy_unsupported_dtypes
=
(
'uint64'
,)
if
ptr_bitwidth
==
32
:
...
...
theano/tensor/nnet/sigm.py
浏览文件 @
3adaa82f
...
...
@@ -14,7 +14,6 @@ import numpy
import
theano
from
theano
import
config
,
gof
,
printing
,
scalar
from
theano.compat
import
imap
from
theano.configparser
import
AddConfigVar
,
BoolParam
from
theano.printing
import
pprint
from
theano.tensor
import
basic
as
tensor
from
theano.tensor
import
elemwise
,
opt
,
NotScalarConstantError
...
...
@@ -462,14 +461,6 @@ def is_1pexp(t):
return
None
AddConfigVar
(
'warn.identify_1pexp_bug'
,
'Warn if Theano versions prior to 7987b51 (2011-12-18) could have '
'yielded a wrong result due to a bug in the is_1pexp function'
,
BoolParam
(
theano
.
configdefaults
.
warn_default
(
'0.4.1'
)),
in_c_key
=
False
)
def
is_exp
(
var
):
"""
Match a variable with either of the `exp(x)` or `-exp(x)` patterns.
...
...
theano/tensor/opt.py
浏览文件 @
3adaa82f
...
...
@@ -53,12 +53,6 @@ from six import StringIO
_logger
=
logging
.
getLogger
(
'theano.tensor.opt'
)
theano
.
configparser
.
AddConfigVar
(
'on_shape_error'
,
"warn: print a warning and use the default"
" value. raise: raise an error"
,
theano
.
configparser
.
EnumStr
(
"warn"
,
"raise"
),
in_c_key
=
False
)
# Utilities
...
...
@@ -230,13 +224,6 @@ def broadcast_like(value, template, fgraph, dtype=None):
return
rval
theano
.
configparser
.
AddConfigVar
(
'tensor.insert_inplace_optimizer_validate_nb'
,
"-1: auto, if graph have less then 500 nodes 1, else 10"
,
theano
.
configparser
.
IntParam
(
-
1
),
in_c_key
=
False
)
def
inplace_elemwise_optimizer_op
(
OP
):
"""
We parametrise it to make it work for Elemwise and GpuElemwise op.
...
...
@@ -1609,26 +1596,6 @@ local_elemwise_alloc = register_specialize(
local_elemwise_alloc_op
(
T
.
Elemwise
,
T
.
Alloc
,
T
.
DimShuffle
)),
'local_alloc_elemwise'
)
theano
.
configparser
.
AddConfigVar
(
'experimental.local_alloc_elemwise'
,
"DEPRECATED: If True, enable the experimental"
" optimization local_alloc_elemwise."
" Generates error if not True. Use"
" optimizer_excluding=local_alloc_elemwise"
" to dsiable."
,
theano
.
configparser
.
BoolParam
(
True
,
is_valid
=
lambda
x
:
x
),
in_c_key
=
False
)
# False could make the graph faster but not as safe.
theano
.
configparser
.
AddConfigVar
(
'experimental.local_alloc_elemwise_assert'
,
"When the local_alloc_elemwise is applied, add"
" an assert to highlight shape errors."
,
theano
.
configparser
.
BoolParam
(
True
),
in_c_key
=
False
)
@gof.local_optimizer
([
T
.
Elemwise
])
def
local_fill_sink
(
node
):
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
3adaa82f
...
...
@@ -6672,7 +6672,7 @@ class test_arithmetic_cast(unittest.TestCase):
class
T_long_tensor
(
unittest
.
TestCase
):
def
test_fit_int64
(
self
):
for
exp
in
xrange
(
gof
.
python_int_bitwidth
()):
for
exp
in
xrange
(
theano
.
configdefaults
.
python_int_bitwidth
()):
val
=
L
(
2
**
exp
-
1
)
scalar_ct
=
constant
(
val
)
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
3adaa82f
...
...
@@ -175,7 +175,7 @@ class TestBinCountOp(utt.InferShapeTester):
'uint8'
,
'uint16'
,
'uint32'
,
'uint64'
):
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
int_bitwidth
=
theano
.
gof
.
python_int_bitwidth
()
int_bitwidth
=
theano
.
configdefaults
.
python_int_bitwidth
()
if
int_bitwidth
==
64
:
numpy_unsupported_dtypes
=
(
'uint64'
,)
if
int_bitwidth
==
32
:
...
...
@@ -208,7 +208,7 @@ class TestBinCountOp(utt.InferShapeTester):
for
dtype
in
tensor
.
discrete_dtypes
:
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
int_bitwidth
=
theano
.
gof
.
python_int_bitwidth
()
int_bitwidth
=
theano
.
configdefaults
.
python_int_bitwidth
()
if
int_bitwidth
==
64
:
numpy_unsupported_dtypes
=
(
'uint64'
,)
if
int_bitwidth
==
32
:
...
...
@@ -408,7 +408,7 @@ class TestRepeatOp(utt.InferShapeTester):
self
.
op
=
RepeatOp
()
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
ptr_bitwidth
=
theano
.
gof
.
local_bitwidth
()
ptr_bitwidth
=
theano
.
configdefaults
.
local_bitwidth
()
if
ptr_bitwidth
==
64
:
self
.
numpy_unsupported_dtypes
=
(
'uint64'
,)
if
ptr_bitwidth
==
32
:
...
...
theano/tests/test_config.py
浏览文件 @
3adaa82f
...
...
@@ -3,7 +3,6 @@ Test config options.
"""
import
unittest
from
theano
import
config
from
theano.configparser
import
AddConfigVar
,
ConfigParam
,
THEANO_FLAGS_DICT
...
...
@@ -31,17 +30,16 @@ class T_config(unittest.TestCase):
except
ValueError
:
pass
try
:
THEANO_FLAGS_DICT
[
'T_config.test_invalid_default_b'
]
=
'ok'
# This should succeed since we defined a proper value, even
# though the default was invalid.
AddConfigVar
(
'T_config.test_invalid_default_b'
,
doc
=
'unittest'
,
configparam
=
ConfigParam
(
'invalid'
,
filter
=
filter
),
in_c_key
=
False
)
finally
:
# Dicionary clean-up.
del
THEANO_FLAGS_DICT
[
'T_config.test_invalid_default_b'
]
THEANO_FLAGS_DICT
[
'T_config.test_invalid_default_b'
]
=
'ok'
# This should succeed since we defined a proper value, even
# though the default was invalid.
AddConfigVar
(
'T_config.test_invalid_default_b'
,
doc
=
'unittest'
,
configparam
=
ConfigParam
(
'invalid'
,
filter
=
filter
),
in_c_key
=
False
)
# Check that the flag has been removed
assert
'T_config.test_invalid_default_b'
not
in
THEANO_FLAGS_DICT
# TODO We should remove these dummy options on test exit.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论