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_squeeze_info.py 2.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright 2020 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. import numpy as np
  15. import mindspore as ms
  16. from mindspore import context, Tensor
  17. from mindspore.common.api import _executor
  18. from mindspore.nn import Cell
  19. from mindspore.ops import operations as P
  20. class Net(Cell):
  21. def __init__(self, strategy1=None, strategy2=None, axis=()):
  22. super().__init__()
  23. self.squeeze = P.Squeeze(axis=axis).set_strategy(strategy1)
  24. self.mul = P.Mul().set_strategy(strategy2)
  25. def construct(self, x, b):
  26. out = self.squeeze(x)
  27. out = self.mul(out, b)
  28. return out
  29. _x = Tensor(np.ones([64, 1, 32, 1]), dtype=ms.float32)
  30. _b = Tensor(np.ones([64, 32]), dtype=ms.float32)
  31. def compile_net(net):
  32. net.set_auto_parallel()
  33. _executor.compile(net, _x, _b)
  34. context.reset_auto_parallel_context()
  35. def test_squeeze_data_parallel():
  36. context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=16, global_rank=0)
  37. strategy1 = ((16, 1, 1, 1),)
  38. strategy2 = ((16, 1), (16, 1))
  39. net = Net(strategy1, strategy2)
  40. compile_net(net)
  41. def test_squeeze_model_parallel():
  42. context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=16, global_rank=0)
  43. strategy1 = ((1, 1, 16, 1),)
  44. strategy2 = ((1, 16), (1, 16))
  45. net = Net(strategy1, strategy2)
  46. compile_net(net)
  47. def test_squeeze_specified_axis():
  48. context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=16, global_rank=0)
  49. strategy1 = ((4, 1, 4, 1),)
  50. strategy2 = ((8, 2), (8, 2))
  51. net = Net(strategy1, strategy2, (1, 3))
  52. compile_net(net)
  53. def test_squeeze_auto_parallel():
  54. context.set_auto_parallel_context(parallel_mode="auto_parallel", device_num=16, global_rank=0)
  55. net = Net()
  56. compile_net(net)
  57. def test_squeeze_repeat_calc():
  58. context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=16, global_rank=0)
  59. strategy1 = ((1, 1, 8, 1),)
  60. strategy2 = ((2, 8), (2, 8))
  61. net = Net(strategy1, strategy2)
  62. compile_net(net)