truefoundry 0.3.2__py3-none-any.whl → 0.4.0.dev0__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/cli/__main__.py +3 -17
- truefoundry/common/__init__.py +0 -0
- truefoundry/common/request_utils.py +56 -0
- truefoundry/deploy/auto_gen/models.py +29 -1
- truefoundry/deploy/cli/cli.py +1 -1
- truefoundry/deploy/lib/auth/credential_provider.py +2 -12
- truefoundry/deploy/lib/clients/servicefoundry_client.py +0 -9
- truefoundry/deploy/lib/exceptions.py +1 -6
- truefoundry/deploy/lib/session.py +1 -16
- truefoundry/{python_deploy_codegen.py → deploy/python_deploy_codegen.py} +1 -0
- truefoundry/langchain/truefoundry_chat.py +1 -1
- truefoundry/langchain/truefoundry_embeddings.py +1 -1
- truefoundry/langchain/truefoundry_llm.py +1 -1
- truefoundry/langchain/utils.py +0 -41
- truefoundry/ml/__init__.py +46 -6
- truefoundry/ml/artifact/__init__.py +0 -0
- truefoundry/ml/artifact/truefoundry_artifact_repo.py +1120 -0
- truefoundry/ml/autogen/__init__.py +0 -0
- truefoundry/ml/autogen/client/__init__.py +373 -0
- truefoundry/ml/autogen/client/api/__init__.py +16 -0
- truefoundry/ml/autogen/client/api/auth_api.py +184 -0
- truefoundry/ml/autogen/client/api/deprecated_api.py +605 -0
- truefoundry/ml/autogen/client/api/experiments_api.py +2109 -0
- truefoundry/ml/autogen/client/api/health_api.py +299 -0
- truefoundry/ml/autogen/client/api/metrics_api.py +371 -0
- truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +7213 -0
- truefoundry/ml/autogen/client/api/python_deployment_config_api.py +201 -0
- truefoundry/ml/autogen/client/api/run_artifacts_api.py +231 -0
- truefoundry/ml/autogen/client/api/runs_api.py +2919 -0
- truefoundry/ml/autogen/client/api_client.py +822 -0
- truefoundry/ml/autogen/client/api_response.py +30 -0
- truefoundry/ml/autogen/client/configuration.py +489 -0
- truefoundry/ml/autogen/client/exceptions.py +161 -0
- truefoundry/ml/autogen/client/models/__init__.py +344 -0
- truefoundry/ml/autogen/client/models/add_custom_metrics_to_model_version_request_dto.py +69 -0
- truefoundry/ml/autogen/client/models/add_features_to_model_version_request_dto.py +83 -0
- truefoundry/ml/autogen/client/models/agent.py +125 -0
- truefoundry/ml/autogen/client/models/agent_app.py +118 -0
- truefoundry/ml/autogen/client/models/agent_open_api_tool.py +143 -0
- truefoundry/ml/autogen/client/models/agent_open_api_tool_with_fqn.py +144 -0
- truefoundry/ml/autogen/client/models/agent_with_fqn.py +127 -0
- truefoundry/ml/autogen/client/models/artifact_dto.py +115 -0
- truefoundry/ml/autogen/client/models/artifact_response_dto.py +75 -0
- truefoundry/ml/autogen/client/models/artifact_type.py +39 -0
- truefoundry/ml/autogen/client/models/artifact_version_dto.py +141 -0
- truefoundry/ml/autogen/client/models/artifact_version_response_dto.py +77 -0
- truefoundry/ml/autogen/client/models/artifact_version_status.py +35 -0
- truefoundry/ml/autogen/client/models/assistant_message.py +89 -0
- truefoundry/ml/autogen/client/models/authorize_user_for_model_request_dto.py +69 -0
- truefoundry/ml/autogen/client/models/authorize_user_for_model_version_request_dto.py +69 -0
- truefoundry/ml/autogen/client/models/backfill_default_storage_integration_id_request_dto.py +67 -0
- truefoundry/ml/autogen/client/models/blob_storage_reference.py +93 -0
- truefoundry/ml/autogen/client/models/body_get_search_runs_get.py +72 -0
- truefoundry/ml/autogen/client/models/chat_prompt.py +156 -0
- truefoundry/ml/autogen/client/models/chat_prompt_messages_inner.py +171 -0
- truefoundry/ml/autogen/client/models/columns_dto.py +73 -0
- truefoundry/ml/autogen/client/models/content.py +153 -0
- truefoundry/ml/autogen/client/models/content1.py +153 -0
- truefoundry/ml/autogen/client/models/content2.py +174 -0
- truefoundry/ml/autogen/client/models/content2_any_of_inner.py +150 -0
- truefoundry/ml/autogen/client/models/create_artifact_request_dto.py +74 -0
- truefoundry/ml/autogen/client/models/create_artifact_response_dto.py +66 -0
- truefoundry/ml/autogen/client/models/create_artifact_version_request_dto.py +74 -0
- truefoundry/ml/autogen/client/models/create_artifact_version_response_dto.py +66 -0
- truefoundry/ml/autogen/client/models/create_dataset_request_dto.py +76 -0
- truefoundry/ml/autogen/client/models/create_experiment_request_dto.py +94 -0
- truefoundry/ml/autogen/client/models/create_experiment_response_dto.py +67 -0
- truefoundry/ml/autogen/client/models/create_model_version_request_dto.py +95 -0
- truefoundry/ml/autogen/client/models/create_multi_part_upload_for_dataset_request_dto.py +73 -0
- truefoundry/ml/autogen/client/models/create_multi_part_upload_for_dataset_response_dto.py +79 -0
- truefoundry/ml/autogen/client/models/create_multi_part_upload_request_dto.py +73 -0
- truefoundry/ml/autogen/client/models/create_python_deployment_config_request_dto.py +72 -0
- truefoundry/ml/autogen/client/models/create_python_deployment_config_response_dto.py +68 -0
- truefoundry/ml/autogen/client/models/create_run_request_dto.py +97 -0
- truefoundry/ml/autogen/client/models/create_run_response_dto.py +76 -0
- truefoundry/ml/autogen/client/models/dataset_dto.py +112 -0
- truefoundry/ml/autogen/client/models/dataset_response_dto.py +75 -0
- truefoundry/ml/autogen/client/models/delete_artifact_versions_request_dto.py +65 -0
- truefoundry/ml/autogen/client/models/delete_dataset_request_dto.py +74 -0
- truefoundry/ml/autogen/client/models/delete_model_version_request_dto.py +65 -0
- truefoundry/ml/autogen/client/models/delete_run_request.py +65 -0
- truefoundry/ml/autogen/client/models/delete_tag_request_dto.py +68 -0
- truefoundry/ml/autogen/client/models/experiment_dto.py +127 -0
- truefoundry/ml/autogen/client/models/experiment_id_request_dto.py +67 -0
- truefoundry/ml/autogen/client/models/experiment_response_dto.py +75 -0
- truefoundry/ml/autogen/client/models/experiment_tag_dto.py +69 -0
- truefoundry/ml/autogen/client/models/feature_dto.py +68 -0
- truefoundry/ml/autogen/client/models/feature_value_type.py +35 -0
- truefoundry/ml/autogen/client/models/file_info_dto.py +76 -0
- truefoundry/ml/autogen/client/models/finalize_artifact_version_request_dto.py +101 -0
- truefoundry/ml/autogen/client/models/get_experiment_response_dto.py +88 -0
- truefoundry/ml/autogen/client/models/get_latest_run_log_response_dto.py +76 -0
- truefoundry/ml/autogen/client/models/get_metric_history_response.py +79 -0
- truefoundry/ml/autogen/client/models/get_signed_url_for_dataset_write_request_dto.py +68 -0
- truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_read_request_dto.py +68 -0
- truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_read_response_dto.py +81 -0
- truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_write_request_dto.py +69 -0
- truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_write_response_dto.py +83 -0
- truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_read_request_dto.py +68 -0
- truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_read_response_dto.py +81 -0
- truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_write_response_dto.py +81 -0
- truefoundry/ml/autogen/client/models/get_tenant_id_response_dto.py +74 -0
- truefoundry/ml/autogen/client/models/http_validation_error.py +82 -0
- truefoundry/ml/autogen/client/models/image_content_part.py +87 -0
- truefoundry/ml/autogen/client/models/image_url.py +75 -0
- truefoundry/ml/autogen/client/models/internal_metadata.py +180 -0
- truefoundry/ml/autogen/client/models/latest_run_log_dto.py +78 -0
- truefoundry/ml/autogen/client/models/list_artifact_versions_request_dto.py +107 -0
- truefoundry/ml/autogen/client/models/list_artifact_versions_response_dto.py +87 -0
- truefoundry/ml/autogen/client/models/list_artifacts_request_dto.py +96 -0
- truefoundry/ml/autogen/client/models/list_artifacts_response_dto.py +86 -0
- truefoundry/ml/autogen/client/models/list_colums_response_dto.py +75 -0
- truefoundry/ml/autogen/client/models/list_datasets_request_dto.py +78 -0
- truefoundry/ml/autogen/client/models/list_datasets_response_dto.py +86 -0
- truefoundry/ml/autogen/client/models/list_experiments_response_dto.py +86 -0
- truefoundry/ml/autogen/client/models/list_files_for_artifact_version_request_dto.py +76 -0
- truefoundry/ml/autogen/client/models/list_files_for_artifact_versions_response_dto.py +82 -0
- truefoundry/ml/autogen/client/models/list_files_for_dataset_request_dto.py +76 -0
- truefoundry/ml/autogen/client/models/list_files_for_dataset_response_dto.py +82 -0
- truefoundry/ml/autogen/client/models/list_latest_run_logs_response_dto.py +82 -0
- truefoundry/ml/autogen/client/models/list_metric_history_request_dto.py +69 -0
- truefoundry/ml/autogen/client/models/list_metric_history_response_dto.py +84 -0
- truefoundry/ml/autogen/client/models/list_model_version_response_dto.py +87 -0
- truefoundry/ml/autogen/client/models/list_model_versions_request_dto.py +93 -0
- truefoundry/ml/autogen/client/models/list_models_request_dto.py +89 -0
- truefoundry/ml/autogen/client/models/list_models_response_dto.py +84 -0
- truefoundry/ml/autogen/client/models/list_run_artifacts_response_dto.py +84 -0
- truefoundry/ml/autogen/client/models/list_run_logs_response_dto.py +82 -0
- truefoundry/ml/autogen/client/models/list_seed_experiments_response_dto.py +81 -0
- truefoundry/ml/autogen/client/models/log_batch_request_dto.py +106 -0
- truefoundry/ml/autogen/client/models/log_metric_request_dto.py +80 -0
- truefoundry/ml/autogen/client/models/log_param_request_dto.py +76 -0
- truefoundry/ml/autogen/client/models/method.py +37 -0
- truefoundry/ml/autogen/client/models/metric_collection_dto.py +82 -0
- truefoundry/ml/autogen/client/models/metric_dto.py +76 -0
- truefoundry/ml/autogen/client/models/mime_type.py +37 -0
- truefoundry/ml/autogen/client/models/model_configuration.py +103 -0
- truefoundry/ml/autogen/client/models/model_dto.py +122 -0
- truefoundry/ml/autogen/client/models/model_response_dto.py +75 -0
- truefoundry/ml/autogen/client/models/model_schema_dto.py +85 -0
- truefoundry/ml/autogen/client/models/model_version_dto.py +163 -0
- truefoundry/ml/autogen/client/models/model_version_response_dto.py +75 -0
- truefoundry/ml/autogen/client/models/multi_part_upload_dto.py +107 -0
- truefoundry/ml/autogen/client/models/multi_part_upload_response_dto.py +79 -0
- truefoundry/ml/autogen/client/models/multi_part_upload_storage_provider.py +34 -0
- truefoundry/ml/autogen/client/models/notify_artifact_version_failure_dto.py +65 -0
- truefoundry/ml/autogen/client/models/openapi_spec.py +152 -0
- truefoundry/ml/autogen/client/models/param_dto.py +66 -0
- truefoundry/ml/autogen/client/models/parameters.py +84 -0
- truefoundry/ml/autogen/client/models/prediction_type.py +34 -0
- truefoundry/ml/autogen/client/models/resolve_agent_app_response_dto.py +75 -0
- truefoundry/ml/autogen/client/models/restore_run_request_dto.py +65 -0
- truefoundry/ml/autogen/client/models/run_data_dto.py +104 -0
- truefoundry/ml/autogen/client/models/run_dto.py +84 -0
- truefoundry/ml/autogen/client/models/run_info_dto.py +105 -0
- truefoundry/ml/autogen/client/models/run_log_dto.py +90 -0
- truefoundry/ml/autogen/client/models/run_log_input_dto.py +80 -0
- truefoundry/ml/autogen/client/models/run_response_dto.py +75 -0
- truefoundry/ml/autogen/client/models/run_tag_dto.py +66 -0
- truefoundry/ml/autogen/client/models/search_runs_request_dto.py +94 -0
- truefoundry/ml/autogen/client/models/search_runs_response_dto.py +84 -0
- truefoundry/ml/autogen/client/models/set_experiment_tag_request_dto.py +73 -0
- truefoundry/ml/autogen/client/models/set_tag_request_dto.py +76 -0
- truefoundry/ml/autogen/client/models/signed_url_dto.py +69 -0
- truefoundry/ml/autogen/client/models/stop.py +152 -0
- truefoundry/ml/autogen/client/models/store_run_logs_request_dto.py +83 -0
- truefoundry/ml/autogen/client/models/system_message.py +89 -0
- truefoundry/ml/autogen/client/models/text.py +153 -0
- truefoundry/ml/autogen/client/models/text_content_part.py +84 -0
- truefoundry/ml/autogen/client/models/update_artifact_version_request_dto.py +74 -0
- truefoundry/ml/autogen/client/models/update_dataset_request_dto.py +74 -0
- truefoundry/ml/autogen/client/models/update_experiment_request_dto.py +74 -0
- truefoundry/ml/autogen/client/models/update_model_version_request_dto.py +93 -0
- truefoundry/ml/autogen/client/models/update_run_request_dto.py +78 -0
- truefoundry/ml/autogen/client/models/update_run_response_dto.py +76 -0
- truefoundry/ml/autogen/client/models/url.py +153 -0
- truefoundry/ml/autogen/client/models/user_message.py +89 -0
- truefoundry/ml/autogen/client/models/validation_error.py +87 -0
- truefoundry/ml/autogen/client/models/validation_error_loc_inner.py +154 -0
- truefoundry/ml/autogen/client/rest.py +426 -0
- truefoundry/ml/autogen/client_README.md +322 -0
- truefoundry/ml/cli/__init__.py +0 -0
- truefoundry/ml/cli/cli.py +18 -0
- truefoundry/ml/cli/commands/__init__.py +3 -0
- truefoundry/ml/cli/commands/download.py +87 -0
- truefoundry/ml/constants.py +84 -0
- truefoundry/ml/enums.py +70 -0
- truefoundry/ml/env_vars.py +13 -0
- truefoundry/ml/exceptions.py +8 -0
- truefoundry/ml/git_info.py +60 -0
- truefoundry/ml/internal_namespace.py +52 -0
- truefoundry/ml/log_types/__init__.py +4 -0
- truefoundry/ml/log_types/artifacts/artifact.py +427 -0
- truefoundry/ml/log_types/artifacts/constants.py +33 -0
- truefoundry/ml/log_types/artifacts/dataset.py +383 -0
- truefoundry/ml/log_types/artifacts/general_artifact.py +110 -0
- truefoundry/ml/log_types/artifacts/model.py +628 -0
- truefoundry/ml/log_types/artifacts/model_extras.py +48 -0
- truefoundry/ml/log_types/artifacts/utils.py +161 -0
- truefoundry/ml/log_types/image/__init__.py +3 -0
- truefoundry/ml/log_types/image/constants.py +8 -0
- truefoundry/ml/log_types/image/image.py +358 -0
- truefoundry/ml/log_types/image/image_normalizer.py +101 -0
- truefoundry/ml/log_types/image/types.py +68 -0
- truefoundry/ml/log_types/plot.py +281 -0
- truefoundry/ml/log_types/pydantic_base.py +10 -0
- truefoundry/ml/log_types/utils.py +12 -0
- truefoundry/ml/logger.py +17 -0
- truefoundry/ml/login.py +241 -0
- truefoundry/ml/mlfoundry_api.py +1620 -0
- truefoundry/ml/mlfoundry_run.py +1238 -0
- truefoundry/ml/run_utils.py +102 -0
- truefoundry/ml/services/__init__.py +0 -0
- truefoundry/ml/services/auth_service.py +109 -0
- truefoundry/ml/services/entities.py +108 -0
- truefoundry/ml/services/servicefoundry_service.py +35 -0
- truefoundry/ml/services/utils.py +122 -0
- truefoundry/ml/session.py +271 -0
- truefoundry/ml/validation_utils.py +346 -0
- truefoundry/pydantic_v1.py +5 -1
- {truefoundry-0.3.2.dist-info → truefoundry-0.4.0.dev0.dist-info}/METADATA +19 -12
- truefoundry-0.4.0.dev0.dist-info/RECORD +342 -0
- truefoundry-0.3.2.dist-info/RECORD +0 -136
- {truefoundry-0.3.2.dist-info → truefoundry-0.4.0.dev0.dist-info}/WHEEL +0 -0
- {truefoundry-0.3.2.dist-info → truefoundry-0.4.0.dev0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
import copy
|
|
3
|
+
import datetime
|
|
4
|
+
import tempfile
|
|
5
|
+
from typing import Any, Dict, Iterator, List, NamedTuple, Optional, Tuple, Union
|
|
6
|
+
from warnings import warn
|
|
7
|
+
|
|
8
|
+
from truefoundry.ml.artifact.truefoundry_artifact_repo import (
|
|
9
|
+
ArtifactIdentifier,
|
|
10
|
+
MlFoundryArtifactsRepository,
|
|
11
|
+
)
|
|
12
|
+
from truefoundry.ml.autogen.client import ( # type: ignore[attr-defined]
|
|
13
|
+
DatasetDto,
|
|
14
|
+
DeleteDatasetRequestDto,
|
|
15
|
+
FileInfoDto,
|
|
16
|
+
MlfoundryArtifactsApi,
|
|
17
|
+
UpdateDatasetRequestDto,
|
|
18
|
+
)
|
|
19
|
+
from truefoundry.ml.exceptions import MlFoundryException
|
|
20
|
+
from truefoundry.ml.log_types.artifacts.utils import (
|
|
21
|
+
_copy_additional_files,
|
|
22
|
+
_validate_artifact_metadata,
|
|
23
|
+
_validate_description,
|
|
24
|
+
calculate_local_directory_size,
|
|
25
|
+
)
|
|
26
|
+
from truefoundry.ml.logger import logger
|
|
27
|
+
from truefoundry.ml.session import _get_api_client
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class DataDirectoryPath(NamedTuple):
|
|
31
|
+
src: str
|
|
32
|
+
dest: Optional[str] = None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class DataDirectory:
|
|
36
|
+
def __init__(self, dataset: DatasetDto) -> None:
|
|
37
|
+
self._api_client = _get_api_client()
|
|
38
|
+
self._mlfoundry_artifacts_api = MlfoundryArtifactsApi(
|
|
39
|
+
api_client=self._api_client
|
|
40
|
+
)
|
|
41
|
+
self._dataset = dataset
|
|
42
|
+
self._description: str = ""
|
|
43
|
+
self._deleted = False
|
|
44
|
+
self._metadata: Dict[str, Any] = {}
|
|
45
|
+
self._set_mutable_attrs()
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def from_fqn(cls, fqn: str):
|
|
49
|
+
"""
|
|
50
|
+
Get the DataDirectory to download contents or load them in memory
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
fqn (str): Fully qualified name of the data directory.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
DataDirectory: An DataDirectory instance of the artifact
|
|
57
|
+
|
|
58
|
+
Examples:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from truefoundry.ml import get_client, DataDirectory
|
|
62
|
+
|
|
63
|
+
client = get_client()
|
|
64
|
+
data_directory = DataDirectory.from_fqn(fqn="<data_directory-fqn>")
|
|
65
|
+
```
|
|
66
|
+
"""
|
|
67
|
+
api_client = _get_api_client()
|
|
68
|
+
mlfoundry_artifacts_api = MlfoundryArtifactsApi(api_client=api_client)
|
|
69
|
+
_dataset = mlfoundry_artifacts_api.get_dataset_by_fqn_get(fqn=fqn)
|
|
70
|
+
return cls(_dataset.dataset)
|
|
71
|
+
|
|
72
|
+
def __repr__(self):
|
|
73
|
+
return f"{self.__class__.__name__}(fqn={self.fqn!r})"
|
|
74
|
+
|
|
75
|
+
def _set_mutable_attrs(self, refetch=False):
|
|
76
|
+
if refetch:
|
|
77
|
+
_dataset = self._mlfoundry_artifacts_api.get_dataset_by_fqn_get(
|
|
78
|
+
fqn=self._dataset.fqn
|
|
79
|
+
)
|
|
80
|
+
self._dataset = _dataset.dataset
|
|
81
|
+
self._description = self._dataset.description or ""
|
|
82
|
+
self._metadata = copy.deepcopy(self._dataset.dataset_metadata)
|
|
83
|
+
|
|
84
|
+
def _get_artifacts_repo(self):
|
|
85
|
+
return MlFoundryArtifactsRepository(
|
|
86
|
+
artifact_identifier=ArtifactIdentifier(dataset_fqn=self._dataset.fqn),
|
|
87
|
+
api_client=self._api_client,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def name(self) -> str:
|
|
92
|
+
"""Get the name of the DataDirectory"""
|
|
93
|
+
return self._dataset.name
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def fqn(self) -> str:
|
|
97
|
+
"""Get fqn of the DataDirectory"""
|
|
98
|
+
return self._dataset.fqn
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def storage_root(self) -> str:
|
|
102
|
+
"""Get storage_root of the DataDirectory"""
|
|
103
|
+
return self._dataset.storage_root
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def description(self) -> Optional[str]:
|
|
107
|
+
"""Get description of the DataDirectory"""
|
|
108
|
+
return self._description
|
|
109
|
+
|
|
110
|
+
@description.setter
|
|
111
|
+
def description(self, value: str):
|
|
112
|
+
"""set the description of the DataDirectory"""
|
|
113
|
+
_validate_description(value)
|
|
114
|
+
self._description = value
|
|
115
|
+
|
|
116
|
+
@property
|
|
117
|
+
def metadata(self) -> Dict[str, Any]:
|
|
118
|
+
"""Get metadata for the current DataDirectory"""
|
|
119
|
+
return self._metadata
|
|
120
|
+
|
|
121
|
+
@metadata.setter
|
|
122
|
+
def metadata(self, value: Dict[str, Any]):
|
|
123
|
+
"""set the metadata for current DataDirectory"""
|
|
124
|
+
_validate_artifact_metadata(value)
|
|
125
|
+
self._metadata = value
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def created_by(self) -> str:
|
|
129
|
+
"""Get the information about who created the DataDirectory"""
|
|
130
|
+
return self._dataset.created_by
|
|
131
|
+
|
|
132
|
+
@property
|
|
133
|
+
def created_at(self) -> datetime.datetime:
|
|
134
|
+
"""Get the time at which DataDirectory was created"""
|
|
135
|
+
return self._dataset.created_at
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def updated_at(self) -> datetime.datetime:
|
|
139
|
+
"""Get the information about the when the DataDirectory was updated"""
|
|
140
|
+
return self._dataset.updated_at
|
|
141
|
+
|
|
142
|
+
def add_files(
|
|
143
|
+
self,
|
|
144
|
+
file_paths: List[
|
|
145
|
+
Union[Tuple[str], Tuple[str, Optional[str]], DataDirectoryPath]
|
|
146
|
+
],
|
|
147
|
+
) -> None:
|
|
148
|
+
"""Logs File in the `DataDirectory`.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
file_paths (List[truefoundry.ml.DataDirectoryPath], optional): A list of pairs
|
|
152
|
+
of (source path, destination path) to add files and folders to the DataDirectory contents.
|
|
153
|
+
The first member of the pair should be a file or directory path and the second member should be
|
|
154
|
+
the path inside the artifact contents to upload to.
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from truefoundry.ml import DataDirectoryPath
|
|
158
|
+
|
|
159
|
+
data_directory.add_files(
|
|
160
|
+
file_paths=[
|
|
161
|
+
DataDirectoryPath("foo.txt", "foo/bar/foo.txt"),
|
|
162
|
+
DataDirectoryPath("tokenizer/", "foo/tokenizer/"),
|
|
163
|
+
DataDirectoryPath('bar.text'),
|
|
164
|
+
('bar.txt', ),
|
|
165
|
+
('foo.txt', 'a/foo.txt')
|
|
166
|
+
]
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
would result in
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
.
|
|
174
|
+
└── foo/
|
|
175
|
+
├── bar/
|
|
176
|
+
│ └── foo.txt
|
|
177
|
+
└── tokenizer/
|
|
178
|
+
└── # contents of tokenizer/ directory will be uploaded here
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Examples:
|
|
182
|
+
```python
|
|
183
|
+
import os
|
|
184
|
+
from truefoundry.ml import get_client, DataDirectoryPath
|
|
185
|
+
|
|
186
|
+
with open("artifact.txt", "w") as f:
|
|
187
|
+
f.write("hello-world")
|
|
188
|
+
|
|
189
|
+
client = get_client()
|
|
190
|
+
data_directory = client.get_data_directory_by_fqn(fqn="<data_directory-fqn>")
|
|
191
|
+
|
|
192
|
+
data_directory.add_files(
|
|
193
|
+
file_paths=[DataDirectoryPath('artifact.txt', 'a/b/')]
|
|
194
|
+
)
|
|
195
|
+
```
|
|
196
|
+
"""
|
|
197
|
+
for i, file_path in enumerate(file_paths):
|
|
198
|
+
if isinstance(file_path, DataDirectoryPath):
|
|
199
|
+
continue
|
|
200
|
+
elif isinstance(file_path, collections.abc.Sequence) and (
|
|
201
|
+
0 < len(file_path) <= 2
|
|
202
|
+
):
|
|
203
|
+
file_paths[i] = DataDirectoryPath(*file_path)
|
|
204
|
+
else:
|
|
205
|
+
raise ValueError(
|
|
206
|
+
"`file_paths` should be an instance of `truefoundry.ml.DataDirectoryPath` "
|
|
207
|
+
"or a tuple of (src, dest) path strings"
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
logger.info("Adding the files to data_directory, this might take a while ...")
|
|
211
|
+
temp_dir = tempfile.TemporaryDirectory(prefix="truefoundry-")
|
|
212
|
+
|
|
213
|
+
try:
|
|
214
|
+
logger.info("Copying the files to add")
|
|
215
|
+
_copy_additional_files(
|
|
216
|
+
root_dir=temp_dir.name,
|
|
217
|
+
files_dir="",
|
|
218
|
+
model_dir=None,
|
|
219
|
+
additional_files=file_paths,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
except Exception as e:
|
|
223
|
+
temp_dir.cleanup()
|
|
224
|
+
raise MlFoundryException("Failed to Add Files to DataDirectory") from e
|
|
225
|
+
|
|
226
|
+
artifacts_repo = self._get_artifacts_repo()
|
|
227
|
+
total_size = calculate_local_directory_size(temp_dir)
|
|
228
|
+
try:
|
|
229
|
+
logger.info(
|
|
230
|
+
"Packaging and uploading files to remote with Size: %.6f MB",
|
|
231
|
+
total_size / 1000000.0,
|
|
232
|
+
)
|
|
233
|
+
artifacts_repo.log_artifacts(local_dir=temp_dir.name, artifact_path=None)
|
|
234
|
+
except Exception as e:
|
|
235
|
+
raise MlFoundryException("Failed to Add Files to DataDirectory") from e
|
|
236
|
+
finally:
|
|
237
|
+
temp_dir.cleanup()
|
|
238
|
+
|
|
239
|
+
def list_files(
|
|
240
|
+
self,
|
|
241
|
+
path: Optional[str] = None,
|
|
242
|
+
) -> Iterator[FileInfoDto]:
|
|
243
|
+
"""
|
|
244
|
+
List all the files and folders in the data_directory.
|
|
245
|
+
|
|
246
|
+
Args:
|
|
247
|
+
path: The path of directory in data_directory, from which the files are to be listed.
|
|
248
|
+
|
|
249
|
+
Returns:
|
|
250
|
+
Iterator[FileInfoDto]: List of FileInfo objects that contain path and file_size attributes.
|
|
251
|
+
|
|
252
|
+
Examples:
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from truefoundry.ml import get_client
|
|
256
|
+
|
|
257
|
+
client = get_client()
|
|
258
|
+
data_directory = client.get_data_directory_by_fqn(fqn="<your-artifact-fqn>")
|
|
259
|
+
files = data_directory.list_files()
|
|
260
|
+
for file in files:
|
|
261
|
+
print(file.path)
|
|
262
|
+
```
|
|
263
|
+
"""
|
|
264
|
+
artifacts_repo = self._get_artifacts_repo()
|
|
265
|
+
return artifacts_repo.list_artifacts(path=path)
|
|
266
|
+
|
|
267
|
+
def download(
|
|
268
|
+
self,
|
|
269
|
+
remote_path: Optional[str] = "",
|
|
270
|
+
path: Optional[str] = None,
|
|
271
|
+
overwrite: bool = False,
|
|
272
|
+
progress: Optional[bool] = None,
|
|
273
|
+
download_path: Optional[str] = "",
|
|
274
|
+
):
|
|
275
|
+
"""
|
|
276
|
+
Download a file or directory to a local directory if applicable, and return a
|
|
277
|
+
local path for it.
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
download_path: (deprecated) Relative source path to the desired files.
|
|
281
|
+
remote_path: Relative source path to the desired files.
|
|
282
|
+
path: Absolute path of the local filesystem destination directory to which to
|
|
283
|
+
download the specified files. This directory must already exist.
|
|
284
|
+
If unspecified, the files will either be downloaded to a new
|
|
285
|
+
uniquely-named directory.
|
|
286
|
+
overwrite: if to overwrite the files at/inside `dst_path` if they exist
|
|
287
|
+
progress: value to show progress bar, defaults to None.
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
str: Absolute path of the local filesystem location containing the desired files or folder.
|
|
291
|
+
|
|
292
|
+
Examples:
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
from truefoundry.ml import get_client
|
|
296
|
+
|
|
297
|
+
client = get_client()
|
|
298
|
+
data_directory = client.get_data_directory_by_fqn(fqn="<your-data_directory-fqn>")
|
|
299
|
+
data_directory.download(download_path="<your-desired-download-path>")
|
|
300
|
+
```
|
|
301
|
+
"""
|
|
302
|
+
self._ensure_not_deleted()
|
|
303
|
+
artifacts_repo = self._get_artifacts_repo()
|
|
304
|
+
if download_path != "" and remote_path != "":
|
|
305
|
+
raise ValueError(
|
|
306
|
+
"Only one of 'download_path' or 'remote_path' should be specified."
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
if download_path != "":
|
|
310
|
+
warn(
|
|
311
|
+
"`download_path` is deprecated, please use `remote_path` instead.",
|
|
312
|
+
DeprecationWarning,
|
|
313
|
+
stacklevel=2,
|
|
314
|
+
)
|
|
315
|
+
remote_path = download_path
|
|
316
|
+
|
|
317
|
+
return artifacts_repo.download_artifacts(
|
|
318
|
+
artifact_path=remote_path,
|
|
319
|
+
dst_path=path,
|
|
320
|
+
overwrite=overwrite,
|
|
321
|
+
progress=progress,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
def update(self):
|
|
325
|
+
"""
|
|
326
|
+
Updates the current instance of the DataDirectory.
|
|
327
|
+
|
|
328
|
+
Examples:
|
|
329
|
+
|
|
330
|
+
```python
|
|
331
|
+
from truefoundry.ml import get_client
|
|
332
|
+
|
|
333
|
+
client = get_client()
|
|
334
|
+
data_directory = client.get_data_directory_by_fqn(fqn="<your-data-directory-fqn>")
|
|
335
|
+
data_directory.description = 'This is the new description'
|
|
336
|
+
data_directory.update()
|
|
337
|
+
```
|
|
338
|
+
"""
|
|
339
|
+
self._ensure_not_deleted()
|
|
340
|
+
_dataset = self._mlfoundry_artifacts_api.update_dataset_post(
|
|
341
|
+
update_dataset_request_dto=UpdateDatasetRequestDto(
|
|
342
|
+
fqn=self._dataset.fqn,
|
|
343
|
+
description=self.description,
|
|
344
|
+
dataset_metadata=self.metadata,
|
|
345
|
+
)
|
|
346
|
+
)
|
|
347
|
+
self._dataset = _dataset.dataset
|
|
348
|
+
self._set_mutable_attrs()
|
|
349
|
+
|
|
350
|
+
def _ensure_not_deleted(self):
|
|
351
|
+
if self._deleted:
|
|
352
|
+
raise MlFoundryException(
|
|
353
|
+
"Data Directory was deleted, cannot access a deleted version"
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
def delete(self, delete_contents: bool = False) -> bool:
|
|
357
|
+
"""
|
|
358
|
+
Deletes the current instance of the DataDirectory.
|
|
359
|
+
|
|
360
|
+
Args:
|
|
361
|
+
delete_contents: set it to true to delete the contents in storage integration. Default is False.
|
|
362
|
+
|
|
363
|
+
Returns:
|
|
364
|
+
True if artifact was deleted successfully
|
|
365
|
+
|
|
366
|
+
Examples:
|
|
367
|
+
|
|
368
|
+
```python
|
|
369
|
+
from truefoundry.ml import get_client
|
|
370
|
+
|
|
371
|
+
client = get_client()
|
|
372
|
+
dataset = client.get_data_directory_by_fqn(fqn="<your-data-directory-fqn>")
|
|
373
|
+
dataset.delete()
|
|
374
|
+
```
|
|
375
|
+
"""
|
|
376
|
+
self._ensure_not_deleted()
|
|
377
|
+
self._mlfoundry_artifacts_api.delete_dataset_post(
|
|
378
|
+
delete_dataset_request_dto=DeleteDatasetRequestDto(
|
|
379
|
+
id=self._dataset.id, delete_contents=delete_contents
|
|
380
|
+
)
|
|
381
|
+
)
|
|
382
|
+
self._deleted = True
|
|
383
|
+
return True
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
import json
|
|
3
|
+
import os.path
|
|
4
|
+
import tempfile
|
|
5
|
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
6
|
+
|
|
7
|
+
from truefoundry.ml.autogen.client import ( # type: ignore[attr-defined]
|
|
8
|
+
ArtifactType,
|
|
9
|
+
MlfoundryArtifactsApi,
|
|
10
|
+
)
|
|
11
|
+
from truefoundry.ml.exceptions import MlFoundryException
|
|
12
|
+
from truefoundry.ml.log_types.artifacts.artifact import (
|
|
13
|
+
ArtifactPath,
|
|
14
|
+
ArtifactVersion,
|
|
15
|
+
ArtifactVersionInternalMetadata,
|
|
16
|
+
_log_artifact_version_helper,
|
|
17
|
+
)
|
|
18
|
+
from truefoundry.ml.log_types.artifacts.constants import (
|
|
19
|
+
FILES_DIR,
|
|
20
|
+
INTERNAL_METADATA_PATH,
|
|
21
|
+
)
|
|
22
|
+
from truefoundry.ml.log_types.artifacts.utils import (
|
|
23
|
+
_copy_additional_files,
|
|
24
|
+
_validate_artifact_metadata,
|
|
25
|
+
_validate_description,
|
|
26
|
+
)
|
|
27
|
+
from truefoundry.ml.logger import logger
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _log_artifact_version(
|
|
31
|
+
run,
|
|
32
|
+
name: str,
|
|
33
|
+
artifact_paths: List[Union[ArtifactPath, Tuple[str, Optional[str]], Tuple[str]]],
|
|
34
|
+
mlfoundry_artifacts_api: Optional[MlfoundryArtifactsApi] = None,
|
|
35
|
+
ml_repo_id: Optional[str] = None,
|
|
36
|
+
description: Optional[str] = None,
|
|
37
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
38
|
+
step: Optional[int] = 0,
|
|
39
|
+
progress: Optional[bool] = None,
|
|
40
|
+
) -> ArtifactVersion:
|
|
41
|
+
if (run and mlfoundry_artifacts_api) or (not run and not mlfoundry_artifacts_api):
|
|
42
|
+
raise MlFoundryException(
|
|
43
|
+
"Exactly one of run, mlfoundry_artifacts_api should be passed"
|
|
44
|
+
)
|
|
45
|
+
if mlfoundry_artifacts_api and not ml_repo_id:
|
|
46
|
+
raise MlFoundryException(
|
|
47
|
+
"If mlfoundry_artifacts_api is passed, ml_repo_id must also be passed"
|
|
48
|
+
)
|
|
49
|
+
for i, artifact_path in enumerate(artifact_paths):
|
|
50
|
+
if isinstance(artifact_path, ArtifactPath):
|
|
51
|
+
continue
|
|
52
|
+
elif isinstance(artifact_path, collections.abc.Sequence) and (
|
|
53
|
+
0 < len(artifact_path) <= 2
|
|
54
|
+
):
|
|
55
|
+
artifact_paths[i] = ArtifactPath(*artifact_path)
|
|
56
|
+
else:
|
|
57
|
+
raise ValueError(
|
|
58
|
+
"`artifact_path` should be an instance of `truefoundry.ml.ArtifactPath` or a tuple "
|
|
59
|
+
"of (src, dest) path strings"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
metadata = metadata or {}
|
|
63
|
+
step = step or 0 # TODO (chiragjn): remove Optional from step
|
|
64
|
+
|
|
65
|
+
_validate_description(description)
|
|
66
|
+
_validate_artifact_metadata(metadata)
|
|
67
|
+
|
|
68
|
+
logger.info("Logging the artifact, this might take a while ...")
|
|
69
|
+
temp_dir = tempfile.TemporaryDirectory(prefix="truefoundry-")
|
|
70
|
+
|
|
71
|
+
internal_metadata = ArtifactVersionInternalMetadata(
|
|
72
|
+
files_dir=FILES_DIR,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
local_files_dir = os.path.join(temp_dir.name, internal_metadata.files_dir)
|
|
77
|
+
os.makedirs(local_files_dir, exist_ok=True)
|
|
78
|
+
|
|
79
|
+
logger.info("Copying the files to log")
|
|
80
|
+
_copy_additional_files(
|
|
81
|
+
root_dir=temp_dir.name,
|
|
82
|
+
files_dir=internal_metadata.files_dir,
|
|
83
|
+
model_dir=None,
|
|
84
|
+
additional_files=artifact_paths,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# TODO(nikp1172) verify error message when artifact doesn't exist
|
|
88
|
+
except Exception as e:
|
|
89
|
+
temp_dir.cleanup()
|
|
90
|
+
raise MlFoundryException("Failed to log artifact") from e
|
|
91
|
+
|
|
92
|
+
# save internal metadata
|
|
93
|
+
local_internal_metadata_path = os.path.join(temp_dir.name, INTERNAL_METADATA_PATH)
|
|
94
|
+
os.makedirs(os.path.dirname(local_internal_metadata_path), exist_ok=True)
|
|
95
|
+
with open(local_internal_metadata_path, "w") as f:
|
|
96
|
+
json.dump(internal_metadata.dict(), f)
|
|
97
|
+
|
|
98
|
+
return _log_artifact_version_helper(
|
|
99
|
+
run=run,
|
|
100
|
+
ml_repo_id=ml_repo_id,
|
|
101
|
+
name=name,
|
|
102
|
+
artifact_type=ArtifactType.ARTIFACT,
|
|
103
|
+
artifact_dir=temp_dir,
|
|
104
|
+
mlfoundry_artifacts_api=mlfoundry_artifacts_api,
|
|
105
|
+
description=description,
|
|
106
|
+
internal_metadata=internal_metadata,
|
|
107
|
+
metadata=metadata,
|
|
108
|
+
step=step,
|
|
109
|
+
progress=progress,
|
|
110
|
+
)
|