truefoundry 0.5.0rc4__py3-none-any.whl → 0.5.0rc6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of truefoundry might be problematic. Click here for more details.
- truefoundry/ml/autogen/client/__init__.py +0 -4
- truefoundry/ml/autogen/client/api/deprecated_api.py +340 -7
- truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +0 -322
- truefoundry/ml/autogen/client/api_client.py +8 -1
- truefoundry/ml/autogen/client/models/__init__.py +0 -4
- truefoundry/ml/autogen/client/models/add_features_to_model_version_request_dto.py +3 -17
- truefoundry/ml/autogen/client/models/agent.py +1 -1
- truefoundry/ml/autogen/client/models/agent_app.py +1 -1
- truefoundry/ml/autogen/client/models/agent_open_api_tool.py +1 -1
- truefoundry/ml/autogen/client/models/agent_open_api_tool_with_fqn.py +1 -1
- truefoundry/ml/autogen/client/models/agent_with_fqn.py +1 -1
- truefoundry/ml/autogen/client/models/artifact_version_manifest.py +1 -1
- truefoundry/ml/autogen/client/models/assistant_message.py +1 -1
- truefoundry/ml/autogen/client/models/blob_storage_reference.py +1 -1
- truefoundry/ml/autogen/client/models/chat_prompt.py +1 -1
- truefoundry/ml/autogen/client/models/external_artifact_source.py +1 -1
- truefoundry/ml/autogen/client/models/fast_ai_framework.py +1 -1
- truefoundry/ml/autogen/client/models/gluon_framework.py +1 -1
- truefoundry/ml/autogen/client/models/h2_o_framework.py +1 -1
- truefoundry/ml/autogen/client/models/image_content_part.py +1 -1
- truefoundry/ml/autogen/client/models/keras_framework.py +1 -1
- truefoundry/ml/autogen/client/models/light_gbm_framework.py +1 -1
- truefoundry/ml/autogen/client/models/model_version_dto.py +7 -8
- truefoundry/ml/autogen/client/models/model_version_manifest.py +15 -2
- truefoundry/ml/autogen/client/models/onnx_framework.py +1 -1
- truefoundry/ml/autogen/client/models/paddle_framework.py +1 -1
- truefoundry/ml/autogen/client/models/py_torch_framework.py +1 -1
- truefoundry/ml/autogen/client/models/sklearn_framework.py +1 -1
- truefoundry/ml/autogen/client/models/spa_cy_framework.py +1 -1
- truefoundry/ml/autogen/client/models/stats_models_framework.py +1 -1
- truefoundry/ml/autogen/client/models/system_message.py +1 -1
- truefoundry/ml/autogen/client/models/tensor_flow_framework.py +1 -1
- truefoundry/ml/autogen/client/models/text_content_part.py +1 -1
- truefoundry/ml/autogen/client/models/transformers_framework.py +1 -1
- truefoundry/ml/autogen/client/models/true_foundry_artifact_source.py +1 -1
- truefoundry/ml/autogen/client/models/update_model_version_request_dto.py +1 -13
- truefoundry/ml/autogen/client/models/user_message.py +1 -1
- truefoundry/ml/autogen/client/models/xg_boost_framework.py +1 -1
- truefoundry/ml/autogen/client_README.md +4 -8
- truefoundry/ml/autogen/entities/artifacts.py +5 -1
- truefoundry/ml/autogen/models/__init__.py +4 -0
- truefoundry/ml/autogen/models/exceptions.py +30 -0
- truefoundry/ml/autogen/models/schema.py +1547 -0
- truefoundry/ml/autogen/models/signature.py +139 -0
- truefoundry/ml/autogen/models/utils.py +699 -0
- truefoundry/ml/log_types/artifacts/model.py +25 -0
- truefoundry/ml/mlfoundry_api.py +2 -0
- truefoundry/ml/mlfoundry_run.py +2 -0
- {truefoundry-0.5.0rc4.dist-info → truefoundry-0.5.0rc6.dist-info}/METADATA +1 -1
- {truefoundry-0.5.0rc4.dist-info → truefoundry-0.5.0rc6.dist-info}/RECORD +52 -51
- truefoundry/ml/autogen/client/models/feature_dto.py +0 -68
- truefoundry/ml/autogen/client/models/feature_value_type.py +0 -35
- truefoundry/ml/autogen/client/models/model_schema_dto.py +0 -85
- truefoundry/ml/autogen/client/models/prediction_type.py +0 -34
- {truefoundry-0.5.0rc4.dist-info → truefoundry-0.5.0rc6.dist-info}/WHEEL +0 -0
- {truefoundry-0.5.0rc4.dist-info → truefoundry-0.5.0rc6.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
from dataclasses import dataclass, is_dataclass
|
|
2
|
+
from typing import Any, Dict, Optional, Union
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
from .schema import ParamSchema, Schema, convert_dataclass_to_schema
|
|
8
|
+
from .utils import infer_param_schema, infer_schema
|
|
9
|
+
|
|
10
|
+
MlflowInferableDataset = Union[pd.DataFrame, np.ndarray, Dict[str, np.ndarray]]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ModelSignature:
|
|
14
|
+
"""
|
|
15
|
+
ModelSignature specifies schema of model's inputs, outputs and params.
|
|
16
|
+
|
|
17
|
+
ModelSignature can be :py:func:`inferred <mlflow.models.infer_signature>` from training
|
|
18
|
+
dataset, model predictions using and params for inference, or constructed by hand by
|
|
19
|
+
passing an input and output :py:class:`Schema <mlflow.types.Schema>`, and params
|
|
20
|
+
:py:class:`ParamSchema <mlflow.types.ParamSchema>`.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
inputs: Union[Schema, dataclass] = None,
|
|
26
|
+
outputs: Union[Schema, dataclass] = None,
|
|
27
|
+
params: ParamSchema = None,
|
|
28
|
+
):
|
|
29
|
+
if inputs and not isinstance(inputs, Schema) and not is_dataclass(inputs):
|
|
30
|
+
raise TypeError(
|
|
31
|
+
"inputs must be either None, mlflow.models.signature.Schema, or a dataclass,"
|
|
32
|
+
f"got '{type(inputs).__name__}'"
|
|
33
|
+
)
|
|
34
|
+
if outputs and not isinstance(outputs, Schema) and not is_dataclass(outputs):
|
|
35
|
+
raise TypeError(
|
|
36
|
+
"outputs must be either None, mlflow.models.signature.Schema, or a dataclass,"
|
|
37
|
+
f"got '{type(outputs).__name__}'"
|
|
38
|
+
)
|
|
39
|
+
if params and not isinstance(params, ParamSchema):
|
|
40
|
+
raise TypeError(
|
|
41
|
+
"If params are provided, they must by of type mlflow.models.signature.ParamSchema, "
|
|
42
|
+
f"got '{type(params).__name__}'"
|
|
43
|
+
)
|
|
44
|
+
if all(x is None for x in [inputs, outputs, params]):
|
|
45
|
+
raise ValueError(
|
|
46
|
+
"At least one of inputs, outputs or params must be provided"
|
|
47
|
+
)
|
|
48
|
+
if is_dataclass(inputs):
|
|
49
|
+
self.inputs = convert_dataclass_to_schema(inputs)
|
|
50
|
+
else:
|
|
51
|
+
self.inputs = inputs
|
|
52
|
+
if is_dataclass(outputs):
|
|
53
|
+
self.outputs = convert_dataclass_to_schema(outputs)
|
|
54
|
+
else:
|
|
55
|
+
self.outputs = outputs
|
|
56
|
+
self.params = params
|
|
57
|
+
|
|
58
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
59
|
+
"""
|
|
60
|
+
Serialize into a 'jsonable' dictionary.
|
|
61
|
+
|
|
62
|
+
Input and output schema are represented as json strings. This is so that the
|
|
63
|
+
representation is compact when embedded in an MLmodel yaml file.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
dictionary representation with input and output schema represented as json strings.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
"inputs": self.inputs.to_json() if self.inputs else None,
|
|
71
|
+
"outputs": self.outputs.to_json() if self.outputs else None,
|
|
72
|
+
"params": self.params.to_json() if self.params else None,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_dict(cls, signature_dict: Dict[str, Any]):
|
|
77
|
+
"""
|
|
78
|
+
Deserialize from dictionary representation.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
signature_dict: Dictionary representation of model signature.
|
|
82
|
+
Expected dictionary format:
|
|
83
|
+
`{'inputs': <json string>,
|
|
84
|
+
'outputs': <json string>,
|
|
85
|
+
'params': <json string>" }`
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
ModelSignature populated with the data form the dictionary.
|
|
89
|
+
"""
|
|
90
|
+
inputs = Schema.from_json(x) if (x := signature_dict.get("inputs")) else None
|
|
91
|
+
outputs = Schema.from_json(x) if (x := signature_dict.get("outputs")) else None
|
|
92
|
+
params = (
|
|
93
|
+
ParamSchema.from_json(x) if (x := signature_dict.get("params")) else None
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
return cls(inputs, outputs, params)
|
|
97
|
+
|
|
98
|
+
def __eq__(self, other) -> bool:
|
|
99
|
+
return (
|
|
100
|
+
isinstance(other, ModelSignature)
|
|
101
|
+
and self.inputs == other.inputs
|
|
102
|
+
and self.outputs == other.outputs
|
|
103
|
+
and self.params == other.params
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def __repr__(self) -> str:
|
|
107
|
+
return (
|
|
108
|
+
"inputs: \n"
|
|
109
|
+
f" {self.inputs!r}\n"
|
|
110
|
+
"outputs: \n"
|
|
111
|
+
f" {self.outputs!r}\n"
|
|
112
|
+
"params: \n"
|
|
113
|
+
f" {self.params!r}\n"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def infer_signature(
|
|
118
|
+
model_input: Any = None,
|
|
119
|
+
model_output: "MlflowInferableDataset" = None,
|
|
120
|
+
params: Optional[Dict[str, Any]] = None,
|
|
121
|
+
) -> ModelSignature:
|
|
122
|
+
if model_input is not None:
|
|
123
|
+
inputs = (
|
|
124
|
+
convert_dataclass_to_schema(model_input)
|
|
125
|
+
if is_dataclass(model_input)
|
|
126
|
+
else infer_schema(model_input)
|
|
127
|
+
)
|
|
128
|
+
else:
|
|
129
|
+
inputs = None
|
|
130
|
+
if model_output is not None:
|
|
131
|
+
outputs = (
|
|
132
|
+
convert_dataclass_to_schema(model_output)
|
|
133
|
+
if is_dataclass(model_output)
|
|
134
|
+
else infer_schema(model_output)
|
|
135
|
+
)
|
|
136
|
+
else:
|
|
137
|
+
outputs = None
|
|
138
|
+
params = infer_param_schema(params) if params else None
|
|
139
|
+
return ModelSignature(inputs, outputs, params)
|