truefoundry 0.5.0rc5__py3-none-any.whl → 0.5.0rc7__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.

Files changed (59) hide show
  1. truefoundry/ml/__init__.py +2 -1
  2. truefoundry/ml/artifact/truefoundry_artifact_repo.py +8 -3
  3. truefoundry/ml/autogen/client/__init__.py +6 -4
  4. truefoundry/ml/autogen/client/api/deprecated_api.py +340 -7
  5. truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +0 -322
  6. truefoundry/ml/autogen/client/api_client.py +8 -1
  7. truefoundry/ml/autogen/client/models/__init__.py +6 -4
  8. truefoundry/ml/autogen/client/models/add_features_to_model_version_request_dto.py +3 -17
  9. truefoundry/ml/autogen/client/models/agent.py +1 -1
  10. truefoundry/ml/autogen/client/models/agent_app.py +1 -1
  11. truefoundry/ml/autogen/client/models/agent_open_api_tool.py +1 -1
  12. truefoundry/ml/autogen/client/models/agent_open_api_tool_with_fqn.py +1 -1
  13. truefoundry/ml/autogen/client/models/agent_with_fqn.py +1 -1
  14. truefoundry/ml/autogen/client/models/artifact_version_manifest.py +1 -1
  15. truefoundry/ml/autogen/client/models/assistant_message.py +1 -1
  16. truefoundry/ml/autogen/client/models/blob_storage_reference.py +1 -1
  17. truefoundry/ml/autogen/client/models/chat_prompt.py +1 -1
  18. truefoundry/ml/autogen/client/models/external_artifact_source.py +1 -1
  19. truefoundry/ml/autogen/client/models/fast_ai_framework.py +1 -1
  20. truefoundry/ml/autogen/client/models/gluon_framework.py +1 -1
  21. truefoundry/ml/autogen/client/models/h2_o_framework.py +1 -1
  22. truefoundry/ml/autogen/client/models/image_content_part.py +1 -1
  23. truefoundry/ml/autogen/client/models/keras_framework.py +1 -1
  24. truefoundry/ml/autogen/client/models/light_gbm_framework.py +1 -1
  25. truefoundry/ml/autogen/client/models/model_version_dto.py +7 -8
  26. truefoundry/ml/autogen/client/models/model_version_environment.py +97 -0
  27. truefoundry/ml/autogen/client/models/model_version_manifest.py +12 -1
  28. truefoundry/ml/autogen/client/models/onnx_framework.py +1 -1
  29. truefoundry/ml/autogen/client/models/paddle_framework.py +1 -1
  30. truefoundry/ml/autogen/client/models/py_torch_framework.py +1 -1
  31. truefoundry/ml/autogen/client/models/{feature_value_type.py → serialization_format.py} +8 -8
  32. truefoundry/ml/autogen/client/models/sklearn_framework.py +16 -3
  33. truefoundry/ml/autogen/client/models/spa_cy_framework.py +1 -1
  34. truefoundry/ml/autogen/client/models/stats_models_framework.py +1 -1
  35. truefoundry/ml/autogen/client/models/system_message.py +1 -1
  36. truefoundry/ml/autogen/client/models/tensor_flow_framework.py +1 -1
  37. truefoundry/ml/autogen/client/models/text_content_part.py +1 -1
  38. truefoundry/ml/autogen/client/models/transformers_framework.py +1 -1
  39. truefoundry/ml/autogen/client/models/true_foundry_artifact_source.py +1 -1
  40. truefoundry/ml/autogen/client/models/update_model_version_request_dto.py +1 -13
  41. truefoundry/ml/autogen/client/models/user_message.py +1 -1
  42. truefoundry/ml/autogen/client/models/xg_boost_framework.py +16 -3
  43. truefoundry/ml/autogen/client_README.md +6 -8
  44. truefoundry/ml/autogen/entities/artifacts.py +38 -1
  45. truefoundry/ml/autogen/models/__init__.py +4 -0
  46. truefoundry/ml/autogen/models/exceptions.py +30 -0
  47. truefoundry/ml/autogen/models/schema.py +1547 -0
  48. truefoundry/ml/autogen/models/signature.py +139 -0
  49. truefoundry/ml/autogen/models/utils.py +699 -0
  50. truefoundry/ml/log_types/artifacts/model.py +3 -0
  51. truefoundry/ml/mlfoundry_api.py +3 -1
  52. truefoundry/ml/mlfoundry_run.py +3 -1
  53. {truefoundry-0.5.0rc5.dist-info → truefoundry-0.5.0rc7.dist-info}/METADATA +2 -2
  54. {truefoundry-0.5.0rc5.dist-info → truefoundry-0.5.0rc7.dist-info}/RECORD +56 -53
  55. truefoundry/ml/autogen/client/models/feature_dto.py +0 -68
  56. truefoundry/ml/autogen/client/models/model_schema_dto.py +0 -85
  57. truefoundry/ml/autogen/client/models/prediction_type.py +0 -34
  58. {truefoundry-0.5.0rc5.dist-info → truefoundry-0.5.0rc7.dist-info}/WHEEL +0 -0
  59. {truefoundry-0.5.0rc5.dist-info → truefoundry-0.5.0rc7.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)