truefoundry 0.5.1rc3__py3-none-any.whl → 0.5.1rc5__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.

@@ -51,7 +51,7 @@ class ServiceFoundryServerAuthServiceClient(AuthServiceClient):
51
51
  self._api_server_url = url
52
52
 
53
53
  def refresh_token(self, token: Token, host: Optional[str] = None) -> Token:
54
- host_arg_str = f"--host {host}" if host else "--host HOST"
54
+ host_arg_str = host if host else "HOST"
55
55
  if not token.refresh_token:
56
56
  # TODO: Add a way to propagate error messages without traceback to the output interface side
57
57
  raise Exception(
@@ -128,7 +128,7 @@ class AuthServerServiceClient(AuthServiceClient):
128
128
  self._auth_server_url = url
129
129
 
130
130
  def refresh_token(self, token: Token, host: Optional[str] = None) -> Token:
131
- host_arg_str = f"--host {host}" if host else "--host HOST"
131
+ host_arg_str = host if host else "HOST"
132
132
  if not token.refresh_token:
133
133
  # TODO: Add a way to propagate error messages without traceback to the output interface side
134
134
  raise Exception(
@@ -19,10 +19,7 @@ from truefoundry.ml.log_types.artifacts.artifact import (
19
19
  BlobStorageDirectory,
20
20
  )
21
21
  from truefoundry.ml.log_types.artifacts.dataset import DataDirectory, DataDirectoryPath
22
- from truefoundry.ml.log_types.artifacts.model import (
23
- ModelVersion,
24
- infer_signature,
25
- )
22
+ from truefoundry.ml.log_types.artifacts.model import ModelVersion
26
23
  from truefoundry.ml.logger import init_logger
27
24
  from truefoundry.ml.mlfoundry_api import get_client
28
25
  from truefoundry.ml.mlfoundry_run import MlFoundryRun
@@ -42,6 +39,7 @@ from truefoundry.ml.model_framework import (
42
39
  TensorFlowFramework,
43
40
  TransformersFramework,
44
41
  XGBoostFramework,
42
+ sklearn_infer_schema,
45
43
  )
46
44
 
47
45
  __all__ = [
@@ -80,7 +78,7 @@ __all__ = [
80
78
  "XGBoostFramework",
81
79
  "XGBoostModelSchema",
82
80
  "get_client",
83
- "infer_signature",
81
+ "sklearn_infer_schema",
84
82
  ]
85
83
 
86
84
  init_logger()
@@ -1,13 +1,16 @@
1
1
  from dataclasses import dataclass, is_dataclass
2
- from typing import Any, Dict, Optional, Union
2
+ from typing import TYPE_CHECKING, Any, Dict, Optional, Union
3
3
 
4
4
  import numpy as np
5
- import pandas as pd
5
+
6
+ if TYPE_CHECKING:
7
+ import pandas as pd
8
+
6
9
 
7
10
  from .schema import ParamSchema, Schema, convert_dataclass_to_schema
8
11
  from .utils import infer_param_schema, infer_schema
9
12
 
10
- MlflowInferableDataset = Union[pd.DataFrame, np.ndarray, Dict[str, np.ndarray]]
13
+ MlflowInferableDataset = Union["pd.DataFrame", "np.ndarray", Dict[str, "np.ndarray"]]
11
14
 
12
15
 
13
16
  class ModelSignature:
@@ -4,7 +4,12 @@ from collections import defaultdict
4
4
  from typing import Any, Dict, List, Optional, Union
5
5
 
6
6
  import numpy as np
7
- import pandas as pd
7
+
8
+ try:
9
+ import pandas as pd
10
+ except ImportError:
11
+ pd = None
12
+
8
13
 
9
14
  from .exceptions import MlflowException
10
15
  from .schema import (
@@ -330,7 +335,7 @@ def infer_schema(data: Any) -> Schema: # noqa: C901
330
335
  ]
331
336
  )
332
337
  # pandas.Series
333
- elif isinstance(data, pd.Series):
338
+ elif pd and isinstance(data, pd.Series):
334
339
  name = getattr(data, "name", None)
335
340
  schema = Schema(
336
341
  [
@@ -342,7 +347,7 @@ def infer_schema(data: Any) -> Schema: # noqa: C901
342
347
  ]
343
348
  )
344
349
  # pandas.DataFrame
345
- elif isinstance(data, pd.DataFrame):
350
+ elif pd and isinstance(data, pd.DataFrame):
346
351
  schema = Schema(
347
352
  [
348
353
  ColSpec(
@@ -473,13 +478,13 @@ def _is_none_or_nan(x):
473
478
 
474
479
 
475
480
  def _infer_required(col) -> bool:
476
- if isinstance(col, (list, pd.Series)):
481
+ if pd and isinstance(col, (list, pd.Series)):
477
482
  return not any(_is_none_or_nan(x) for x in col)
478
483
  return not _is_none_or_nan(col)
479
484
 
480
485
 
481
- def _infer_pandas_column(col: pd.Series) -> DataType:
482
- if not isinstance(col, pd.Series):
486
+ def _infer_pandas_column(col: "pd.Series") -> DataType:
487
+ if pd and not isinstance(col, pd.Series):
483
488
  raise TypeError(f"Expected pandas.Series, got '{type(col)}'.")
484
489
  if len(col.values.shape) > 1:
485
490
  raise MlflowException(f"Expected 1d array, got array with shape {col.shape}")
@@ -496,7 +501,7 @@ def _infer_pandas_column(col: pd.Series) -> DataType:
496
501
  # For backwards compatibility, we fall back to string
497
502
  # if the provided array is of string type
498
503
  # This is for diviner test where df field is ('key2', 'key1', 'key0')
499
- if pd.api.types.is_string_dtype(col):
504
+ if pd and pd.api.types.is_string_dtype(col):
500
505
  return DataType.string
501
506
  raise MlflowException(
502
507
  f"Failed to infer schema for pandas.Series {col}. Error: {e}"
@@ -31,6 +31,7 @@ from truefoundry.ml.autogen.client import ( # type: ignore[attr-defined]
31
31
  TrueFoundryArtifactSource,
32
32
  UpdateModelVersionRequestDto,
33
33
  )
34
+ from truefoundry.ml.autogen.models import infer_signature as _infer_signature
34
35
  from truefoundry.ml.enums import ModelFramework
35
36
  from truefoundry.ml.exceptions import MlFoundryException
36
37
  from truefoundry.ml.log_types.artifacts.artifact import BlobStorageDirectory
@@ -611,9 +612,6 @@ def infer_signature(
611
612
  ] = None,
612
613
  params: Optional[Dict[str, Any]] = None,
613
614
  ):
614
- # TODO: Importing this globally causes hard dependencies on some libraries like pandas
615
- from truefoundry.ml.autogen.models import infer_signature as _infer_signature
616
-
617
615
  return _infer_signature(
618
616
  model_input=model_input, model_output=model_output, params=params
619
617
  )
@@ -172,7 +172,7 @@ def _get_src_dest_pairs(
172
172
  dest_to_src_map: Dict[str, str],
173
173
  ) -> Sequence[Tuple[str, str]]:
174
174
  src_dest_pairs = [
175
- (src_path, os.path.relpath(dest_abs_path, root_dir))
175
+ (src_path, to_unix_path(os.path.relpath(dest_abs_path, root_dir)))
176
176
  for dest_abs_path, src_path in dest_to_src_map.items()
177
177
  ]
178
178
  return src_dest_pairs
@@ -1,8 +1,20 @@
1
+ import json
1
2
  import os
2
3
  import warnings
3
4
  from collections import OrderedDict
4
5
  from pickle import load as pickle_load
5
- from typing import Any, Callable, Dict, List, Literal, Optional, Type, Union, get_args
6
+ from typing import (
7
+ TYPE_CHECKING,
8
+ Any,
9
+ Callable,
10
+ Dict,
11
+ List,
12
+ Literal,
13
+ Optional,
14
+ Type,
15
+ Union,
16
+ get_args,
17
+ )
6
18
 
7
19
  from truefoundry.common.utils import (
8
20
  get_python_version_major_minor,
@@ -10,6 +22,7 @@ from truefoundry.common.utils import (
10
22
  )
11
23
  from truefoundry.ml.autogen.client import SerializationFormat
12
24
  from truefoundry.ml.autogen.entities import artifacts as autogen_artifacts
25
+ from truefoundry.ml.autogen.models import infer_signature
13
26
  from truefoundry.ml.enums import ModelFramework
14
27
  from truefoundry.ml.log_types.artifacts.utils import (
15
28
  get_single_file_path_if_only_one_in_directory,
@@ -17,6 +30,9 @@ from truefoundry.ml.log_types.artifacts.utils import (
17
30
  )
18
31
  from truefoundry.pydantic_v1 import BaseModel, Field
19
32
 
33
+ if TYPE_CHECKING:
34
+ from sklearn.base import BaseEstimator
35
+
20
36
  # Map serialization format to corresponding pip packages
21
37
  SERIALIZATION_FORMAT_TO_PACKAGES_NAME_MAP = {
22
38
  SerializationFormat.JOBLIB: ["joblib"],
@@ -421,3 +437,37 @@ def auto_update_model_framework_details(
421
437
  model_file_path=absolute_model_filepath
422
438
  )
423
439
  )
440
+
441
+
442
+ def sklearn_infer_schema(
443
+ model_input: Any,
444
+ model: "BaseEstimator",
445
+ infer_method_name: str = "predict",
446
+ ) -> autogen_artifacts.SklearnModelSchema:
447
+ """
448
+ Infer the schema of a Sklearn model.
449
+
450
+ Args:
451
+ model_input (Any): The input data to be used for schema inference.
452
+ model (Any): The Sklearn model instance.
453
+ infer_method_name (str): The name of the method to be used for schema inference.
454
+ Eg: predict (default), predict_proba
455
+ Returns:
456
+ SklearnModelSchema: The inferred schema of the Sklearn model.
457
+ """
458
+ if not hasattr(model, infer_method_name):
459
+ raise ValueError(
460
+ f"Model does not have the method '{infer_method_name}' to infer the schema."
461
+ )
462
+ model_infer_method = getattr(model, infer_method_name)
463
+ model_output = model_infer_method(model_input)
464
+
465
+ model_signature = infer_signature(
466
+ model_input=model_input, model_output=model_output
467
+ )
468
+ model_signature_json = model_signature.to_dict()
469
+ return autogen_artifacts.SklearnModelSchema(
470
+ infer_method_name=infer_method_name,
471
+ inputs=json.loads(model_signature_json["inputs"]),
472
+ outputs=json.loads(model_signature_json["outputs"]),
473
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: truefoundry
3
- Version: 0.5.1rc3
3
+ Version: 0.5.1rc5
4
4
  Summary: Truefoundry CLI
5
5
  Author: Abhishek Choudhary
6
6
  Author-email: abhishek@truefoundry.com
@@ -26,7 +26,7 @@ truefoundry/autodeploy/utils/pydantic_compat.py,sha256=hEAUy5kLjhPdzw7yGZ2iXGMXb
26
26
  truefoundry/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  truefoundry/cli/__main__.py,sha256=-NkhYlT3mC5MhtekueKAvCw-sWvguj0LJRpXWzvvFjc,727
28
28
  truefoundry/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- truefoundry/common/auth_service_client.py,sha256=tZOa0NdATnItsMeTnEnUeTZQIgUJtpU-nvLdWtB4Px8,7978
29
+ truefoundry/common/auth_service_client.py,sha256=RRiGUqITxeVYwKZLc923zJP-61UAvFtVlMaG2HJBvXc,7940
30
30
  truefoundry/common/constants.py,sha256=OwT8CJxGDhnrfgXCiKG5d5pkGbrd1UGGY-y672Et07Y,2310
31
31
  truefoundry/common/credential_file_manager.py,sha256=1yEk1Zm2xS4G0VDFwKSZ4w0VUrcPWQ1nJnoBaz9xyKA,4251
32
32
  truefoundry/common/credential_provider.py,sha256=Aht7hFLsnyRgMR34dRbzln7dor0WYSeA8ej8ApNmnKM,4148
@@ -107,7 +107,7 @@ truefoundry/deploy/v2/lib/models.py,sha256=pSolLMTArDuYpeNsmeeS5DWliloN_iCDfZSpR
107
107
  truefoundry/deploy/v2/lib/patched_models.py,sha256=NTU8J_CwdvEuF9zNXwFyN3suOp_196Wrm75DDy5qcXE,14184
108
108
  truefoundry/deploy/v2/lib/source.py,sha256=VHKuFREiixUP40D3Mrz-TA70spu1M0RbCzl--qwlFaY,9263
109
109
  truefoundry/logger.py,sha256=u-YCNjg5HBwE70uQcpjIG64Ghos-K2ulTWaxC03BSj4,714
110
- truefoundry/ml/__init__.py,sha256=iTuqq6FuVozL0Vyz1B2Xb5PL2LNnXyALXM0S3ehQicQ,2039
110
+ truefoundry/ml/__init__.py,sha256=VtP0B3DNFFV_1b4WHkAo_XRMvWHmyeEwDu984t4cy8s,2040
111
111
  truefoundry/ml/artifact/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
112
112
  truefoundry/ml/artifact/truefoundry_artifact_repo.py,sha256=FksxhUpRHb9pgWZmAB16DhXqkAL6UIAPA1S3RJUApQU,46201
113
113
  truefoundry/ml/autogen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -310,8 +310,8 @@ truefoundry/ml/autogen/entities/artifacts.py,sha256=x3DxHXPS5OpNb1vmuy6p44g2hymq
310
310
  truefoundry/ml/autogen/models/__init__.py,sha256=--TGRea9SQBWFfwtcl3ekb1XGfFTdEkQGSG8a2SJ60I,187
311
311
  truefoundry/ml/autogen/models/exceptions.py,sha256=q3n7FGBrg_hUy1UyoefhMnhcXUAaqXlLIGHoOVzn_d8,1390
312
312
  truefoundry/ml/autogen/models/schema.py,sha256=IhpO9qbygLqEamP3NIt3m90SseJXCOm1ZTqNbNbW-M0,55772
313
- truefoundry/ml/autogen/models/signature.py,sha256=EppDGjws10CTatxcTBTuT-b3jJX9lmR6ZX98eC6PB5w,4942
314
- truefoundry/ml/autogen/models/utils.py,sha256=Z52SnAF7UL7uluNtA_VXuB9iPju-q9bpTTFJnUh0ZTQ,24289
313
+ truefoundry/ml/autogen/models/signature.py,sha256=rBjpxUIsEeWM0sIyYG5uCJB18DKHR4k5yZw8TzuoP48,4987
314
+ truefoundry/ml/autogen/models/utils.py,sha256=c7RtSLXhOLcP8rjuUtfnMdaKVTZvvbsmw98gPAkAFrs,24371
315
315
  truefoundry/ml/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
316
316
  truefoundry/ml/cli/cli.py,sha256=ckBcjUpqfhgrPE1okqT_G2iouOLt-0KjpLhHp2YdVFU,256
317
317
  truefoundry/ml/cli/commands/__init__.py,sha256=diDUiRUX4l6TtNLI4iF-ZblczkELM7FRViJ-8gGNJQY,82
@@ -333,8 +333,8 @@ truefoundry/ml/log_types/artifacts/artifact.py,sha256=6X4lO23DwM7yTgUOY4RRoYMrf9
333
333
  truefoundry/ml/log_types/artifacts/constants.py,sha256=qKxQ5mMvJE4j83BvGW3qNTKunxCiBg_EEjTdgbgJtyE,1036
334
334
  truefoundry/ml/log_types/artifacts/dataset.py,sha256=a4dxd2EN8p7Ci-cLGGiDOboN3t0395_XhWE1dmTw1Q4,13112
335
335
  truefoundry/ml/log_types/artifacts/general_artifact.py,sha256=B4XErLr-m6RmQWtxMTu3wlFRFcqSwPYp6J0OL4Ng6L0,3179
336
- truefoundry/ml/log_types/artifacts/model.py,sha256=d2Q-61yXpX1mjXX6t2sL0_xKz-DPA3Z8xYDxzMfUSiA,22820
337
- truefoundry/ml/log_types/artifacts/utils.py,sha256=yhIZYe3Y-J0rG0Wcwql_Qjxe9hlefFbXUfRFqg4E9cM,7502
336
+ truefoundry/ml/log_types/artifacts/model.py,sha256=sOqMptIpr2YRv7VC6AntFDvDUg5eQLsS7jQ_4TUB5Ds,22724
337
+ truefoundry/ml/log_types/artifacts/utils.py,sha256=8mmahc1b6wvrA_E795h9ynRfhYRIdci7LRGN8U6ySm8,7516
338
338
  truefoundry/ml/log_types/image/__init__.py,sha256=fcOq8yQnNj1rkLcPeIjLXBpdA1WIeiPsXOlAAvMxx7M,76
339
339
  truefoundry/ml/log_types/image/constants.py,sha256=wLtGEOA4T5fZHSlOXPuNDLX3lpbCtwlvGKPFk_1fah0,255
340
340
  truefoundry/ml/log_types/image/image.py,sha256=qQnAVgErAq4Jn6wXFFpaveOd52zcjUuomUCqNRxO2io,12478
@@ -346,7 +346,7 @@ truefoundry/ml/log_types/utils.py,sha256=xjJ21jdPScvFmw3TbVh5NCzbzJwaqiXJyiiT4xx
346
346
  truefoundry/ml/logger.py,sha256=VT-BF3BnBYTWVq87O58F0c8uXMu94gYzsiFlGY3_7Ao,458
347
347
  truefoundry/ml/mlfoundry_api.py,sha256=PefznXwBPBv8TD4RYid9aiE8WWEkZQAHoaAbvklFoRs,62364
348
348
  truefoundry/ml/mlfoundry_run.py,sha256=RLTZGz3htyxNmG1Xat9WevawEIjDoUCbWrSNql8WynI,44597
349
- truefoundry/ml/model_framework.py,sha256=2JTQ8m5oqy2FaIBqIEgPeDEfwNBfcQHTw-gdcMXF1pA,15033
349
+ truefoundry/ml/model_framework.py,sha256=I04pbczUh6bBmxWI-fzWgpUSY_ab7Js2zDB6fX4zvYM,16458
350
350
  truefoundry/ml/run_utils.py,sha256=0W208wSLUrbdfk2pjNcZlkUi9bNxG2JORqoe-5rVqHI,2423
351
351
  truefoundry/ml/session.py,sha256=F83GTC5WwGBjnJ69Ct8MqMnlutYc56JCc6YhEY1Wl-A,5394
352
352
  truefoundry/ml/validation_utils.py,sha256=J5atNhcJLvKj64ralSV9Y5Fv1Rt4SE237ICdP9-7sP4,12149
@@ -367,7 +367,7 @@ truefoundry/workflow/remote_filesystem/tfy_signed_url_client.py,sha256=5mBCIc-ON
367
367
  truefoundry/workflow/remote_filesystem/tfy_signed_url_fs.py,sha256=Hf6Dk6Fu6P7DqsK5ULgraf9DStjgigf-kjaRAMBW-RU,8680
368
368
  truefoundry/workflow/task.py,sha256=ToitYiKcNzFCtOVQwz1W8sRjbR97eVS7vQBdbgUQtKg,1779
369
369
  truefoundry/workflow/workflow.py,sha256=WaTqUjhwfAXDWu4E5ehuwAxrCbDJkoAf1oWmR2E9Qy0,4575
370
- truefoundry-0.5.1rc3.dist-info/METADATA,sha256=isGJJmi0DSlh57OQh5ukDKprSYhHxMt59RG1vsjSbhA,2887
371
- truefoundry-0.5.1rc3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
372
- truefoundry-0.5.1rc3.dist-info/entry_points.txt,sha256=TXvUxQkI6zmqJuycPsyxEIMr3oqfDjgrWj0m_9X12x4,95
373
- truefoundry-0.5.1rc3.dist-info/RECORD,,
370
+ truefoundry-0.5.1rc5.dist-info/METADATA,sha256=t-aW1hCgehMk_D0ptXbHYE9auNrknNpupQpRsNS6Kws,2887
371
+ truefoundry-0.5.1rc5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
372
+ truefoundry-0.5.1rc5.dist-info/entry_points.txt,sha256=TXvUxQkI6zmqJuycPsyxEIMr3oqfDjgrWj0m_9X12x4,95
373
+ truefoundry-0.5.1rc5.dist-info/RECORD,,