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_fuse_basic.py 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. # ============================================================================
  15. import logging
  16. import numpy as np
  17. import mindspore.context as context
  18. import mindspore.ops.composite as C
  19. from mindspore import Tensor
  20. from mindspore.nn import Cell
  21. from mindspore.ops import operations as P
  22. from mindspore.nn.composite_ops import ReLU
  23. log = logging.getLogger("ME")
  24. log.setLevel(level=logging.DEBUG)
  25. context.set_context(mode=context.GRAPH_MODE, save_graphs=True, device_target="Ascend")
  26. class NetBasicFuse1(Cell):
  27. def __init__(self):
  28. super(NetBasicFuse1, self).__init__()
  29. def construct(self, x):
  30. mul = P.Mul()(x, 2.0)
  31. add = mul + 1.0
  32. reduce = P.ReduceSum()(add, (0, ))
  33. return reduce
  34. def test_basic_fuse1():
  35. x = np.random.normal(0, 1, [2, 3]).astype(np.float32)
  36. net = NetBasicFuse1()
  37. result = net(Tensor(x))
  38. print("================result=======================")
  39. print("x: {}".format(x))
  40. print("result: {}".format(result))
  41. print("=======================================")
  42. test_basic_fuse1()