truefoundry 0.5.0rc7__py3-none-any.whl → 0.5.1__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/common/auth_service_client.py +2 -2
- truefoundry/common/constants.py +9 -0
- truefoundry/common/utils.py +81 -1
- truefoundry/deploy/__init__.py +5 -0
- truefoundry/deploy/builder/builders/tfy_notebook_buildpack/__init__.py +4 -2
- truefoundry/deploy/builder/builders/tfy_python_buildpack/__init__.py +7 -5
- truefoundry/deploy/builder/builders/tfy_python_buildpack/dockerfile_template.py +87 -28
- truefoundry/deploy/builder/constants.py +8 -0
- truefoundry/deploy/builder/utils.py +9 -4
- truefoundry/deploy/cli/cli.py +2 -0
- truefoundry/deploy/cli/commands/__init__.py +1 -0
- truefoundry/deploy/cli/commands/deploy_init_command.py +22 -0
- truefoundry/deploy/lib/dao/application.py +2 -1
- truefoundry/deploy/v2/lib/patched_models.py +8 -0
- truefoundry/ml/__init__.py +25 -16
- truefoundry/ml/autogen/client/__init__.py +21 -3
- truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +325 -0
- truefoundry/ml/autogen/client/models/__init__.py +21 -3
- truefoundry/ml/autogen/client/models/artifact_version_manifest.py +2 -2
- truefoundry/ml/autogen/client/models/export_deployment_files_request_dto.py +82 -0
- truefoundry/ml/autogen/client/models/infer_method_name.py +34 -0
- truefoundry/ml/autogen/client/models/model_server.py +34 -0
- truefoundry/ml/autogen/client/models/model_version_environment.py +1 -1
- truefoundry/ml/autogen/client/models/model_version_manifest.py +2 -8
- truefoundry/ml/autogen/client/models/sklearn_framework.py +15 -5
- truefoundry/ml/autogen/client/models/sklearn_model_schema.py +82 -0
- truefoundry/ml/autogen/client/models/{serialization_format.py → sklearn_serialization_format.py} +5 -5
- truefoundry/ml/autogen/client/models/transformers_framework.py +2 -2
- truefoundry/ml/autogen/client/models/validate_external_storage_root_request_dto.py +71 -0
- truefoundry/ml/autogen/client/models/validate_external_storage_root_response_dto.py +69 -0
- truefoundry/ml/autogen/client/models/xg_boost_framework.py +17 -5
- truefoundry/ml/autogen/client/models/xg_boost_model_schema.py +88 -0
- truefoundry/ml/autogen/client/models/xg_boost_serialization_format.py +36 -0
- truefoundry/ml/autogen/client_README.md +11 -1
- truefoundry/ml/autogen/entities/artifacts.py +95 -39
- truefoundry/ml/autogen/models/signature.py +6 -3
- truefoundry/ml/autogen/models/utils.py +12 -7
- truefoundry/ml/cli/commands/model_init.py +97 -0
- truefoundry/ml/cli/utils.py +34 -0
- truefoundry/ml/log_types/artifacts/model.py +50 -38
- truefoundry/ml/log_types/artifacts/utils.py +38 -2
- truefoundry/ml/mlfoundry_api.py +74 -80
- truefoundry/ml/mlfoundry_run.py +0 -32
- truefoundry/ml/model_framework.py +372 -3
- truefoundry/ml/validation_utils.py +2 -0
- {truefoundry-0.5.0rc7.dist-info → truefoundry-0.5.1.dist-info}/METADATA +1 -5
- {truefoundry-0.5.0rc7.dist-info → truefoundry-0.5.1.dist-info}/RECORD +49 -56
- truefoundry/deploy/function_service/__init__.py +0 -3
- truefoundry/deploy/function_service/__main__.py +0 -27
- truefoundry/deploy/function_service/app.py +0 -92
- truefoundry/deploy/function_service/build.py +0 -45
- truefoundry/deploy/function_service/remote/__init__.py +0 -6
- truefoundry/deploy/function_service/remote/context.py +0 -3
- truefoundry/deploy/function_service/remote/method.py +0 -67
- truefoundry/deploy/function_service/remote/remote.py +0 -144
- truefoundry/deploy/function_service/route.py +0 -137
- truefoundry/deploy/function_service/service.py +0 -113
- truefoundry/deploy/function_service/utils.py +0 -53
- truefoundry/langchain/__init__.py +0 -12
- truefoundry/langchain/deprecated.py +0 -302
- truefoundry/langchain/truefoundry_chat.py +0 -130
- truefoundry/langchain/truefoundry_embeddings.py +0 -171
- truefoundry/langchain/truefoundry_llm.py +0 -106
- truefoundry/langchain/utils.py +0 -44
- truefoundry/ml/log_types/artifacts/model_extras.py +0 -48
- {truefoundry-0.5.0rc7.dist-info → truefoundry-0.5.1.dist-info}/WHEEL +0 -0
- {truefoundry-0.5.0rc7.dist-info → truefoundry-0.5.1.dist-info}/entry_points.txt +0 -0
truefoundry/ml/mlfoundry_api.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import time
|
|
3
3
|
import uuid
|
|
4
|
-
|
|
4
|
+
import zipfile
|
|
5
|
+
from io import BytesIO
|
|
5
6
|
from typing import (
|
|
6
7
|
TYPE_CHECKING,
|
|
7
8
|
Any,
|
|
@@ -15,9 +16,8 @@ from typing import (
|
|
|
15
16
|
)
|
|
16
17
|
|
|
17
18
|
import coolname
|
|
18
|
-
import pandas as pd
|
|
19
19
|
|
|
20
|
-
from truefoundry.common.utils import relogin_error_message
|
|
20
|
+
from truefoundry.common.utils import ContextualDirectoryManager, relogin_error_message
|
|
21
21
|
from truefoundry.ml import ModelVersionEnvironment, constants
|
|
22
22
|
from truefoundry.ml.autogen.client import ( # type: ignore[attr-defined]
|
|
23
23
|
ArtifactDto,
|
|
@@ -27,12 +27,14 @@ from truefoundry.ml.autogen.client import ( # type: ignore[attr-defined]
|
|
|
27
27
|
CreateRunRequestDto,
|
|
28
28
|
DatasetDto,
|
|
29
29
|
ExperimentsApi,
|
|
30
|
+
ExportDeploymentFilesRequestDto,
|
|
30
31
|
ListArtifactsRequestDto,
|
|
31
32
|
ListArtifactVersionsRequestDto,
|
|
32
33
|
ListDatasetsRequestDto,
|
|
33
34
|
ListModelVersionsRequestDto,
|
|
34
35
|
MlfoundryArtifactsApi,
|
|
35
36
|
ModelDto,
|
|
37
|
+
ModelServer,
|
|
36
38
|
RunsApi,
|
|
37
39
|
RunTagDto,
|
|
38
40
|
SearchRunsRequestDto,
|
|
@@ -75,7 +77,7 @@ if TYPE_CHECKING:
|
|
|
75
77
|
from truefoundry.ml import ModelFrameworkType
|
|
76
78
|
|
|
77
79
|
_SEARCH_MAX_RESULTS_DEFAULT = 1000
|
|
78
|
-
|
|
80
|
+
_ML_FOUNDRY_API_REQUEST_TIMEOUT = 10
|
|
79
81
|
_INTERNAL_ENV_VARS = [
|
|
80
82
|
"TFY_INTERNAL_APPLICATION_ID",
|
|
81
83
|
"TFY_INTERNAL_JOB_RUN_NAME",
|
|
@@ -476,43 +478,6 @@ class MlFoundry:
|
|
|
476
478
|
)
|
|
477
479
|
return mlfoundry_run
|
|
478
480
|
|
|
479
|
-
def get_all_runs(
|
|
480
|
-
self,
|
|
481
|
-
ml_repo: str,
|
|
482
|
-
) -> pd.DataFrame:
|
|
483
|
-
"""Returns all the run name and id present under a ML Repo.
|
|
484
|
-
|
|
485
|
-
The user must have `READ` access to the ML Repo.
|
|
486
|
-
|
|
487
|
-
Args:
|
|
488
|
-
ml_repo (str): Name of the ML Repo.
|
|
489
|
-
Returns:
|
|
490
|
-
pd.DataFrame: dataframe with two columns- run_id and run_name
|
|
491
|
-
|
|
492
|
-
Examples:
|
|
493
|
-
|
|
494
|
-
### get all the runs from a ml_repo
|
|
495
|
-
```python
|
|
496
|
-
from truefoundry.ml import get_client
|
|
497
|
-
|
|
498
|
-
client = get_client()
|
|
499
|
-
|
|
500
|
-
run = client.get_all_runs(ml_repo='my-repo')
|
|
501
|
-
```
|
|
502
|
-
"""
|
|
503
|
-
runs = []
|
|
504
|
-
for run in self.search_runs(ml_repo=ml_repo):
|
|
505
|
-
runs.append((run.run_id, run.run_name))
|
|
506
|
-
|
|
507
|
-
if len(runs) == 0:
|
|
508
|
-
return pd.DataFrame(
|
|
509
|
-
columns=[constants.RUN_ID_COL_NAME, constants.RUN_NAME_COL_NAME]
|
|
510
|
-
)
|
|
511
|
-
|
|
512
|
-
return pd.DataFrame(
|
|
513
|
-
runs, columns=[constants.RUN_ID_COL_NAME, constants.RUN_NAME_COL_NAME]
|
|
514
|
-
)
|
|
515
|
-
|
|
516
481
|
def search_runs(
|
|
517
482
|
self,
|
|
518
483
|
ml_repo: str,
|
|
@@ -658,6 +623,74 @@ class MlFoundry:
|
|
|
658
623
|
"""
|
|
659
624
|
return self._tracking_uri
|
|
660
625
|
|
|
626
|
+
def _initialize_model_server(
|
|
627
|
+
self,
|
|
628
|
+
name: str,
|
|
629
|
+
model_version_fqn: str,
|
|
630
|
+
workspace_fqn: str,
|
|
631
|
+
model_server: ModelServer,
|
|
632
|
+
output_dir: Optional[str] = None,
|
|
633
|
+
) -> str:
|
|
634
|
+
"""
|
|
635
|
+
Initialize the model server for deployment.
|
|
636
|
+
|
|
637
|
+
Args:
|
|
638
|
+
name (str): Name of the application.
|
|
639
|
+
model_version_fqn (str): Fully Qualified Name of the model version.
|
|
640
|
+
workspace_fqn (str): Fully Qualified Name of the workspace.
|
|
641
|
+
model_server (ModelServer): Server type for deployment (e.g., TRITON).
|
|
642
|
+
output_dir (Optional[str]): Directory where the model files will be extracted.
|
|
643
|
+
Defaults to the current working directory.
|
|
644
|
+
|
|
645
|
+
Returns:
|
|
646
|
+
str: Path to the directory where the model files are extracted.
|
|
647
|
+
|
|
648
|
+
Raises:
|
|
649
|
+
MlFoundryException: If an error occurs during API calls, directory creation, or file extraction.
|
|
650
|
+
"""
|
|
651
|
+
|
|
652
|
+
# Using get_with_http_info to get the response object and extract the raw data
|
|
653
|
+
try:
|
|
654
|
+
export_deployment_files_request_dto = ExportDeploymentFilesRequestDto(
|
|
655
|
+
model_version_fqn=model_version_fqn,
|
|
656
|
+
workspace_fqn=workspace_fqn,
|
|
657
|
+
service_name=name,
|
|
658
|
+
model_server=model_server,
|
|
659
|
+
)
|
|
660
|
+
response = self._mlfoundry_artifacts_api.export_deployment_files_by_fqn_post_with_http_info(
|
|
661
|
+
export_deployment_files_request_dto=export_deployment_files_request_dto,
|
|
662
|
+
_preload_content=False,
|
|
663
|
+
_request_timeout=_ML_FOUNDRY_API_REQUEST_TIMEOUT,
|
|
664
|
+
)
|
|
665
|
+
except ApiException as e:
|
|
666
|
+
err_msg = (
|
|
667
|
+
f"Failed to fetch deployment files for name={name}, "
|
|
668
|
+
f"model_version_fqn={model_version_fqn}, workspace_fqn={workspace_fqn}. "
|
|
669
|
+
f"Error: {e}"
|
|
670
|
+
)
|
|
671
|
+
raise MlFoundryException(err_msg) from e
|
|
672
|
+
|
|
673
|
+
output_dir = os.path.abspath(output_dir or os.getcwd())
|
|
674
|
+
codegen_dir = os.path.join(output_dir, name)
|
|
675
|
+
if codegen_dir == output_dir:
|
|
676
|
+
raise ValueError("Name cannot be empty, please provide a valid name")
|
|
677
|
+
|
|
678
|
+
try:
|
|
679
|
+
with ContextualDirectoryManager(dir_path=codegen_dir) as dir_path:
|
|
680
|
+
with zipfile.ZipFile(BytesIO(response.raw_data), mode="r") as zip_file:
|
|
681
|
+
zip_file.extractall(dir_path)
|
|
682
|
+
except FileExistsError as e:
|
|
683
|
+
err_msg = (
|
|
684
|
+
f"Deployment directory {codegen_dir!r} already exists. "
|
|
685
|
+
"Please choose a different deployment name or delete the existing directory."
|
|
686
|
+
)
|
|
687
|
+
raise MlFoundryException(err_msg) from e
|
|
688
|
+
except zipfile.BadZipFile as e:
|
|
689
|
+
raise MlFoundryException(
|
|
690
|
+
f"Failed to extract model files. Error: {e}"
|
|
691
|
+
) from e
|
|
692
|
+
return codegen_dir
|
|
693
|
+
|
|
661
694
|
def get_model_version(
|
|
662
695
|
self,
|
|
663
696
|
ml_repo: str,
|
|
@@ -1227,13 +1260,11 @@ class MlFoundry:
|
|
|
1227
1260
|
ml_repo: str,
|
|
1228
1261
|
name: str,
|
|
1229
1262
|
model_file_or_folder: Union[str, BlobStorageDirectory],
|
|
1230
|
-
additional_files: Sequence[Tuple[Union[str, Path], Optional[str]]] = (),
|
|
1231
1263
|
description: Optional[str] = None,
|
|
1232
1264
|
metadata: Optional[Dict[str, Any]] = None,
|
|
1233
1265
|
progress: Optional[bool] = None,
|
|
1234
1266
|
framework: Optional[Union[str, ModelFramework, "ModelFrameworkType"]] = None,
|
|
1235
1267
|
environment: Optional[ModelVersionEnvironment] = None,
|
|
1236
|
-
model_schema: Optional[Dict[str, Any]] = None,
|
|
1237
1268
|
) -> ModelVersion:
|
|
1238
1269
|
"""
|
|
1239
1270
|
Serialize and log a versioned model under the current ml_repo. Each logged model generates a new version
|
|
@@ -1263,41 +1294,6 @@ class MlFoundry:
|
|
|
1263
1294
|
Can also be `None` if the framework is not known or not supported.
|
|
1264
1295
|
**Deprecated**: Prefer `ModelFrameworkType` over `enums.ModelFramework`.
|
|
1265
1296
|
|
|
1266
|
-
additional_files (Sequence[Tuple[Union[str, Path], Optional[str]]], optional): A list of pairs
|
|
1267
|
-
of (source path, destination path) to add additional files and folders
|
|
1268
|
-
to the model version contents. The first member of the pair should be a file or directory path
|
|
1269
|
-
and the second member should be the path inside the model versions contents to upload to.
|
|
1270
|
-
The model version contents are arranged like follows
|
|
1271
|
-
.
|
|
1272
|
-
└── model/
|
|
1273
|
-
└── # model files are serialized here
|
|
1274
|
-
└── # any additional files and folders can be added here.
|
|
1275
|
-
|
|
1276
|
-
You can also add additional files to model/ subdirectory by specifying the destination path as model/
|
|
1277
|
-
|
|
1278
|
-
```python
|
|
1279
|
-
from truefoundry.ml import TensorFlowFramework
|
|
1280
|
-
|
|
1281
|
-
run.log_model(
|
|
1282
|
-
name="xyz",
|
|
1283
|
-
model_file_or_folder="clf.joblib",
|
|
1284
|
-
framework=TensorFlowFramework(),
|
|
1285
|
-
additional_files=[("foo.txt", "foo/bar/foo.txt"), ("tokenizer/", "foo/tokenizer/")]
|
|
1286
|
-
)
|
|
1287
|
-
```
|
|
1288
|
-
|
|
1289
|
-
would result in
|
|
1290
|
-
|
|
1291
|
-
```
|
|
1292
|
-
.
|
|
1293
|
-
├── model/
|
|
1294
|
-
│ └── clf.joblib # if `model_file_or_folder` is a folder, contents will be added here
|
|
1295
|
-
└── foo/
|
|
1296
|
-
├── bar/
|
|
1297
|
-
│ └── foo.txt
|
|
1298
|
-
└── tokenizer/
|
|
1299
|
-
└── # contents of tokenizer/ directory will be uploaded here
|
|
1300
|
-
```
|
|
1301
1297
|
description (Optional[str], optional): arbitrary text upto 1024 characters to store as description.
|
|
1302
1298
|
This field can be updated at any time after logging. Defaults to `None`
|
|
1303
1299
|
metadata (Optional[Dict[str, Any]], optional): arbitrary json serializable dictionary to store metadata.
|
|
@@ -1387,14 +1383,12 @@ class MlFoundry:
|
|
|
1387
1383
|
ml_repo_id=ml_repo_id,
|
|
1388
1384
|
name=name,
|
|
1389
1385
|
model_file_or_folder=model_file_or_folder,
|
|
1390
|
-
additional_files=additional_files,
|
|
1391
1386
|
description=description,
|
|
1392
1387
|
metadata=metadata,
|
|
1393
1388
|
step=None,
|
|
1394
1389
|
progress=progress,
|
|
1395
1390
|
framework=framework,
|
|
1396
1391
|
environment=environment,
|
|
1397
|
-
model_schema=model_schema,
|
|
1398
1392
|
)
|
|
1399
1393
|
logger.info(f"Logged model successfully with fqn {model_version.fqn!r}")
|
|
1400
1394
|
return model_version
|
truefoundry/ml/mlfoundry_run.py
CHANGED
|
@@ -3,7 +3,6 @@ import os
|
|
|
3
3
|
import platform
|
|
4
4
|
import re
|
|
5
5
|
import time
|
|
6
|
-
from pathlib import Path
|
|
7
6
|
from typing import (
|
|
8
7
|
TYPE_CHECKING,
|
|
9
8
|
Any,
|
|
@@ -12,7 +11,6 @@ from typing import (
|
|
|
12
11
|
Iterator,
|
|
13
12
|
List,
|
|
14
13
|
Optional,
|
|
15
|
-
Sequence,
|
|
16
14
|
Tuple,
|
|
17
15
|
Union,
|
|
18
16
|
)
|
|
@@ -930,14 +928,12 @@ class MlFoundryRun:
|
|
|
930
928
|
*,
|
|
931
929
|
name: str,
|
|
932
930
|
model_file_or_folder: Union[str, BlobStorageDirectory],
|
|
933
|
-
additional_files: Sequence[Tuple[Union[str, Path], Optional[str]]] = (),
|
|
934
931
|
description: Optional[str] = None,
|
|
935
932
|
metadata: Optional[Dict[str, Any]] = None,
|
|
936
933
|
step: int = 0,
|
|
937
934
|
progress: Optional[bool] = None,
|
|
938
935
|
framework: Optional[Union[str, ModelFramework, "ModelFrameworkType"]] = None,
|
|
939
936
|
environment: Optional[ModelVersionEnvironment] = None,
|
|
940
|
-
model_schema: Optional[Dict[str, Any]] = None,
|
|
941
937
|
) -> ModelVersion:
|
|
942
938
|
# TODO (chiragjn): Document mapping of framework to list of valid model save kwargs
|
|
943
939
|
# TODO (chiragjn): Add more examples
|
|
@@ -965,33 +961,7 @@ class MlFoundryRun:
|
|
|
965
961
|
Supported frameworks can be found in `truefoundry.ml.enums.ModelFramework`.
|
|
966
962
|
Can also be `None` if the framework is not known or not supported.
|
|
967
963
|
**Deprecated**: Prefer `ModelFrameworkType` over `enums.ModelFramework`.
|
|
968
|
-
additional_files (Sequence[Tuple[Union[str, Path], Optional[str]]], optional): A list of pairs
|
|
969
|
-
of (source path, destination path) to add additional files and folders
|
|
970
|
-
to the model version contents. The first member of the pair should be a file or directory path
|
|
971
|
-
and the second member should be the path inside the model versions contents to upload to.
|
|
972
|
-
The model version contents are arranged like follows
|
|
973
|
-
.
|
|
974
|
-
└── model/
|
|
975
|
-
└── # model files are serialized here
|
|
976
|
-
└── # any additional files and folders can be added here.
|
|
977
|
-
|
|
978
|
-
You can also add additional files to model/ subdirectory by specifying the destination path as model/
|
|
979
964
|
|
|
980
|
-
```
|
|
981
|
-
E.g. >>> run.log_model(
|
|
982
|
-
... name="xyz", model_file_or_folder="clf.joblib", framework="sklearn",
|
|
983
|
-
... additional_files=[("foo.txt", "foo/bar/foo.txt"), ("tokenizer/", "foo/tokenizer/")]
|
|
984
|
-
... )
|
|
985
|
-
would result in
|
|
986
|
-
.
|
|
987
|
-
├── model/
|
|
988
|
-
│ └── clf.joblib # if `model_file_or_folder` is a folder, contents will be added here
|
|
989
|
-
└── foo/
|
|
990
|
-
├── bar/
|
|
991
|
-
│ └── foo.txt
|
|
992
|
-
└── tokenizer/
|
|
993
|
-
└── # contents of tokenizer/ directory will be uploaded here
|
|
994
|
-
```
|
|
995
965
|
description (Optional[str], optional): arbitrary text upto 1024 characters to store as description.
|
|
996
966
|
This field can be updated at any time after logging. Defaults to `None`
|
|
997
967
|
metadata (Optional[Dict[str, Any]], optional): arbitrary json serializable dictionary to store metadata.
|
|
@@ -1084,14 +1054,12 @@ class MlFoundryRun:
|
|
|
1084
1054
|
run=self,
|
|
1085
1055
|
name=name,
|
|
1086
1056
|
model_file_or_folder=model_file_or_folder,
|
|
1087
|
-
additional_files=additional_files,
|
|
1088
1057
|
description=description,
|
|
1089
1058
|
metadata=metadata,
|
|
1090
1059
|
step=step,
|
|
1091
1060
|
progress=progress,
|
|
1092
1061
|
framework=framework,
|
|
1093
1062
|
environment=environment,
|
|
1094
|
-
model_schema=model_schema,
|
|
1095
1063
|
)
|
|
1096
1064
|
logger.info(f"Logged model successfully with fqn {model_version.fqn!r}")
|
|
1097
1065
|
return model_version
|