Skip to content

artifact_serializer

serialize_artifact(value_node_id, execution_id, reference, name, storage_backend=None, **kwargs)

Serialize artifact using various backend.

Currently, most objects are using lineapy as the backend for serialization. The only exception is MLflow-supported model flavors. In order to use MLflow for ml model serialization, following conditions need to be satisfied:

  1. The artifact(ML model) should be a MLflow-supported flavor
  2. MLflow is installed
  3. storage_backend should be mlflow or storage_backend is None and options.get("default_ARTIFACT_STORAGE_BACKEND")=='mlflow'

Parameters:

Name Type Description Default
value_node_id LineaID

Value node id in Linea Graph

required
execution_id LineaID

Execution id

required
reference Any

Same as reference in lineapy.save()

required
name str

Same as reference in lineapy.save()

required
storage_backend Optional[ARTIFACT_STORAGE_BACKEND]

Same as reference in lineapy.save()

None
**kwargs

Same as reference in lineapy.save()

{}

Returns:

Type Description
Dict

Dictionary with following key-value pair:

  • backend: storage backend used to save the artifact
  • metadata: metadata of the storage backed
Source code in lineapy/api/artifact_serializer.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def serialize_artifact(
    value_node_id: LineaID,
    execution_id: LineaID,
    reference: Any,
    name: str,
    storage_backend: Optional[ARTIFACT_STORAGE_BACKEND] = None,
    **kwargs,
) -> Dict[str, Any]:
    """
    Serialize artifact using various backend.

    Currently, most objects are using lineapy as the backend for serialization.
    The only exception is MLflow-supported model flavors. In order to use
    MLflow for ml model serialization, following conditions need to be
    satisfied:

    1. The artifact(ML model) should be a MLflow-supported flavor
    2. MLflow is installed
    3. `storage_backend` should be `mlflow` or `storage_backend` is `None` and
    `options.get("default_ARTIFACT_STORAGE_BACKEND")=='mlflow'`

    Parameters
    ----------
    value_node_id: LineaID
        Value node id in Linea Graph
    execution_id: LineaID
        Execution id
    reference: Union[object, ExternalState]
        Same as reference in [`lineapy.save()`][lineapy.api.api.save]
    name: str
        Same as reference in [`lineapy.save()`][lineapy.api.api.save]
    storage_backend: Optional[ARTIFACT_STORAGE_BACKEND]
        Same as reference in [`lineapy.save()`][lineapy.api.api.save]
    **kwargs:
        Same as reference in [`lineapy.save()`][lineapy.api.api.save]

    Returns
    -------
    Dict
        Dictionary with following key-value pair:

        - backend: storage backend used to save the artifact
        - metadata: metadata of the storage backed
    """
    if _able_to_use_mlflow(storage_backend):
        model_info = try_write_to_mlflow(reference, name, **kwargs)
        if model_info is not None:
            return {
                "backend": "mlflow",
                "metadata": model_info,
            }

    pickle_name = _pickle_name(value_node_id, execution_id)
    _try_write_to_pickle(reference, pickle_name)
    return {
        "backend": "lineapy",
        "metadata": {"pickle_name": str(pickle_name)},
    }

Was this helpful?

Help us improve docs with your feedback!