ML Repositories are backed by a blob storage. So, you need to have atleast one blob storage integration to create an ML Repo. You can follow the guides to integrate AWS S3, Google Cloud Storage, Azure Blob Storage or any S3 compatible storage to TrueFoundry.
You can then create an ML Repo from the ML Repo’s tab in the Platform.
You can use the code below to create a run, log metrics and parameters and then finally end the run.
Python
Copy
Ask AI
from truefoundry.ml import get_clientclient = get_client()# Create a new runrun = client.create_run(ml_repo="iris-demo", run_name="svm-model")# Log parametersrun.log_params({"learning_rate": 0.001})# Log metricsrun.log_metrics({"accuracy": 0.7, "loss": 0.6})# End the runrun.end()
Create and end a run
Python
Copy
Ask AI
from truefoundry.ml import get_clientclient = get_client()run = client.create_run(ml_repo="iris-demo", run_name="svm-model")# Your code here.run.end()
Add tags to a run
Copy
Ask AI
from truefoundry.ml import get_clientclient = get_client()run = client.create_run(ml_repo="iris-demo", run_name="svm-model")run.set_tags({"env": "development", "task": "classification"})# Your code here.run.end()
import osfrom truefoundry.ml import get_clientfrom truefoundry.ml import ArtifactPathclient = get_client()run = client.create_run(ml_repo="iris-demo", run_name="svm-model")run.log_params({"cache_size": 200.0, "kernel": "linear"})run.log_metrics(metric_dict={"accuracy": 0.7, "loss": 0.6})# Just creating sample files to log as artifacts# os.makedirs("my-folder", exist_ok=True)# with open("my-folder/file-inside-folder.txt", "w") as f:# f.write("Hello!")# with open("just-a-file.txt", "w") as f:# f.write("Hello from file!")artifact_version = run.log_artifact( name="my-artifact", artifact_paths=[ # Add files and folders here, `ArtifactPath` takes source and destination # source can be single file path or folder path # destination can be file path or folder path # Note: When source is a folder path, destination is always interpreted as folder path ArtifactPath(src="just-a-file.txt"), ArtifactPath(src="my-folder/", dest="cool-dir"), ArtifactPath(src="just-a-file.txt", dest="cool-dir/copied-file.txt") ], description="This is a sample artifact", metadata={"created_by": "my-username"})print(artifact_version.fqn)run.end()
This run will now appear on the TrueFoundry dashboard under ML Repos Tab.
Congratulations! You have successfully created a new ML repository. It is now ready for use, and you can start populating it with your data, code, models, and other related resources.