MlFoundry.

Properties

Methods

Returns a list of names of ML Repos accessible by the current user.

Returns

return
List[str]

Usage

from truefoundry.ml import get_client

client = get_client()

# Get all ML repos accessible by the current user
ml_repos = client.list_ml_repos()
print(f'Found {len(ml_repos)} ML repos:')
for repo in ml_repos:
    print(f'  - {repo}')
Creates an ML Repository.

Parameters

name
str
required
storage_integration_fqn
str
required
description
Optional[str]
default:"None"

Returns

return
None

Usage

from truefoundry.ml import get_client

client = get_client()

# Create a new ML repository
client.create_ml_repo(
    name="my-ml-repo",
    storage_integration_fqn="your-storage-integration-fqn",
    description="My ML repository for experiments"
)
Initialize a run.

Parameters

ml_repo
str
required
run_name
Optional[str]
default:"None"
tags
Optional[Dict[str, Any]]
default:"None"

Returns

return
MlFoundryRun

Usage

from truefoundry.ml import get_client

client = get_client()

client.create_run(
    ml_repo="my-ml-repo",
    run_name="my-run",
    tags={"key": "value"},
)
Get an existing run by the run_id.

Parameters

run_id
str
required

Returns

return
MlFoundryRun

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_run_by_id(
    run_id="run-id-123",
)
Get an existing run by fqn.

Parameters

run_fqn
str
required

Returns

return
MlFoundryRun

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_run_by_fqn(
    run_fqn="value",
)
Get an existing run by run_name.

Parameters

ml_repo
str
required
run_name
str
required

Returns

return
MlFoundryRun

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_run_by_name(
    ml_repo="my-ml-repo",
    run_name="my-run",
)
The user must have READ access to the ML Repo.

Parameters

ml_repo
str
required
filter_string
str
run_view_type
ViewType
default:"value"
order_by
Sequence[str]
default:"..."
job_run_name
Optional[str]
default:"None"

Returns

return
Iterator[MlFoundryRun]

Usage

from truefoundry.ml import get_client

client = get_client()

client.search_runs(
    ml_repo="my-ml-repo",
    filter_string="value",
    run_view_type="value",
    order_by="value",
    job_run_name="value",
)

# Iterate through results
for item in response:
    print(item.name)
Get the model version to download contents or load it in memory

Parameters

ml_repo
str
required
name
str
required
version
Union[str, int]
default:"constants.LATEST_ARTIFACT_OR_MODEL_VERSION"

Returns

return
Optional[ModelVersion]

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_model_version(
    ml_repo="my-ml-repo",
    name="my-run",
    version="value",
)
Get the model version to download contents or load it in memory

Parameters

fqn
str
required

Returns

return
ModelVersion

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_model_version_by_fqn(
    fqn="run-id-123",
)
Get all the version of a model to download contents or load them in memory

Parameters

ml_repo
str
required
name
str
required

Returns

return
Iterator[ModelVersion]

Usage

from truefoundry.ml import get_client

client = get_client()

client.list_model_versions(
    ml_repo="my-ml-repo",
    name="my-run",
)
List versions for a given model

Parameters

model_fqn
str
required

Returns

return
Iterator[ModelVersion]

Usage

from truefoundry.ml import get_client

client = get_client()

client.list_model_versions_by_fqn(
    model_fqn="value",
)
Get the model version to download contents or load it in memory

Parameters

ml_repo
str
required
name
str
required
artifact_type
Optional[ArtifactType]
default:"ArtifactType.ARTIFACT"
version
Union[str, int]
default:"constants.LATEST_ARTIFACT_OR_MODEL_VERSION"

Returns

return
Optional[ArtifactVersion]

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_artifact_version(
    ml_repo="my-ml-repo",
    name="my-run",
    artifact_type="value",
    version="value",
)
Get the artifact version to download contents

Parameters

fqn
str
required

Returns

return
ArtifactVersion

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_artifact_version_by_fqn(
    fqn="run-id-123",
)
Get all the version of na artifact to download contents or load them in memory

Parameters

ml_repo
str
required
name
str
required
artifact_type
Optional[ArtifactType]
default:"ArtifactType.ARTIFACT"

Returns

return
Iterator[ArtifactVersion]

Usage

from truefoundry.ml import get_client

client = get_client()

client.list_artifact_versions(
    ml_repo="my-ml-repo",
    name="my-run",
    artifact_type="value",
)
List versions for a given artifact

Parameters

artifact_fqn
str
required

Returns

return
Iterator[ArtifactVersion]

Usage

from truefoundry.ml import get_client

client = get_client()

client.list_artifact_versions_by_fqn(
    artifact_fqn="value",
)
Logs an artifact for the current ml_repo.

Parameters

ml_repo
str
required
name
str
required
artifact_paths
List[Union[Tuple[str], Tuple[str, Optional[str]], ArtifactPath]]
required
description
Optional[str]
default:"None"
metadata
Optional[Dict[str, Any]]
default:"None"
progress
Optional[bool]
default:"None"

Returns

return
Optional[ArtifactVersion]

Usage

from truefoundry.ml import get_client

client = get_client()

client.log_artifact(
    ml_repo="my-ml-repo",
    name="my-run",
    artifact_paths=[ArtifactPath("file.txt")],
    description="value",
    metadata="value",
    progress="value",
)
Serialize and log a versioned model under the current ml_repo. Each logged model generates a new version

Parameters

ml_repo
str
required
name
str
required
model_file_or_folder
Union[str, BlobStorageDirectory]
required
description
Optional[str]
default:"None"
metadata
Optional[Dict[str, Any]]
default:"None"
progress
Optional[bool]
default:"None"
framework
Optional[Union[str, ModelFramework, Any]]
default:"None"
environment
Optional[ModelVersionEnvironment]
default:"None"

Returns

return
ModelVersion

Usage

from truefoundry.ml import get_client

client = get_client()

client.log_model(
    ml_repo="my-ml-repo",
    name="my-run",
    model_file_or_folder="model.pkl",
    description="value",
    metadata="value",
    progress="value",
    framework="value",
    environment="value",
)
Create DataDirectory to Upload the files

Parameters

ml_repo
str
required
name
str
required
description
Optional[str]
default:"None"
metadata
Optional[Dict[str, Any]]
default:"None"

Returns

return
DataDirectory

Usage

from truefoundry.ml import get_client

client = get_client()

client.create_data_directory(
    ml_repo="my-ml-repo",
    name="my-run",
    description="value",
    metadata="value",
)
Get the DataDirectory by DataDirectory FQN

Parameters

fqn
str
required

Returns

return
DataDirectory

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_data_directory_by_fqn(
    fqn="run-id-123",
)
Get an existing data_directory by name.

Parameters

ml_repo
str
required
name
str
required

Returns

return
DataDirectory

Usage

from truefoundry.ml import get_client

client = get_client()

client.get_data_directory(
    ml_repo="my-ml-repo",
    name="my-run",
)
Get the list of DataDirectory in a ml_repo

Parameters

ml_repo
str
required

Returns

return
Iterator[DataDirectory]

Usage

from truefoundry.ml import get_client

client = get_client()

client.list_data_directories(
    ml_repo="my-ml-repo",
)