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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "utils/callbacks.h"
  20. #include "common/common_test.h"
  21. #include "pipeline/jit/pipeline.h"
  22. #include "pipeline/jit/parse/python_adapter.h"
  23. #include "transform/graph_ir/df_graph_manager.h"
  24. #include "debug/draw.h"
  25. #ifdef ENABLE_GE
  26. #include "utils/callbacks_ge.h"
  27. #endif
  28. namespace mindspore {
  29. namespace python_adapter = mindspore::parse::python_adapter;
  30. class TestCallback : public UT::Common {
  31. public:
  32. TestCallback() {}
  33. };
  34. /*
  35. * # ut and python static info not share
  36. TEST_F(TestCallback, test_get_anf_tensor_shape) {
  37. py::object obj = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_class", "test_get_object_graph");
  38. FuncGraphPtr func_graph = pipeline::ExecutorPy::GetInstance()->GetFuncGraphPy(obj);
  39. transform::DfGraphManager::GetInstance().SetAnfGraph(func_graph);
  40. std::shared_ptr<std::vector<int64_t>> param_shape_ptr = std::make_shared<std::vector<int64_t>>();
  41. bool get_shape = callbacks::GetParameterShape(func_graph, "weight", param_shape_ptr);
  42. ASSERT_TRUE(get_shape == true);
  43. }
  44. TEST_F(TestCallback, test_checkpoint_save_op) {
  45. py::object obj = python_adapter::CallPyFn("gtest_input.pipeline.parse.parse_class", "test_get_object_graph");
  46. FuncGraphPtr func_graph = pipeline::ExecutorPy::GetInstance()->GetFuncGraphPy(obj);
  47. transform::DfGraphManager::GetInstance().SetAnfGraph(func_graph);
  48. #define DTYPE float
  49. ge::DataType dt = ge::DataType::DT_FLOAT;
  50. std::vector<float> data1 = {1.1, 2.2, 3.3, 4.4, 6.6, 7.7, 8.8, 9.9};
  51. auto data = data1;
  52. ge::Shape shape({2, 2, 2, 1});
  53. ge::Format format = ge::Format::FORMAT_NCHW;
  54. ge::TensorDesc desc(shape, format, dt);
  55. transform::GeTensorPtr ge_tensor_ptr =
  56. std::make_shared<GeTensor>(desc, reinterpret_cast<uint8_t *>(data.data()), data.size() * sizeof(DTYPE));
  57. std::map<std::string, GeTensor> param_map;
  58. param_map.insert(std::pair<std::string, GeTensor>("weight", *ge_tensor_ptr));
  59. param_map.insert(std::pair<std::string, GeTensor>("network.weight", *ge_tensor_ptr));
  60. int ret = callbacks::CheckpointSaveCallback(0, param_map);
  61. MS_LOG(INFO) << "ret=" << ret;
  62. ASSERT_EQ(ret, 0);
  63. }
  64. */
  65. /*
  66. TEST_F(TestCallback, test_summary_save_op) {
  67. py::object obj = python_adapter::CallPyFn(
  68. "gtest_input.pipeline.parse.parse_class", "test_get_object_graph");
  69. FuncGraphPtr func_graph = obj.cast<FuncGraphPtr>();
  70. transform::DfGraphManager::GetInstance().SetAnfGraph(func_graph);
  71. #define DTYPE float
  72. ge::DataType dt = ge::DataType::DT_FLOAT;
  73. float data1 = 1.1;
  74. float data2 = 2.1;
  75. ge::Shape shape({1, 1, 1, 1});
  76. ge::Format format = ge::Format::FORMAT_NCHW;
  77. ge::TensorDesc desc(shape, format, dt);
  78. GeTensorPtr ge_tensor_ptr1 = std::make_shared<GeTensor>(desc,
  79. reinterpret_cast<uint8_t *>(&data1),
  80. sizeof(DTYPE));
  81. GeTensorPtr ge_tensor_ptr2 = std::make_shared<GeTensor>(desc,
  82. reinterpret_cast<uint8_t *>(&data2),
  83. sizeof(DTYPE));
  84. std::map<std::string, GeTensor> param_map;
  85. param_map.insert(std::pair<std::string, GeTensor>("x1[:Scalar]", *ge_tensor_ptr1));
  86. param_map.insert(std::pair<std::string, GeTensor>("x2[:Scalar]", *ge_tensor_ptr2));
  87. int ret = callbacks::SummarySaveCallback(0, param_map);
  88. MS_LOG(INFO) << "ret=" << ret;
  89. ASSERT_TRUE(ret == 0);
  90. }
  91. */
  92. } // namespace mindspore