model_storage_base.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  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. from abc import ABC, abstractmethod
  17. from contextlib import AbstractContextManager
  18. class ModelStorageBase(ABC):
  19. @abstractmethod
  20. def exists(self, model_id: str, model_version: str, store_address: dict):
  21. pass
  22. @abstractmethod
  23. def store(self, model_id: str, model_version: str, store_address: dict, force_update: bool = False):
  24. """
  25. Store the model from local cache to a reliable system
  26. :param model_id:
  27. :param model_version:
  28. :param store_address:
  29. :return:
  30. """
  31. pass
  32. @abstractmethod
  33. def restore(self, model_id: str, model_version: str, store_address: dict, force_update: bool = False, hash_: str = None):
  34. """
  35. Restore model from storage system to local cache
  36. :param model_id:
  37. :param model_version:
  38. :param store_address:
  39. :return:
  40. """
  41. pass
  42. class ComponentStorageBase(AbstractContextManager):
  43. def __exit__(self, *exc):
  44. pass
  45. @abstractmethod
  46. def exists(self, party_model_id, model_version, component_name):
  47. pass
  48. @abstractmethod
  49. def upload(self, party_model_id, model_version, component_name):
  50. pass
  51. @abstractmethod
  52. def download(self, party_model_id, model_version, component_name, hash_=None):
  53. pass
  54. @abstractmethod
  55. def copy(self, party_model_id, model_version, component_name, source_model_version):
  56. pass