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.

encode_executor.h 2.3 kB

4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright 2022 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_CCSRC_FL_COMPRESSION_ENCODE_EXECUTOR_H_
  17. #define MINDSPORE_CCSRC_FL_COMPRESSION_ENCODE_EXECUTOR_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include <map>
  22. #include "proto/comm.pb.h"
  23. #include "schema/fl_job_generated.h"
  24. #include "schema/cipher_generated.h"
  25. #include "fl/armour/secure_protocol/key_agreement.h"
  26. #include "ps/ps_context.h"
  27. #include "ps/core/worker_node.h"
  28. #include "ps/core/cluster_metadata.h"
  29. #include "ps/core/communicator/tcp_communicator.h"
  30. #include "fl/server/common.h"
  31. namespace mindspore {
  32. namespace fl {
  33. namespace compression {
  34. // compress type map: schema::CompressType -> num bits
  35. const std::map<schema::CompressType, size_t> kCompressTypeMap = {{schema::CompressType_QUANT, 8}};
  36. struct CompressWeight {
  37. std::vector<int8_t> compress_data;
  38. size_t compress_data_len;
  39. float min_val;
  40. float max_val;
  41. };
  42. class CompressExecutor {
  43. public:
  44. static CompressExecutor &GetInstance() {
  45. static CompressExecutor instance;
  46. return instance;
  47. }
  48. bool EnableCompressWeight(const schema::CompressType compressType);
  49. bool construct_compress_weight(std::map<std::string, CompressWeight> *compressWeights,
  50. std::map<std::string, std::vector<float>> feature_maps,
  51. const schema::CompressType compressType);
  52. bool quant_min_max(std::map<std::string, CompressWeight> *compressWeights,
  53. std::map<std::string, std::vector<float>> feature_maps, size_t num_bits);
  54. schema::CompressType GetCompressType(const flatbuffers::Vector<int8_t> *download_compress_types);
  55. };
  56. } // namespace compression
  57. } // namespace fl
  58. } // namespace mindspore
  59. #endif // MINDSPORE_CCSRC_FL_COMPRESSION_ENCODE_EXECUTOR_H_