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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright 2022 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 pytest
  15. import numpy as np
  16. from mindspore import Tensor, context
  17. from mindspore.nn import Cell
  18. from mindspore.ops import operations as P
  19. from parallel.utils.utils import compile_net
  20. x_ = (Tensor(np.random.normal(size=[8, 8, 8])),
  21. Tensor(np.random.normal(size=[8, 8, 8])),
  22. Tensor(np.random.normal(size=[8, 8, 8])))
  23. class Net(Cell):
  24. def __init__(self, strategy=None):
  25. super(Net, self).__init__()
  26. self.addn = P.AddN().shard(strategy)
  27. def construct(self, x):
  28. return self.addn(x)
  29. def test_addn_auto_parallel():
  30. """
  31. Feature: test AddN auto parallel
  32. Description: auto parallel
  33. Expectation: compile success
  34. """
  35. context.set_auto_parallel_context(parallel_mode="auto_parallel", device_num=8, global_rank=0)
  36. net = Net()
  37. compile_net(net, x_)
  38. def test_addn_model_parallel():
  39. """
  40. Feature: test AddN model parallel
  41. Description: model parallel
  42. Expectation: compile success
  43. """
  44. context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0)
  45. strategy = ((2, 2, 2), (2, 2, 2), (2, 2, 2))
  46. net = Net(strategy)
  47. compile_net(net, x_)
  48. def test_addn_strategy_error():
  49. """
  50. Feature: test invalid strategy for AddN
  51. Description: illegal strategy
  52. Expectation: raise RuntimeError
  53. """
  54. context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0)
  55. strategy = ((2, 2, 2), (2, 2, 2), (2, 2, 1))
  56. net = Net(strategy)
  57. with pytest.raises(RuntimeError):
  58. compile_net(net, x_)