Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
7e23a1a4
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7e23a1a4
编写于
4月 20, 2020
作者:
F
fary86
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issues of save_graphs_path, Type/Value error message and log file mode
上级
ae7556ff
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
67 addition
and
8 deletion
+67
-8
mindspore/ccsrc/utils/log_adapter.cc
mindspore/ccsrc/utils/log_adapter.cc
+5
-1
mindspore/context.py
mindspore/context.py
+27
-1
tests/ut/cpp/operator/composite_test.cc
tests/ut/cpp/operator/composite_test.cc
+2
-2
tests/ut/python/pynative_mode/test_backend.py
tests/ut/python/pynative_mode/test_backend.py
+16
-2
tests/ut/python/pynative_mode/test_context.py
tests/ut/python/pynative_mode/test_context.py
+17
-2
未找到文件。
mindspore/ccsrc/utils/log_adapter.cc
浏览文件 @
7e23a1a4
...
...
@@ -179,7 +179,7 @@ void LogWriter::operator^(const LogStream &stream) const {
std
::
ostringstream
oss
;
oss
<<
location_
.
file_
<<
":"
<<
location_
.
line_
<<
" "
<<
location_
.
func_
<<
"] "
;
if
(
exception_type_
!=
NoExceptionType
)
{
if
(
exception_type_
!=
NoExceptionType
&&
exception_type_
!=
TypeError
&&
exception_type_
!=
ValueError
)
{
oss
<<
ExceptionTypeToString
(
exception_type_
)
<<
" "
;
}
oss
<<
msg
.
str
();
...
...
@@ -242,6 +242,10 @@ void mindspore_log_init(void) {
if
(
mindspore
::
GetEnv
(
"GLOG_v"
).
empty
())
{
FLAGS_v
=
mindspore
::
WARNING
;
}
// set default log file mode to 0640
if
(
mindspore
::
GetEnv
(
"GLOG_logfile_mode"
).
empty
())
{
FLAGS_logfile_mode
=
0640
;
}
// default print log to screen
if
(
mindspore
::
GetEnv
(
"GLOG_logtostderr"
).
empty
())
{
FLAGS_logtostderr
=
true
;
...
...
mindspore/context.py
浏览文件 @
7e23a1a4
...
...
@@ -16,6 +16,7 @@
The context of mindspore, used to configure the current execution environment,
including execution mode, execution backend and other feature switchs.
"""
import
os
import
threading
from
collections
import
namedtuple
from
types
import
FunctionType
...
...
@@ -33,6 +34,31 @@ GRAPH_MODE = 0
PYNATIVE_MODE
=
1
def
_make_directory
(
path
:
str
):
"""Make directory."""
real_path
=
None
if
path
is
None
or
not
isinstance
(
path
,
str
)
or
path
.
strip
()
==
""
:
raise
ValueError
(
f
"Input path `
{
path
}
` is invaild type"
)
# convert the relative paths
path
=
os
.
path
.
realpath
(
path
)
logger
.
debug
(
"The absolute path is %r"
,
path
)
# check whether the path is already existed and has written permissions
if
os
.
path
.
exists
(
path
):
real_path
=
path
else
:
# All exceptions need to be caught because create directory maybe have some limit(permissions)
logger
.
debug
(
"The directory(%s) doesn't exist, will create it"
,
path
)
try
:
os
.
makedirs
(
path
)
real_path
=
path
except
PermissionError
as
e
:
logger
.
error
(
f
"No write permission on the directory `
{
path
}
, error =
{
e
}
"
)
raise
ValueError
(
f
"No write permission on the directory `
{
path
}
`."
)
return
real_path
class
_ThreadLocalInfo
(
threading
.
local
):
"""
Thread local Info used for store thread local attributes.
...
...
@@ -173,7 +199,7 @@ class _Context:
@
save_graphs_path
.
setter
def
save_graphs_path
(
self
,
save_graphs_path
):
self
.
_context_handle
.
set_save_graphs_path
(
save_graphs_path
)
self
.
_context_handle
.
set_save_graphs_path
(
_make_directory
(
save_graphs_path
)
)
@
property
def
device_target
(
self
):
...
...
tests/ut/cpp/operator/composite_test.cc
浏览文件 @
7e23a1a4
...
...
@@ -128,8 +128,8 @@ TEST_F(TestComposite, test_TupleSlice_arg_one_number) {
trace
::
ClearTraceStack
();
engine_
->
Run
(
tupleSliceGraphPtr
,
args_spec_list
);
FAIL
()
<<
"Excepted exception :Args type is wrong"
;
}
catch
(
std
::
runtim
e_error
const
&
err
)
{
ASSERT_TRUE
(
std
::
string
(
err
.
what
()).
find
(
"TypeError"
)
!=
std
::
string
::
npos
);
}
catch
(
pybind11
::
typ
e_error
const
&
err
)
{
ASSERT_TRUE
(
true
);
}
catch
(...)
{
FAIL
()
<<
"Excepted exception :Args type is wrong"
;
}
...
...
tests/ut/python/pynative_mode/test_backend.py
浏览文件 @
7e23a1a4
...
...
@@ -13,6 +13,7 @@
# limitations under the License.
# ============================================================================
""" test_backend """
import
os
import
numpy
as
np
import
pytest
from
mindspore.ops
import
operations
as
P
...
...
@@ -51,10 +52,11 @@ def test_vm_backend():
def
test_vm_set_context
():
""" test_vm_set_context """
context
.
set_context
(
save_graphs
=
True
,
save_graphs_path
=
"
/home/mindspore
"
,
mode
=
context
.
GRAPH_MODE
)
context
.
set_context
(
save_graphs
=
True
,
save_graphs_path
=
"
mindspore_ir_path
"
,
mode
=
context
.
GRAPH_MODE
)
assert
context
.
get_context
(
"save_graphs"
)
assert
context
.
get_context
(
"mode"
)
==
context
.
GRAPH_MODE
assert
context
.
get_context
(
"save_graphs_path"
)
==
"/home/mindspore"
assert
os
.
path
.
exists
(
"mindspore_ir_path"
)
assert
context
.
get_context
(
"save_graphs_path"
).
find
(
"mindspore_ir_path"
)
>
0
context
.
set_context
(
mode
=
context
.
PYNATIVE_MODE
)
@
args_type_check
(
v_str
=
str
,
v_int
=
int
,
v_tuple
=
tuple
)
...
...
@@ -74,3 +76,15 @@ def test_args_type_check():
with
pytest
.
raises
(
TypeError
):
check_input
(
"name"
,
100
,
"age"
)
check_input
(
"name"
,
100
,
(
10
,
10
))
def
teardown_module
():
dirs
=
[
'mindspore_ir_path'
]
for
item
in
dirs
:
item_name
=
'./'
+
item
if
not
os
.
path
.
exists
(
item_name
):
continue
if
os
.
path
.
isdir
(
item_name
):
os
.
rmdir
(
item_name
)
elif
os
.
path
.
isfile
(
item_name
):
os
.
remove
(
item_name
)
tests/ut/python/pynative_mode/test_context.py
浏览文件 @
7e23a1a4
...
...
@@ -13,6 +13,7 @@
# limitations under the License.
# ============================================================================
""" test_context """
import
os
import
pytest
from
mindspore
import
context
# pylint: disable=W0212
...
...
@@ -74,11 +75,12 @@ def test_dump_target():
def
test_set_context
():
""" test_set_context """
context
.
set_context
(
mode
=
context
.
GRAPH_MODE
,
device_target
=
"Ascend"
,
device_id
=
0
,
save_graphs
=
True
,
save_graphs_path
=
"
/mindspore
"
)
device_id
=
0
,
save_graphs
=
True
,
save_graphs_path
=
"
mindspore_ir_path
"
)
assert
context
.
get_context
(
"device_id"
)
==
0
assert
context
.
get_context
(
"device_target"
)
==
"Ascend"
assert
context
.
get_context
(
"save_graphs"
)
assert
context
.
get_context
(
"save_graphs_path"
)
==
"/mindspore"
assert
os
.
path
.
exists
(
"mindspore_ir_path"
)
assert
context
.
get_context
(
"save_graphs_path"
).
find
(
"mindspore_ir_path"
)
>
0
assert
context
.
get_context
(
"mode"
)
==
context
.
GRAPH_MODE
context
.
set_context
(
mode
=
context
.
PYNATIVE_MODE
)
...
...
@@ -87,3 +89,16 @@ def test_set_context():
with
pytest
.
raises
(
ValueError
):
context
.
set_context
(
modex
=
"ge"
)
def
teardown_module
():
dirs
=
[
'mindspore_ir_path'
]
for
item
in
dirs
:
item_name
=
'./'
+
item
if
not
os
.
path
.
exists
(
item_name
):
continue
if
os
.
path
.
isdir
(
item_name
):
os
.
rmdir
(
item_name
)
elif
os
.
path
.
isfile
(
item_name
):
os
.
remove
(
item_name
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录