forked from mindspore-Ecosystem/mindspore
use temporary dir as dump dir
This commit is contained in:
parent
c35d32d45a
commit
b4c82be639
|
@ -15,6 +15,7 @@
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import glob
|
import glob
|
||||||
|
@ -46,12 +47,11 @@ x = np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32)
|
||||||
y = np.array([[7, 8, 9], [10, 11, 12]]).astype(np.float32)
|
y = np.array([[7, 8, 9], [10, 11, 12]]).astype(np.float32)
|
||||||
|
|
||||||
|
|
||||||
def change_current_dump_json(file_name, dump_path):
|
def change_current_dump_json(file_name, dump_path, dump_config_path):
|
||||||
with open(file_name, 'r+') as f:
|
with open(file_name, 'r+') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
data["common_dump_settings"]["path"] = dump_path
|
data["common_dump_settings"]["path"] = dump_path
|
||||||
with open(file_name, 'w') as f:
|
with open(dump_config_path, 'w') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,52 +62,49 @@ def change_current_dump_json(file_name, dump_path):
|
||||||
def test_async_dump():
|
def test_async_dump():
|
||||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
dump_path = pwd + "/async_dump"
|
with tempfile.TemporaryDirectory(dir=pwd) as tmp_dir:
|
||||||
change_current_dump_json('async_dump.json', dump_path)
|
dump_path = os.path.join(tmp_dir, 'async_dump')
|
||||||
os.environ['MINDSPORE_DUMP_CONFIG'] = pwd + "/async_dump.json"
|
dump_config_path = os.path.join(tmp_dir, 'async_dump.json')
|
||||||
dump_file_path = dump_path + '/rank_0/Net/0/0/'
|
change_current_dump_json('async_dump.json', dump_path, dump_config_path)
|
||||||
if os.path.isdir(dump_path):
|
os.environ['MINDSPORE_DUMP_CONFIG'] = dump_config_path
|
||||||
shutil.rmtree(dump_path)
|
dump_file_path = os.path.join(dump_path, 'rank_0', 'Net', '0', '0')
|
||||||
add = Net()
|
if os.path.isdir(dump_path):
|
||||||
add(Tensor(x), Tensor(y))
|
shutil.rmtree(dump_path)
|
||||||
time.sleep(5)
|
add = Net()
|
||||||
assert len(os.listdir(dump_file_path)) == 1
|
add(Tensor(x), Tensor(y))
|
||||||
|
time.sleep(5)
|
||||||
# Delete generated dump data
|
assert len(os.listdir(dump_file_path)) == 1
|
||||||
os.system("rm -rf {}".format(dump_path))
|
|
||||||
|
|
||||||
|
|
||||||
def run_e2e_dump():
|
def run_e2e_dump():
|
||||||
if sys.platform != 'linux':
|
if sys.platform != 'linux':
|
||||||
return
|
return
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
dump_path = pwd + '/e2e_dump'
|
with tempfile.TemporaryDirectory(dir=pwd) as tmp_dir:
|
||||||
change_current_dump_json('e2e_dump.json', dump_path)
|
dump_path = os.path.join(tmp_dir, 'e2e_dump')
|
||||||
os.environ['MINDSPORE_DUMP_CONFIG'] = pwd + '/e2e_dump.json'
|
dump_config_path = os.path.join(tmp_dir, 'e2e_dump.json')
|
||||||
dump_file_path = dump_path + '/rank_0/Net/0/0/'
|
change_current_dump_json('e2e_dump.json', dump_path, dump_config_path)
|
||||||
if os.path.isdir(dump_path):
|
os.environ['MINDSPORE_DUMP_CONFIG'] = dump_config_path
|
||||||
shutil.rmtree(dump_path)
|
dump_file_path = os.path.join(dump_path, 'rank_0', 'Net', '0', '0')
|
||||||
add = Net()
|
if os.path.isdir(dump_path):
|
||||||
add(Tensor(x), Tensor(y))
|
shutil.rmtree(dump_path)
|
||||||
time.sleep(5)
|
add = Net()
|
||||||
if context.get_context("device_target") == "Ascend":
|
add(Tensor(x), Tensor(y))
|
||||||
assert len(os.listdir(dump_file_path)) == 5
|
if context.get_context("device_target") == "Ascend":
|
||||||
output_name = "Add.Add-op1.0.0.*.output.0.DefaultFormat.npy"
|
assert len(os.listdir(dump_file_path)) == 5
|
||||||
elif context.get_context("device_target") == "CPU":
|
output_name = "Add.Add-op1.0.0.*.output.0.DefaultFormat.npy"
|
||||||
assert len(os.listdir(dump_file_path)) == 5
|
elif context.get_context("device_target") == "CPU":
|
||||||
output_name = "Add.Add-op3.0.0.*.output.0.DefaultFormat.npy"
|
assert len(os.listdir(dump_file_path)) == 5
|
||||||
else:
|
output_name = "Add.Add-op3.0.0.*.output.0.DefaultFormat.npy"
|
||||||
assert len(os.listdir(dump_file_path)) == 3
|
else:
|
||||||
output_name = "Add.Add-op3.0.0.*.output.0.DefaultFormat.npy"
|
assert len(os.listdir(dump_file_path)) == 3
|
||||||
output_path = glob.glob(dump_file_path + output_name)[0]
|
output_name = "Add.Add-op3.0.0.*.output.0.DefaultFormat.npy"
|
||||||
real_path = os.path.realpath(output_path)
|
output_path = glob.glob(os.path.join(dump_file_path, output_name))[0]
|
||||||
output = np.load(real_path)
|
real_path = os.path.realpath(output_path)
|
||||||
expect = np.array([[8, 10, 12], [14, 16, 18]], np.float32)
|
output = np.load(real_path)
|
||||||
assert output.dtype == expect.dtype
|
expect = np.array([[8, 10, 12], [14, 16, 18]], np.float32)
|
||||||
assert np.array_equal(output, expect)
|
assert output.dtype == expect.dtype
|
||||||
|
assert np.array_equal(output, expect)
|
||||||
# Delete generated dump data
|
|
||||||
os.system("rm -rf {}".format(dump_path))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.level0
|
@pytest.mark.level0
|
||||||
|
@ -257,16 +254,15 @@ def test_dump_with_diagnostic_path():
|
||||||
"""
|
"""
|
||||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
change_current_dump_json('e2e_dump.json', '')
|
with tempfile.TemporaryDirectory(dir=pwd) as tmp_dir:
|
||||||
os.environ['MINDSPORE_DUMP_CONFIG'] = pwd + "/e2e_dump.json"
|
dump_config_path = os.path.join(tmp_dir, 'e2e_dump.json')
|
||||||
diagnose_path = pwd + "/e2e_dump"
|
change_current_dump_json('e2e_dump.json', '', dump_config_path)
|
||||||
os.environ['MS_DIAGNOSTIC_DATA_PATH'] = diagnose_path
|
os.environ['MINDSPORE_DUMP_CONFIG'] = dump_config_path
|
||||||
dump_file_path = diagnose_path + '/debug_dump/rank_0/Net/0/0/'
|
diagnose_path = os.path.join(tmp_dir, 'e2e_dump')
|
||||||
if os.path.isdir(diagnose_path):
|
os.environ['MS_DIAGNOSTIC_DATA_PATH'] = diagnose_path
|
||||||
shutil.rmtree(diagnose_path)
|
dump_file_path = os.path.join(diagnose_path, 'debug_dump', 'rank_0', 'Net', '0', '0')
|
||||||
add = Net()
|
if os.path.isdir(diagnose_path):
|
||||||
add(Tensor(x), Tensor(y))
|
shutil.rmtree(diagnose_path)
|
||||||
assert len(os.listdir(dump_file_path)) == 5
|
add = Net()
|
||||||
|
add(Tensor(x), Tensor(y))
|
||||||
# Delete generated dump data
|
assert len(os.listdir(dump_file_path)) == 5
|
||||||
os.system("rm -rf {}".format(diagnose_path))
|
|
||||||
|
|
Loading…
Reference in New Issue