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.

servable.h 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #ifndef MINDSPORE_SERVING_SERVABLE_H
  17. #define MINDSPORE_SERVING_SERVABLE_H
  18. #include <utility>
  19. #include <unordered_map>
  20. #include <string>
  21. #include <vector>
  22. #include <memory>
  23. #include "common/serving_common.h"
  24. #include "worker/inference/inference.h"
  25. namespace mindspore::serving {
  26. enum PredictPhaseTag {
  27. kPredictPhaseTag_Input,
  28. kPredictPhaseTag_Preproces,
  29. kPredictPhaseTag_Predict,
  30. kPredictPhaseTag_Postprocess,
  31. kPredictPhaseTag_Output,
  32. };
  33. struct MethodSignature {
  34. std::string method_name;
  35. std::vector<std::string> inputs;
  36. std::vector<std::string> outputs;
  37. std::string preprocess_name;
  38. // the output index of the 'predict phase'
  39. std::vector<std::pair<PredictPhaseTag, uint64_t>> preprocess_inputs;
  40. std::string postprocess_name;
  41. std::vector<std::pair<PredictPhaseTag, uint64_t>> postprocess_inputs;
  42. std::string servable_name;
  43. std::vector<std::pair<PredictPhaseTag, uint64_t>> servable_inputs;
  44. std::vector<std::pair<PredictPhaseTag, uint64_t>> returns;
  45. };
  46. struct LoadServableSpec {
  47. std::string servable_directory;
  48. std::string servable_name;
  49. uint64_t version_number = 0;
  50. std::string Repr() const;
  51. };
  52. struct WorkerMethodInfo {
  53. std::string name;
  54. std::vector<std::string> input_names;
  55. };
  56. struct WorkerSpec {
  57. std::string servable_name;
  58. uint64_t version_number = 0;
  59. std::string worker_address;
  60. std::vector<WorkerMethodInfo> methods;
  61. std::string Repr() const;
  62. };
  63. struct RequestSpec {
  64. std::string servable_name;
  65. std::string method_name;
  66. uint64_t version_number = 0; // not specified
  67. std::string Repr() const;
  68. };
  69. struct MS_API ServableMeta {
  70. std::string servable_name;
  71. std::string servable_file; // file name
  72. ModelType model_format; // OM, MindIR
  73. bool with_batch_dim = true; // whether there is batch dim in model's inputs/outputs
  74. size_t inputs_count = 0;
  75. size_t outputs_count = 0;
  76. std::string Repr() const;
  77. void SetModelFormat(const std::string &format);
  78. };
  79. struct ServableSignature {
  80. ServableMeta servable_meta;
  81. std::vector<MethodSignature> methods;
  82. Status Check() const;
  83. bool GetMethodDeclare(const std::string &method_name, MethodSignature *method);
  84. };
  85. class MS_API ServableStorage {
  86. public:
  87. void Register(const ServableSignature &def);
  88. void RegisterMethod(const MethodSignature &method);
  89. bool GetServableDef(const std::string &model_name, ServableSignature *def) const;
  90. void DeclareServable(const ServableMeta &servable);
  91. void RegisterInputOutputInfo(const std::string &servable_name, size_t inputs_count, size_t outputs_count);
  92. std::vector<size_t> GetInputOutputInfo(const std::string &servable_name) const;
  93. static std::shared_ptr<ServableStorage> Instance();
  94. private:
  95. std::unordered_map<std::string, ServableSignature> servable_signatures_map_;
  96. };
  97. } // namespace mindspore::serving
  98. #endif // MINDSPORE_SERVING_SERVABLE_H

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.