truefoundry 0.3.4__py3-none-any.whl → 0.4.0__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/__init__.py +2 -0
- truefoundry/autodeploy/agents/developer.py +1 -1
- truefoundry/autodeploy/agents/project_identifier.py +2 -2
- truefoundry/autodeploy/agents/tester.py +1 -1
- truefoundry/autodeploy/cli.py +1 -1
- truefoundry/autodeploy/tools/list_files.py +1 -1
- truefoundry/cli/__main__.py +3 -17
- truefoundry/common/__init__.py +0 -0
- truefoundry/{deploy/lib/auth → common}/auth_service_client.py +50 -40
- truefoundry/common/constants.py +12 -0
- truefoundry/{deploy/lib/auth → common}/credential_file_manager.py +7 -7
- truefoundry/{deploy/lib/auth → common}/credential_provider.py +10 -23
- truefoundry/common/entities.py +124 -0
- truefoundry/common/exceptions.py +12 -0
- truefoundry/common/request_utils.py +84 -0
- truefoundry/common/servicefoundry_client.py +91 -0
- truefoundry/common/utils.py +56 -0
- truefoundry/deploy/auto_gen/models.py +4 -6
- truefoundry/deploy/cli/cli.py +3 -1
- truefoundry/deploy/cli/commands/apply_command.py +1 -1
- truefoundry/deploy/cli/commands/build_command.py +1 -1
- truefoundry/deploy/cli/commands/deploy_command.py +1 -1
- truefoundry/deploy/cli/commands/login_command.py +2 -2
- truefoundry/deploy/cli/commands/patch_application_command.py +1 -1
- truefoundry/deploy/cli/commands/patch_command.py +1 -1
- truefoundry/deploy/cli/commands/terminate_comand.py +1 -1
- truefoundry/deploy/cli/util.py +1 -1
- truefoundry/deploy/function_service/remote/remote.py +1 -1
- truefoundry/deploy/lib/auth/servicefoundry_session.py +2 -2
- truefoundry/deploy/lib/clients/servicefoundry_client.py +120 -159
- truefoundry/deploy/lib/const.py +1 -35
- truefoundry/deploy/lib/exceptions.py +0 -16
- truefoundry/deploy/lib/model/entity.py +1 -112
- truefoundry/deploy/lib/session.py +14 -42
- truefoundry/deploy/lib/util.py +0 -37
- truefoundry/{python_deploy_codegen.py → deploy/python_deploy_codegen.py} +2 -2
- truefoundry/deploy/v2/lib/deploy.py +3 -3
- truefoundry/deploy/v2/lib/deployable_patched_models.py +1 -1
- 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 +37 -6
- truefoundry/ml/artifact/__init__.py +0 -0
- truefoundry/ml/artifact/truefoundry_artifact_repo.py +1161 -0
- truefoundry/ml/autogen/__init__.py +0 -0
- truefoundry/ml/autogen/client/__init__.py +370 -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 +1944 -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 +341 -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/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 +65 -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 +65 -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 +67 -0
- truefoundry/ml/autogen/client/models/create_run_request_dto.py +97 -0
- truefoundry/ml/autogen/client/models/create_run_response_dto.py +75 -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 +75 -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 +73 -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 +170 -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 +75 -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 +320 -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/clients/__init__.py +0 -0
- truefoundry/ml/clients/entities.py +8 -0
- truefoundry/ml/clients/servicefoundry_client.py +45 -0
- truefoundry/ml/clients/utils.py +122 -0
- truefoundry/ml/constants.py +84 -0
- truefoundry/ml/entities.py +62 -0
- truefoundry/ml/enums.py +70 -0
- truefoundry/ml/env_vars.py +9 -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 +431 -0
- truefoundry/ml/log_types/artifacts/constants.py +33 -0
- truefoundry/ml/log_types/artifacts/dataset.py +384 -0
- truefoundry/ml/log_types/artifacts/general_artifact.py +110 -0
- truefoundry/ml/log_types/artifacts/model.py +611 -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 +357 -0
- truefoundry/ml/log_types/image/image_normalizer.py +102 -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/mlfoundry_api.py +1575 -0
- truefoundry/ml/mlfoundry_run.py +1203 -0
- truefoundry/ml/run_utils.py +93 -0
- truefoundry/ml/session.py +168 -0
- truefoundry/ml/validation_utils.py +346 -0
- truefoundry/pydantic_v1.py +6 -2
- truefoundry/workflow/__init__.py +16 -1
- {truefoundry-0.3.4.dist-info → truefoundry-0.4.0.dist-info}/METADATA +21 -14
- truefoundry-0.4.0.dist-info/RECORD +344 -0
- truefoundry/deploy/lib/clients/utils.py +0 -41
- truefoundry-0.3.4.dist-info/RECORD +0 -136
- {truefoundry-0.3.4.dist-info → truefoundry-0.4.0.dist-info}/WHEEL +0 -0
- {truefoundry-0.3.4.dist-info → truefoundry-0.4.0.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
import datetime
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import tempfile
|
|
6
|
+
import uuid
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import TYPE_CHECKING, Any, Dict, NamedTuple, Optional, Tuple, Union
|
|
9
|
+
|
|
10
|
+
from truefoundry.ml.artifact.truefoundry_artifact_repo import (
|
|
11
|
+
ArtifactIdentifier,
|
|
12
|
+
MlFoundryArtifactsRepository,
|
|
13
|
+
)
|
|
14
|
+
from truefoundry.ml.autogen.client import ( # type: ignore[attr-defined]
|
|
15
|
+
ArtifactDto,
|
|
16
|
+
ArtifactType,
|
|
17
|
+
ArtifactVersionDto,
|
|
18
|
+
CreateArtifactVersionRequestDto,
|
|
19
|
+
DeleteArtifactVersionsRequestDto,
|
|
20
|
+
FinalizeArtifactVersionRequestDto,
|
|
21
|
+
MlfoundryArtifactsApi,
|
|
22
|
+
NotifyArtifactVersionFailureDto,
|
|
23
|
+
UpdateArtifactVersionRequestDto,
|
|
24
|
+
)
|
|
25
|
+
from truefoundry.ml.autogen.client import ( # type: ignore[attr-defined]
|
|
26
|
+
InternalMetadata as InternalMetadataDto,
|
|
27
|
+
)
|
|
28
|
+
from truefoundry.ml.exceptions import MlFoundryException
|
|
29
|
+
from truefoundry.ml.log_types.artifacts.constants import INTERNAL_METADATA_PATH
|
|
30
|
+
from truefoundry.ml.log_types.artifacts.utils import (
|
|
31
|
+
_validate_artifact_metadata,
|
|
32
|
+
_validate_description,
|
|
33
|
+
calculate_local_directory_size,
|
|
34
|
+
)
|
|
35
|
+
from truefoundry.ml.logger import logger
|
|
36
|
+
from truefoundry.ml.session import _get_api_client
|
|
37
|
+
from truefoundry.pydantic_v1 import BaseModel, Extra
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING:
|
|
40
|
+
from truefoundry.ml.mlfoundry_run import MlFoundryRun
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ArtifactPath(NamedTuple):
|
|
44
|
+
src: str
|
|
45
|
+
dest: Optional[str] = None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ArtifactVersionInternalMetadata(BaseModel):
|
|
49
|
+
class Config:
|
|
50
|
+
extra = Extra.allow
|
|
51
|
+
|
|
52
|
+
files_dir: str # relative to root
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ArtifactVersionDownloadInfo(BaseModel):
|
|
56
|
+
download_dir: str
|
|
57
|
+
content_dir: str
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class ArtifactVersion:
|
|
61
|
+
def __init__(
|
|
62
|
+
self,
|
|
63
|
+
artifact_version: ArtifactVersionDto,
|
|
64
|
+
artifact: ArtifactDto,
|
|
65
|
+
) -> None:
|
|
66
|
+
self._api_client = _get_api_client()
|
|
67
|
+
self._mlfoundry_artifacts_api = MlfoundryArtifactsApi(
|
|
68
|
+
api_client=self._api_client
|
|
69
|
+
)
|
|
70
|
+
self._artifact_version: ArtifactVersionDto = artifact_version
|
|
71
|
+
self._artifact: ArtifactDto = artifact
|
|
72
|
+
self._deleted = False
|
|
73
|
+
self._description: str = ""
|
|
74
|
+
self._metadata: Dict[str, Any] = {}
|
|
75
|
+
self._set_mutable_attrs()
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
def from_fqn(cls, fqn: str) -> "ArtifactVersion":
|
|
79
|
+
"""
|
|
80
|
+
Get the version of an Artifact to download contents or load them in memory
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
fqn (str): Fully qualified name of the artifact version.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
ArtifactVersion: An ArtifactVersion instance of the artifact
|
|
87
|
+
|
|
88
|
+
Examples:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from truefoundry.ml import get_client, ArtifactVersion
|
|
92
|
+
|
|
93
|
+
client = get_client()
|
|
94
|
+
artifact_version = ArtifactVersion.from_fqn(fqn="<artifact-fqn>")
|
|
95
|
+
```
|
|
96
|
+
"""
|
|
97
|
+
api_client = _get_api_client()
|
|
98
|
+
mlfoundry_artifacts_api = MlfoundryArtifactsApi(api_client=api_client)
|
|
99
|
+
_artifact_version = mlfoundry_artifacts_api.get_artifact_version_by_fqn_get(
|
|
100
|
+
fqn=fqn
|
|
101
|
+
)
|
|
102
|
+
artifact_version = _artifact_version.artifact_version
|
|
103
|
+
_artifact = mlfoundry_artifacts_api.get_artifact_by_id_get(
|
|
104
|
+
id=artifact_version.artifact_id
|
|
105
|
+
)
|
|
106
|
+
return cls(
|
|
107
|
+
artifact_version=_artifact_version.artifact_version,
|
|
108
|
+
artifact=_artifact.artifact,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
def _ensure_not_deleted(self):
|
|
112
|
+
if self._deleted:
|
|
113
|
+
raise MlFoundryException(
|
|
114
|
+
"Artifact Version was deleted, cannot access a deleted version"
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def _set_mutable_attrs(self, refetch=False):
|
|
118
|
+
if refetch:
|
|
119
|
+
_artifact_version = (
|
|
120
|
+
self._mlfoundry_artifacts_api.get_artifact_version_by_id_get(
|
|
121
|
+
id=self._artifact_version.id
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
self._artifact_version = _artifact_version.artifact_version
|
|
125
|
+
self._description = self._artifact_version.description or ""
|
|
126
|
+
self._metadata = copy.deepcopy(self._artifact_version.artifact_metadata)
|
|
127
|
+
|
|
128
|
+
def __repr__(self):
|
|
129
|
+
return f"{self.__class__.__name__}(fqn={self.fqn!r})"
|
|
130
|
+
|
|
131
|
+
def _get_artifacts_repo(self):
|
|
132
|
+
return MlFoundryArtifactsRepository(
|
|
133
|
+
artifact_identifier=ArtifactIdentifier(
|
|
134
|
+
artifact_version_id=uuid.UUID(self._artifact_version.id)
|
|
135
|
+
),
|
|
136
|
+
api_client=self._api_client,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def name(self) -> str:
|
|
141
|
+
"""Get the name of the artifact"""
|
|
142
|
+
return self._artifact.name
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def artifact_fqn(self) -> str:
|
|
146
|
+
"""Get fqn of the artifact"""
|
|
147
|
+
return self._artifact.fqn
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def version(self) -> int:
|
|
151
|
+
"""Get version information of the artifact"""
|
|
152
|
+
return self._artifact_version.version
|
|
153
|
+
|
|
154
|
+
@property
|
|
155
|
+
def fqn(self) -> str:
|
|
156
|
+
"""Get fqn of the current artifact version"""
|
|
157
|
+
return self._artifact_version.fqn
|
|
158
|
+
|
|
159
|
+
@property
|
|
160
|
+
def step(self) -> int:
|
|
161
|
+
"""Get the step in which artifact was created"""
|
|
162
|
+
return self._artifact_version.step
|
|
163
|
+
|
|
164
|
+
@property
|
|
165
|
+
def description(self) -> Optional[str]:
|
|
166
|
+
"""Get description of the artifact"""
|
|
167
|
+
return self._description
|
|
168
|
+
|
|
169
|
+
@description.setter
|
|
170
|
+
def description(self, value: str):
|
|
171
|
+
"""set the description of the artifact"""
|
|
172
|
+
_validate_description(value)
|
|
173
|
+
self._description = value
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def metadata(self) -> Dict[str, Any]:
|
|
177
|
+
"""Get metadata for the current artifact"""
|
|
178
|
+
return self._metadata
|
|
179
|
+
|
|
180
|
+
@metadata.setter
|
|
181
|
+
def metadata(self, value: Dict[str, Any]):
|
|
182
|
+
"""set the metadata for current artifact"""
|
|
183
|
+
_validate_artifact_metadata(value)
|
|
184
|
+
self._metadata = value
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def created_by(self) -> str:
|
|
188
|
+
"""Get the information about who created the artifact"""
|
|
189
|
+
return self._artifact_version.created_by
|
|
190
|
+
|
|
191
|
+
@property
|
|
192
|
+
def created_at(self) -> datetime.datetime:
|
|
193
|
+
"""Get the time at which artifact was created"""
|
|
194
|
+
return self._artifact_version.created_at
|
|
195
|
+
|
|
196
|
+
@property
|
|
197
|
+
def updated_at(self) -> datetime.datetime:
|
|
198
|
+
"""Get the information about when the artifact was updated"""
|
|
199
|
+
return self._artifact_version.updated_at
|
|
200
|
+
|
|
201
|
+
def raw_download(
|
|
202
|
+
self,
|
|
203
|
+
path: Optional[Union[str, Path]],
|
|
204
|
+
overwrite: bool = False,
|
|
205
|
+
progress: Optional[bool] = None,
|
|
206
|
+
) -> str:
|
|
207
|
+
"""
|
|
208
|
+
Download an artifact file or directory to a local directory if applicable, and return a
|
|
209
|
+
local path for it.
|
|
210
|
+
|
|
211
|
+
Args:
|
|
212
|
+
path (str): Absolute path of the local filesystem destination directory to which to
|
|
213
|
+
download the specified artifacts. This directory must already exist.
|
|
214
|
+
If unspecified, the artifacts will either be downloaded to a new
|
|
215
|
+
uniquely-named directory on the local filesystem.
|
|
216
|
+
overwrite (bool): If True it will overwrite the file if it is already present in the download directory else
|
|
217
|
+
it will throw an error
|
|
218
|
+
progress (bool): value to show progress bar, defaults to None.
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
path: Absolute path of the local filesystem location containing the desired artifacts.
|
|
222
|
+
|
|
223
|
+
Examples:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from truefoundry.ml import get_client
|
|
227
|
+
|
|
228
|
+
client = get_client()
|
|
229
|
+
artifact_version = client.get_artifact_version_by_fqn(fqn="<your-artifact-fqn>")
|
|
230
|
+
artifact_version.raw_download(path="<your-desired-download-path>")
|
|
231
|
+
```
|
|
232
|
+
"""
|
|
233
|
+
logger.info(
|
|
234
|
+
"Downloading artifact version contents, this might take a while ..."
|
|
235
|
+
)
|
|
236
|
+
artifacts_repo = self._get_artifacts_repo()
|
|
237
|
+
return artifacts_repo.download_artifacts(
|
|
238
|
+
artifact_path="", dst_path=path, overwrite=overwrite, progress=progress
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
def _download(
|
|
242
|
+
self,
|
|
243
|
+
path: Optional[Union[str, Path]],
|
|
244
|
+
overwrite: bool = False,
|
|
245
|
+
progress: Optional[bool] = None,
|
|
246
|
+
) -> Tuple[ArtifactVersionInternalMetadata, str]:
|
|
247
|
+
self._ensure_not_deleted()
|
|
248
|
+
download_dir = self.raw_download(
|
|
249
|
+
path=path, overwrite=overwrite, progress=progress
|
|
250
|
+
)
|
|
251
|
+
internal_metadata_path = os.path.join(download_dir, INTERNAL_METADATA_PATH)
|
|
252
|
+
if not os.path.exists(internal_metadata_path):
|
|
253
|
+
raise MlFoundryException(
|
|
254
|
+
"Artifact version seems to be corrupted or in invalid format due to missing artifact metadata. "
|
|
255
|
+
"You can still use .raw_download(path='/your/path/here') to download and inspect files."
|
|
256
|
+
)
|
|
257
|
+
with open(internal_metadata_path) as f:
|
|
258
|
+
internal_metadata = ArtifactVersionInternalMetadata.parse_obj(json.load(f))
|
|
259
|
+
download_path = os.path.join(download_dir, internal_metadata.files_dir)
|
|
260
|
+
return internal_metadata, download_path
|
|
261
|
+
|
|
262
|
+
def download(
|
|
263
|
+
self,
|
|
264
|
+
path: Optional[Union[str, Path]] = None,
|
|
265
|
+
overwrite: bool = False,
|
|
266
|
+
progress: Optional[bool] = None,
|
|
267
|
+
) -> str:
|
|
268
|
+
"""
|
|
269
|
+
Download an artifact file or directory to a local directory if applicable, and return a
|
|
270
|
+
local path for it.
|
|
271
|
+
|
|
272
|
+
Args:
|
|
273
|
+
path (str): Absolute path of the local filesystem destination directory to which to
|
|
274
|
+
download the specified artifacts. This directory must already exist.
|
|
275
|
+
If unspecified, the artifacts will either be downloaded to a new
|
|
276
|
+
uniquely-named directory on the local filesystem or will be returned
|
|
277
|
+
directly in the case of the Local ArtifactRepository.
|
|
278
|
+
overwrite (bool): If True it will overwrite the file if it is already present in the download directory else
|
|
279
|
+
it will throw an error
|
|
280
|
+
progress (bool): value to show progress bar, defaults to None.
|
|
281
|
+
|
|
282
|
+
Returns:
|
|
283
|
+
path: Absolute path of the local filesystem location containing the desired artifacts.
|
|
284
|
+
|
|
285
|
+
Examples:
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
from truefoundry.ml import get_client
|
|
289
|
+
|
|
290
|
+
client = get_client()
|
|
291
|
+
artifact_version = client.get_artifact_version_by_fqn(fqn="<your-artifact-fqn>")
|
|
292
|
+
artifact_version.download(path="<your-desired-download-path>")
|
|
293
|
+
```
|
|
294
|
+
"""
|
|
295
|
+
_, download_path = self._download(
|
|
296
|
+
path=path, overwrite=overwrite, progress=progress
|
|
297
|
+
)
|
|
298
|
+
return download_path
|
|
299
|
+
|
|
300
|
+
def delete(self) -> bool:
|
|
301
|
+
"""
|
|
302
|
+
Deletes the current instance of the ArtifactVersion hence deleting the current version.
|
|
303
|
+
|
|
304
|
+
Returns:
|
|
305
|
+
True if artifact was deleted successfully
|
|
306
|
+
|
|
307
|
+
Examples:
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
from truefoundry.ml import get_client
|
|
311
|
+
|
|
312
|
+
client = get_client()
|
|
313
|
+
artifact_version = client.get_artifact_version_by_fqn(fqn="<your-artifact-fqn>")
|
|
314
|
+
artifact_version.delete()
|
|
315
|
+
```
|
|
316
|
+
"""
|
|
317
|
+
self._ensure_not_deleted()
|
|
318
|
+
self._mlfoundry_artifacts_api.delete_artifact_version_post(
|
|
319
|
+
delete_artifact_versions_request_dto=DeleteArtifactVersionsRequestDto(
|
|
320
|
+
id=self._artifact_version.id
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
self._deleted = True
|
|
324
|
+
return True
|
|
325
|
+
|
|
326
|
+
def update(self):
|
|
327
|
+
"""
|
|
328
|
+
Updates the current instance of the ArtifactVersion hence updating the current version.
|
|
329
|
+
|
|
330
|
+
Examples:
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
from truefoundry.ml import get_client
|
|
334
|
+
|
|
335
|
+
client = get_client()
|
|
336
|
+
artifact_version = client.get_artifact_version_by_fqn(fqn="<your-artifact-fqn>")
|
|
337
|
+
artifact_version.description = 'This is the new description'
|
|
338
|
+
artifact_version.update()
|
|
339
|
+
```
|
|
340
|
+
"""
|
|
341
|
+
self._ensure_not_deleted()
|
|
342
|
+
|
|
343
|
+
_artifact_version = self._mlfoundry_artifacts_api.update_artifact_version_post(
|
|
344
|
+
update_artifact_version_request_dto=UpdateArtifactVersionRequestDto(
|
|
345
|
+
id=self._artifact_version.id,
|
|
346
|
+
description=self.description,
|
|
347
|
+
artifact_metadata=self.metadata,
|
|
348
|
+
)
|
|
349
|
+
)
|
|
350
|
+
self._artifact_version = _artifact_version.artifact_version
|
|
351
|
+
self._set_mutable_attrs()
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def _log_artifact_version_helper(
|
|
355
|
+
run: "MlFoundryRun",
|
|
356
|
+
name: str,
|
|
357
|
+
artifact_type: ArtifactType,
|
|
358
|
+
artifact_dir: tempfile.TemporaryDirectory,
|
|
359
|
+
mlfoundry_artifacts_api: Optional[MlfoundryArtifactsApi] = None,
|
|
360
|
+
ml_repo_id: Optional[str] = None,
|
|
361
|
+
description: Optional[str] = None,
|
|
362
|
+
internal_metadata: Optional[BaseModel] = None,
|
|
363
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
364
|
+
step: int = 0,
|
|
365
|
+
progress: Optional[bool] = None,
|
|
366
|
+
) -> ArtifactVersion:
|
|
367
|
+
if (run and mlfoundry_artifacts_api) or (not run and not mlfoundry_artifacts_api):
|
|
368
|
+
raise MlFoundryException(
|
|
369
|
+
"Exactly one of run, mlfoundry_artifacts_api should be passed"
|
|
370
|
+
)
|
|
371
|
+
if mlfoundry_artifacts_api and not ml_repo_id:
|
|
372
|
+
raise MlFoundryException(
|
|
373
|
+
"If mlfoundry_artifacts_api is passed, ml_repo_id must also be passed"
|
|
374
|
+
)
|
|
375
|
+
if run:
|
|
376
|
+
mlfoundry_artifacts_api = run._mlfoundry_artifacts_api
|
|
377
|
+
|
|
378
|
+
assert mlfoundry_artifacts_api is not None
|
|
379
|
+
_create_artifact_response = mlfoundry_artifacts_api.create_artifact_version_post(
|
|
380
|
+
create_artifact_version_request_dto=CreateArtifactVersionRequestDto(
|
|
381
|
+
experiment_id=int(run._experiment_id if run else ml_repo_id),
|
|
382
|
+
name=name,
|
|
383
|
+
artifact_type=artifact_type,
|
|
384
|
+
)
|
|
385
|
+
)
|
|
386
|
+
version_id = _create_artifact_response.id
|
|
387
|
+
artifacts_repo = MlFoundryArtifactsRepository(
|
|
388
|
+
artifact_identifier=ArtifactIdentifier(
|
|
389
|
+
artifact_version_id=uuid.UUID(version_id),
|
|
390
|
+
),
|
|
391
|
+
api_client=mlfoundry_artifacts_api.api_client,
|
|
392
|
+
)
|
|
393
|
+
total_size = calculate_local_directory_size(artifact_dir)
|
|
394
|
+
try:
|
|
395
|
+
logger.info(
|
|
396
|
+
"Packaging and uploading files to remote with Artifact Size: %.6f MB",
|
|
397
|
+
total_size / 1000000.0,
|
|
398
|
+
)
|
|
399
|
+
artifacts_repo.log_artifacts(
|
|
400
|
+
local_dir=artifact_dir.name, artifact_path=None, progress=progress
|
|
401
|
+
)
|
|
402
|
+
except Exception as e:
|
|
403
|
+
mlfoundry_artifacts_api.notify_failure_post(
|
|
404
|
+
notify_artifact_version_failure_dto=NotifyArtifactVersionFailureDto(
|
|
405
|
+
id=version_id
|
|
406
|
+
)
|
|
407
|
+
)
|
|
408
|
+
raise MlFoundryException("Failed to log Artifact") from e
|
|
409
|
+
finally:
|
|
410
|
+
artifact_dir.cleanup()
|
|
411
|
+
|
|
412
|
+
# Note: Here we call from_dict instead of directly passing in init and relying on it
|
|
413
|
+
# to convert because the complicated union of types generates a custom type to handle casting
|
|
414
|
+
# Check the source of `InternalMetadataDto` to see the generated code
|
|
415
|
+
internal_metadata_dto = InternalMetadataDto.from_dict(
|
|
416
|
+
internal_metadata.dict() if internal_metadata is not None else {}
|
|
417
|
+
)
|
|
418
|
+
finalize_artifact_version_request_dto = FinalizeArtifactVersionRequestDto(
|
|
419
|
+
id=version_id,
|
|
420
|
+
run_uuid=run.run_id if run else None,
|
|
421
|
+
description=description,
|
|
422
|
+
internal_metadata=internal_metadata_dto,
|
|
423
|
+
artifact_metadata=metadata,
|
|
424
|
+
data_path=INTERNAL_METADATA_PATH,
|
|
425
|
+
step=step,
|
|
426
|
+
artifact_size=total_size,
|
|
427
|
+
)
|
|
428
|
+
_artifact_version = mlfoundry_artifacts_api.finalize_artifact_version_post(
|
|
429
|
+
finalize_artifact_version_request_dto=finalize_artifact_version_request_dto
|
|
430
|
+
)
|
|
431
|
+
return ArtifactVersion.from_fqn(fqn=_artifact_version.artifact_version.fqn)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.
|
|
3
|
+
├── .truefoundry/
|
|
4
|
+
│ └── metadata.json
|
|
5
|
+
└── files/
|
|
6
|
+
└── model/
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import posixpath
|
|
10
|
+
|
|
11
|
+
INTERNAL_METADATA_DIR = ".truefoundry"
|
|
12
|
+
INTERNAL_METADATA_FILE_NAME = "metadata.json"
|
|
13
|
+
INTERNAL_METADATA_PATH = posixpath.join(
|
|
14
|
+
INTERNAL_METADATA_DIR, INTERNAL_METADATA_FILE_NAME
|
|
15
|
+
)
|
|
16
|
+
FILES_DIR = "files"
|
|
17
|
+
MODEL_DIR_NAME = "model"
|
|
18
|
+
DESCRIPTION_MAX_LENGTH = 1024
|
|
19
|
+
|
|
20
|
+
# Link to docs here explaining schema consistency across model versions
|
|
21
|
+
MODEL_SCHEMA_UPDATE_FAILURE_HELP = """Model was logged successfully but failed to update the model schema because
|
|
22
|
+
it is inconsistent with the previous versions of the model. You can still fix the schema and update it using the
|
|
23
|
+
following:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
from truefoundry.ml import get_client
|
|
27
|
+
from truefoundry.ml import ModelVersion, ModelSchema, Feature, FeatureValueType, PredictionValueType
|
|
28
|
+
client = get_client()
|
|
29
|
+
model_version = ModelVersion(fqn="{fqn}")
|
|
30
|
+
model_version = ModelSchema(...) # or schema in dictionary format {{"features": [...], "prediction": ...}}
|
|
31
|
+
model_version.update()
|
|
32
|
+
```
|
|
33
|
+
"""
|