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.

test_load_tensor.py 1.4 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright 2019 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. from hccl_test.manage.api import Hccl
  15. from mindspore import Tensor
  16. from mindspore.parallel._tensor import _load_tensor
  17. def test_load_tensor():
  18. hccl = Hccl()
  19. tensor = Tensor([[1, 2, 3], [4, 5, 6]])
  20. dev_mat = [2, 3]
  21. tensor_map = [1, -1]
  22. hccl.rank_id = 5
  23. tensor_slice = _load_tensor(tensor, dev_mat, tensor_map)
  24. expected_tensor = Tensor([[4, 5, 6]])
  25. if expected_tensor.__str__() != tensor_slice.__str__():
  26. raise AssertionError
  27. hccl.rank_id = 2
  28. tensor_slice = _load_tensor(tensor, dev_mat, tensor_map)
  29. expected_tensor = Tensor([[1, 2, 3]])
  30. if expected_tensor.__str__() != tensor_slice.__str__():
  31. raise AssertionError
  32. # set back to the defalt value
  33. hccl.rank_id = 0
  34. if __name__ == '__main__':
  35. test_load_tensor()