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_uniform_real.py 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. from mindspore import context
  15. from mindspore.nn import Cell
  16. from mindspore.ops import operations as P
  17. from parallel.utils.utils import ParallelValidator, compile_net
  18. SEED_ = 1
  19. SEED2_ = 1
  20. class Net(Cell):
  21. def __init__(self, seed, seed2, strategy=None):
  22. super(Net, self).__init__()
  23. self.uniform_real = P.UniformReal(seed, seed2).shard(strategy)
  24. def construct(self, shape):
  25. out = self.uniform_real(shape)
  26. return out
  27. def test_uniform_real_auto_parallel():
  28. """
  29. Features: test UniformReal auto parallel
  30. Description: auto parallel
  31. Expectation: compile success
  32. """
  33. context.set_auto_parallel_context(parallel_mode="auto_parallel", device_num=8, global_rank=0)
  34. net = Net(SEED_, SEED2_)
  35. shape = (4, 4, 4)
  36. compile_net(net, shape)
  37. def test_uniform_real_data_parallel():
  38. """
  39. Features: test UniformReal data parallel
  40. Description: data parallel
  41. Expectation: compile success
  42. """
  43. context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=1)
  44. net = Net(SEED_, SEED2_)
  45. shape = (8, 8)
  46. phase = compile_net(net, shape)
  47. validator = ParallelValidator(net, phase)
  48. assert validator.check_node_attrs("UniformReal-0", {"seed": 2, "seed2": 2})
  49. def test_uniform_real_model_parallel():
  50. """
  51. Features: test UniformReal model parallel
  52. Description: model parallel
  53. Expectation: compile success
  54. """
  55. context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=5)
  56. shape = (8, 8)
  57. strategy = ((2, 2),)
  58. net = Net(SEED_, SEED2_, strategy)
  59. phase = compile_net(net, shape)
  60. validator = ParallelValidator(net, phase)
  61. assert validator.check_node_attrs("UniformReal-0", {"seed": 3, "seed2": 3})