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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2021 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. """Test dump."""
  16. import pytest
  17. import mindspore.nn as nn
  18. import mindspore.ops as ops
  19. from mindspore import set_dump
  20. def test_set_dump_on_cell():
  21. """
  22. Feature: Python API set_dump.
  23. Description: Use set_dump API on Cell instance.
  24. Expectation: Success.
  25. """
  26. class MyNet(nn.Cell):
  27. def __init__(self):
  28. super(MyNet, self).__init__()
  29. self.conv1 = nn.Conv2d(5, 6, 5, pad_mode='valid')
  30. self.relu1 = nn.ReLU()
  31. def construct(self, x):
  32. x = self.conv1(x)
  33. x = self.relu1(x)
  34. return x
  35. net = MyNet()
  36. set_dump(net.conv1)
  37. def test_set_dump_on_primitive():
  38. """
  39. Feature: Python API set_dump.
  40. Description: Use set_dump API on Primitive instance.
  41. Expectation: Success.
  42. """
  43. op = ops.Add()
  44. set_dump(op)
  45. def test_input_type_check():
  46. """
  47. Feature: Python API set_dump.
  48. Description: Use set_dump API on unsupported instance.
  49. Expectation: Throw ValueError exception.
  50. """
  51. with pytest.raises(ValueError):
  52. set_dump(1)