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_combined_tensor.py 2.2 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 mindspore import Tensor
  15. from mindspore.parallel._tensor import _reshape_param_data
  16. def test_reshape_param_data():
  17. expected_tensor = Tensor([[1, 2, 3, 4], [5, 6, 7, 8]])
  18. dev_mat = [2, 2]
  19. tensor_map = [0, 1]
  20. input_tensor = Tensor([[1, 2], [5, 6], [3, 4], [7, 8]])
  21. tensor = _reshape_param_data(input_tensor, dev_mat, tensor_map)
  22. if expected_tensor.__str__() != tensor.__str__():
  23. raise AssertionError
  24. tensor_map = [1, -1]
  25. input_tensor = Tensor([[1, 2, 3, 4], [1, 2, 3, 4], [5, 6, 7, 8], [5, 6, 7, 8]])
  26. tensor = _reshape_param_data(input_tensor, dev_mat, tensor_map)
  27. if expected_tensor.__str__() != tensor.__str__():
  28. raise AssertionError
  29. expected_tensor = Tensor([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], \
  30. [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]])
  31. input_tensor = Tensor([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], \
  32. [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], \
  33. [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], \
  34. [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], \
  35. [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], \
  36. [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], \
  37. [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], \
  38. [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]])
  39. dev_mat = [4]
  40. tensor_map = [-1, -1, -1, -1]
  41. tensor = _reshape_param_data(input_tensor, dev_mat, tensor_map)
  42. if expected_tensor.__str__() != tensor.__str__():
  43. raise AssertionError
  44. if __name__ == '__main__':
  45. test_reshape_param_data()