From cfab80d69277564e8a3cac3d098cca80cb58644c Mon Sep 17 00:00:00 2001 From: bxdd Date: Sun, 31 Dec 2023 04:00:41 +0800 Subject: [PATCH] [DOC] finish reuse --- docs/components/learnware.rst | 2 +- docs/workflows/reuse.rst | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docs/components/learnware.rst b/docs/components/learnware.rst index 1b5f000..7ae7c29 100644 --- a/docs/components/learnware.rst +++ b/docs/components/learnware.rst @@ -16,7 +16,7 @@ In our implementation, the class ``Learnware`` has 3 important member variables: - ``model``: The model in the learnware, can be a ``BaseModel`` or a dict including model name and path. When it is a dict, the function ``Learnware.instantiate_model`` is used to transform it to a ``BaseModel``. The function ``Learnware.predict`` use the model to predict for an input ``X``. See more in `COMPONENTS: Model <./model.html>`_. - ``specification``: The specification including the semantic specification and the statistic specification. -Learnware for Hetero Reuse (Feature Align + Hetero Map Learnware) +Learnware for Hetero Reuse ======================================================================= In the Hetero Market(see `COMPONENTS: Hetero Market <./market.html#hetero-market>`_ for details), ``HeteroSearcher`` identifies and recommends helpful learnwares among all learnwares in the market, diff --git a/docs/workflows/reuse.rst b/docs/workflows/reuse.rst index 86d9e50..d9e6eb1 100644 --- a/docs/workflows/reuse.rst +++ b/docs/workflows/reuse.rst @@ -132,5 +132,27 @@ combine ``HeteroMapAlignLearnware`` with the homogeneous reuse methods ``Averagi reuse_ensemble.fit(val_x, val_y) ensemble_pruning_predict_y = reuse_ensemble.predict(user_data=test_x) -Reuse with Container -===================== +Reuse with ``Model Container`` +================================ + +``Learnware`` package provides ``Model Container`` to build executive environment for learnwares according to their runtime dependent files. The learnware's model will be executed in the containers and its env will be installed and uninstalled automatically. + +Run the following codes to try run a learnware with ``Model Container``: + +.. code-block:: python + + from learnware.learnware import Learnware + + with LearnwaresContainer(learnware, mode="conda") as env_container: # Let learnware be instance of Learnware Class, and its input shape is (20, 204) + learnware = env_container.get_learnwares_with_container()[0] + input_array = np.random.random(size=(20, 204)) + print(learnware.predict(input_array)) + +The ``mode`` parameter has two options, each for a specific learnware environment loading method: + +- ``'conda'``: Install a separate conda virtual environment for each learnware (automatically deleted after execution); run each learnware independently within its virtual environment. +- ``'docker'``: Install a conda virtual environment inside a Docker container (automatically destroyed after execution); run each learnware independently within the container (requires Docker privileges). + +.. note:: + It's important to note that the "conda" modes are not secure if there are any malicious learnwares. If the user cannot guarantee the security of the learnware they want to load, it's recommended to use the "docker" mode to load the learnware. +