You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dump_test_utils.py 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """
  16. Utils for testing offline debugger.
  17. """
  18. import os
  19. import tempfile
  20. import numpy as np
  21. def build_dump_structure(path, tensor_name_list, tensor_list, net_name, tensor_info_list):
  22. """Build dump file structure from tensor_list."""
  23. temp_dir = tempfile.mkdtemp(prefix=net_name, dir=path)
  24. for tensor_name, tensor, tensor_info in zip(tensor_name_list, tensor_list, tensor_info_list):
  25. slot = str(tensor_info.slot)
  26. iteration = str(tensor_info.iteration)
  27. rank_id = str(tensor_info.rank_id)
  28. root_graph_id = str(tensor_info.root_graph_id)
  29. is_output = str(tensor_info.is_output)
  30. path = os.path.join(temp_dir, "rank_" + rank_id, net_name, root_graph_id, iteration)
  31. os.makedirs(path, exist_ok=True)
  32. if is_output == "True":
  33. file = tempfile.mkstemp(prefix=tensor_name, suffix=".output." + slot +
  34. ".DefaultFormat.npy", dir=path)
  35. else:
  36. file = tempfile.mkstemp(prefix=tensor_name, suffix=".input." + slot +
  37. ".DefaultFormat.npy", dir=path)
  38. full_path = file[1]
  39. np.save(full_path, tensor)
  40. return temp_dir