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.

callback_test.cc 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <map>
  17. #include <string>
  18. #include "pybind11/pybind11.h"
  19. #include "include/common/utils/callbacks.h"
  20. #include "common/common_test.h"
  21. #include "pipeline/jit/pipeline.h"
  22. #include "include/common/utils/python_adapter.h"
  23. #include "include/transform/graph_ir/df_graph_manager.h"
  24. #include "include/common/debug/draw.h"
  25. #ifdef ENABLE_D
  26. #include "include/common/utils/callbacks_ge.h"
  27. #endif
  28. namespace mindspore {
  29. class TestCallback : public UT::Common {
  30. public:
  31. TestCallback() {}
  32. };
  33. /*
  34. * # ut and python static info not share
  35. TEST_F(TestCallback, test_get_anf_tensor_shape) {
  36. py::object obj = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_class", "test_get_object_graph");
  37. FuncGraphPtr func_graph = pipeline::GraphExecutorPy::GetInstance()->GetFuncGraphPy(obj);
  38. transform::DfGraphManager::GetInstance().SetAnfGraph(func_graph);
  39. std::shared_ptr<std::vector<int64_t>> param_shape_ptr = std::make_shared<std::vector<int64_t>>();
  40. bool get_shape = callbacks::GetParameterShape(func_graph, "weight", param_shape_ptr);
  41. ASSERT_TRUE(get_shape == true);
  42. }
  43. TEST_F(TestCallback, test_checkpoint_save_op) {
  44. py::object obj = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_class", "test_get_object_graph");
  45. FuncGraphPtr func_graph = pipeline::GraphExecutorPy::GetInstance()->GetFuncGraphPy(obj);
  46. transform::DfGraphManager::GetInstance().SetAnfGraph(func_graph);
  47. #define DTYPE float
  48. ge::DataType dt = ge::DataType::DT_FLOAT;
  49. std::vector<float> data1 = {1.1, 2.2, 3.3, 4.4, 6.6, 7.7, 8.8, 9.9};
  50. auto data = data1;
  51. ge::Shape shape({2, 2, 2, 1});
  52. ge::Format format = ge::Format::FORMAT_NCHW;
  53. ge::TensorDesc desc(shape, format, dt);
  54. transform::GeTensorPtr ge_tensor_ptr =
  55. std::make_shared<GeTensor>(desc, reinterpret_cast<uint8_t *>(data.data()), data.size() * sizeof(DTYPE));
  56. std::map<std::string, GeTensor> param_map;
  57. param_map.insert(std::pair<std::string, GeTensor>("weight", *ge_tensor_ptr));
  58. param_map.insert(std::pair<std::string, GeTensor>("network.weight", *ge_tensor_ptr));
  59. int ret = callbacks::CheckpointSaveCallback(0, param_map);
  60. MS_LOG(INFO) << "ret=" << ret;
  61. ASSERT_EQ(ret, 0);
  62. }
  63. */
  64. /*
  65. TEST_F(TestCallback, test_summary_save_op) {
  66. py::object obj = python_adapter::CallPyFn(
  67. "gtest_input.pipeline.parse.parse_class", "test_get_object_graph");
  68. FuncGraphPtr func_graph = obj.cast<FuncGraphPtr>();
  69. transform::DfGraphManager::GetInstance().SetAnfGraph(func_graph);
  70. #define DTYPE float
  71. ge::DataType dt = ge::DataType::DT_FLOAT;
  72. float data1 = 1.1;
  73. float data2 = 2.1;
  74. ge::Shape shape({1, 1, 1, 1});
  75. ge::Format format = ge::Format::FORMAT_NCHW;
  76. ge::TensorDesc desc(shape, format, dt);
  77. GeTensorPtr ge_tensor_ptr1 = std::make_shared<GeTensor>(desc,
  78. reinterpret_cast<uint8_t *>(&data1),
  79. sizeof(DTYPE));
  80. GeTensorPtr ge_tensor_ptr2 = std::make_shared<GeTensor>(desc,
  81. reinterpret_cast<uint8_t *>(&data2),
  82. sizeof(DTYPE));
  83. std::map<std::string, GeTensor> param_map;
  84. param_map.insert(std::pair<std::string, GeTensor>("x1[:Scalar]", *ge_tensor_ptr1));
  85. param_map.insert(std::pair<std::string, GeTensor>("x2[:Scalar]", *ge_tensor_ptr2));
  86. int ret = callbacks::SummarySaveCallback(0, param_map);
  87. MS_LOG(INFO) << "ret=" << ret;
  88. ASSERT_TRUE(ret == 0);
  89. }
  90. */
  91. } // namespace mindspore