comet-ml / issue-tracking

Questions, Help, and Issues for Comet ML
https://www.comet.ml
85 stars 7 forks source link

Experiment created when downloading artifact #540

Closed AlexandreBrown closed 6 months ago

AlexandreBrown commented 6 months ago

Describe the Bug

When instantiating an Experiment class to download an artifact, the experiment gets created on cometml.com even tho I did not log anything.

Expected behavior

A dummy experiment should not be created every time we donwload an artifact.
No experiment should be created, we should be able to just download the artifact we want.

Where is the issue?

To Reproduce

Steps to reproduce the behavior:

experiment = Experiment(api_key=api_key, project_name=project_name, workspace=workspace)
artifact = experiment.get_artifact(artifact_name)
artifact.download(output_dir)

Comet Debug Log

comet.log

Screenshots or GIFs

image

Link to Comet Project/Experiment

Additional context

Using comet-ml version 3.38.1

Workaround

def download_artifact(api_key: str, project_name: str, workspace: str, artifact_name: str, output_dir: Path) -> Path: experiment = Experiment(api_key=api_key, project_name=project_name, workspace=workspace) artifact = experiment.get_artifact(artifact_name) artifact_path = Path(artifact.assets[0].logical_path) artifact.download(output_dir)

# Workaround for deleting the dummy experiment created during the download
api = API(api_key=api_key)
api.delete_experiment(experiment_key=experiment.get_key())

return output_dir / artifact_path
dsblank commented 6 months ago

@AlexandreBrown , indeed you are creating the experiment when you execute Experiment().

You can use the ExistingExperiment() or the APIExperiment() class interfaces. See https://www.comet.com/docs/v2/api-and-sdk/python-sdk/experiment-overview/

One way: https://www.comet.com/docs/v2/api-and-sdk/python-sdk/reference/ExistingExperiment/#existingexperimentget_artifact

from comet_ml import ExistingExperiment

experiment = ExistingExperiment(previous_experiment=KEY)
experiment.get_artifact(...)

Another way: https://www.comet.com/docs/v2/api-and-sdk/python-sdk/reference/API/#apiget_artifact_files

from comet_ml import API

api = API()
api.get_artifact_files("demo", artifact_name="demo-artifact", version="2.0.0")