Sweep log code version

I would like to run a sweep from a repo, e.g. code/
I fetch the version of the code, e.g. HASH_1, and I also run the diff file between the hash and the remove branch and save it to a file.
Now I want to attach to this sweep the code version and the diff file.
I don’t want to do it on each run, because of unneeded duplication.

Is there a way to do this efficiently ? Attach artifacts to a sweep ?

Hello @pantelis-ai2c ,

Yes, you can use the wandb.Artifact API to create an artifact and attach files to it. Here’s an example of how you can do this:

import wandb

# Initialize a new run
run = wandb.init()

# Create a new artifact
artifact = wandb.Artifact('my_artifact', type='code')

# Add a file to the artifact
artifact.add_file('path/to/your/code.py')

# Log the artifact
run.log_artifact(artifact)

This will create a new artifact of type ‘code’ and add your code file to it. The artifact is then logged to the current run. You can add multiple files to the same artifact, which can be useful if you want to include additional files like a diff file.

If you want to avoid unnecessary duplication, you can use the wandb.Artifact API’s versioning capabilities. When you log an artifact, W&B checks if an artifact with the same name and type already exists. If it does, and the contents of the new artifact are identical to the existing one, W&B will not create a new version of the artifact. Instead, it will simply create a new reference to the existing artifact. This can help you avoid unnecessary duplication when logging artifacts.

I see. Thanks a lot.
I was not aware of this versioning capabilities. That would solve my problem.
Thank you.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.