|
| 1 | +Associate a Model |
| 2 | +_________________ |
| 3 | + |
| 4 | +Model version sets are a collection of models. After a model is associated with a model version set, the model can't be associated with a different model version set. Further, the model can't be disassociated with the model version set. |
| 5 | + |
| 6 | +When a model is associated with a model version set, a version label can be assigned to the set. This version is different than the model version that is maintained by the model version set. |
| 7 | + |
| 8 | +There are a number of ways to associate a model with a model version set. Which approach you use depends on the workflow. |
| 9 | + |
| 10 | +ModelVersionSet Object |
| 11 | +---------------------- |
| 12 | + |
| 13 | +For a model not associated with a model version set, use the ``.model_add()`` method on a ``ModelVersionSet`` object to associate the model with the model version set. The ``.model_add()`` requires that you provide the model OCID and optionally a version label. |
| 14 | + |
| 15 | +.. code-block:: python3 |
| 16 | +
|
| 17 | + mvs = ModelVersionSet.from_id(id="<model_version_set_id>") |
| 18 | + mvs.model_add(<your_model_id>, version_label="Version 1") |
| 19 | +
|
| 20 | +Model Serialization |
| 21 | +------------------- |
| 22 | + |
| 23 | +The :ref:`Model Serialization` classes allow a model to be associated with a model version set at the time that it is saved to the model catalog. You do this with the ``model_version_set`` parameter in the ``.save()`` method. In addition, you can add the model's version label with the ``version_label`` parameter. |
| 24 | + |
| 25 | +The ``model_version_set`` parameter accepts a model version set's OCID or name. The parameter also accepts a ``ModelVersionSet`` object. |
| 26 | + |
| 27 | +In the following, the ``model`` variable is a :ref:`Model Serialization` object that is to be saved to the model catalog, and at the same time associated with a model version set. |
| 28 | + |
| 29 | +.. code-block:: python3 |
| 30 | +
|
| 31 | + model.save( |
| 32 | + display_name='Model attached to a model version set', |
| 33 | + version_label = "Version 1", |
| 34 | + model_version_set="<model_version_set_id>" |
| 35 | + ) |
| 36 | +
|
| 37 | +
|
| 38 | +Context Manager |
| 39 | +--------------- |
| 40 | + |
| 41 | +To associate several models with a model version set, use a context manager. The ``ads.model.experiment()`` method requires a ``name`` parameter. If the model catalog has a matching model version set name, the model catalog uses that model version set. If the parameter ``create_if_not_exists`` is ``True``, the ``experiment()`` method attempts to match the model version set name with name in the model catalog. If the name does not exist, the method creates a new model version set. |
| 42 | + |
| 43 | +Within the context manager, you can save multiple :ref:`Model Serialization` models without specifying the ``model_version_set`` parameter because it's taken from the model context manager. The following example assumes that ``model_1``, ``model_2``, and ``model_3`` are :ref:`Model Serialization` objects. If the model version set doesn't exist in the model catalog, the example creates a model version set named ``my_model_version_set``. If the model version set exists in the model catalog, the models are saved to that model version set. |
| 44 | + |
| 45 | +.. code-block:: python3 |
| 46 | +
|
| 47 | + with ads.model.experiment(name="my_model_version_set", create_if_not_exists=True): |
| 48 | + # experiment 1 |
| 49 | + model_1.save( |
| 50 | + display_name='Generic Model Experiment 1', |
| 51 | + version_label = "Experiment 1" |
| 52 | + ) |
| 53 | +
|
| 54 | + # experiment 2 |
| 55 | + model_2.save( |
| 56 | + display_name='Generic Model Experiment 2', |
| 57 | + version_label = "Experiment 2" |
| 58 | + ) |
| 59 | +
|
| 60 | + # experiment 3 |
| 61 | + model_3.save( |
| 62 | + display_name='Generic Model Experiment 3', |
| 63 | + version_label = "Experiment 3" |
| 64 | + ) |
| 65 | +
|
| 66 | +
|
0 commit comments