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.

model.rst 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. .. _model:
  2. ================================
  3. Model
  4. ================================
  5. A learnware is a well-performed trained model with a specification, where the model is an indispensable component of the learnware.
  6. In this section, we will introduce the model module implemented within ``learnware`` package. We will first introduce the ``BaseModel``, which defines the standard format for models in the ``learnware`` package. Following that, we will introduce the ``ModelContainer``, which implements model deployment in conda virtual environments and Docker containers.
  7. BaseModel
  8. ======================================
  9. The ``BaseModel`` class is a fundamental component of the learnware package which provides standardized interface for model training, prediction and fine-tuning.
  10. This class is created to make it easier for users to submit learnwares to the market.
  11. It helps ensure that submitted models follow a clear set of rules and requirements.
  12. All user models should inherit the ``BaseModel`` class. Here's a more detailed explanation of key components:
  13. - ``input_shape``: Specify the shape of the input features your model expects.
  14. - ``output_shape``: Define the shape of the output predictions generated by your model.
  15. - ``predict``: Implement the predict method to make predictions using your model.
  16. - ``fit`` (optional): Use the fit method for training a model with input data and labels.
  17. - ``finetune`` (optional): Utilize the finetune method for further adjusting pre-existing models sourced from the market.
  18. By adhering to these standards, the compatibility and quality of submitted learnwares in the market are ensured.
  19. ModelContainer
  20. ======================================
  21. The ``ModelContainer`` class is an essential component of the learnware package, designed to facilitate the management, deployment, and execution of machine learning models within a containerized environment.
  22. It inherits from the ``BaseModel`` class and extends its functionality to encapsulate model deployment and execution.
  23. ModelCondaContainer
  24. ---------------------
  25. The ``ModelCondaContainer`` class is an extension of the ``ModelContainer`` class within the learnware package.
  26. Its primary purpose is to enable the management, deployment, and execution of machine learning models in a containerized environment, with a specific focus on using Conda virtual environments.
  27. This class inherits functionality from ``ModelContainer`` while providing additional capabilities related to Conda-based model execution.
  28. Specifically, the ``ModelCondaContainer`` supports the automatic creation of new Conda virtual environments based on the ``requirements.txt`` file (for pip installation) or ``environment.yaml`` file (for Conda installation) included within the learnware itself.
  29. It also installs the environment dependencies of the learnware, enabling it to run.
  30. ModelDockerContainer
  31. ---------------------
  32. The ``ModelDockerContainer`` class is a specialized extension of the ``ModelContainer`` class within the learnware package.
  33. It is designed to manage, deploy, and execute machine learning models within a containerized environment, specifically using Docker containers.
  34. This class inherits functionality from ``ModelContainer`` and enhances it with features related to Docker-based model execution.
  35. Compared to ``ModelCondaContainer``, ``ModelDockerContainer`` confines the model's execution within a Docker container.
  36. It installs the learnware's virtual environment inside the Docker container, isolating the learnware's execution from the host machine, thus enhancing the security of the learnware.
  37. Similar to the ``ModelCondaContainer`` class, the ``ModelDockerContainer`` class also supports both types of environment dependency files for learnware: ``requirements.txt`` for pip-based installation and ``environment.yaml`` for conda-based installation.
  38. It automates the creation of Docker containers and the installation of learnware's environment dependencies within the container, enabling the learnware to run.