Browse Source

[DOC] finish reuse

tags/v0.3.2
bxdd 1 year ago
parent
commit
cfab80d692
2 changed files with 25 additions and 3 deletions
  1. +1
    -1
      docs/components/learnware.rst
  2. +24
    -2
      docs/workflows/reuse.rst

+ 1
- 1
docs/components/learnware.rst View File

@@ -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>`_. - ``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. - ``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, 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,


+ 24
- 2
docs/workflows/reuse.rst View File

@@ -132,5 +132,27 @@ combine ``HeteroMapAlignLearnware`` with the homogeneous reuse methods ``Averagi
reuse_ensemble.fit(val_x, val_y) reuse_ensemble.fit(val_x, val_y)
ensemble_pruning_predict_y = reuse_ensemble.predict(user_data=test_x) 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.

Loading…
Cancel
Save