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.1 kB

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