Downloading best sweep model from python

I have run a few sweeps, and now I want to get the best models from any given sweeps. I follow the tutorial here: and run my code as following

import wandb
api = wandb.Api()
runs = api.sweep(f"{team_name}/{project_name}/{sweep_id}").runs
run = sorted(runs, key=lambda run: run.summary.get("val_accuracy", 0), reverse=True)[0]

And I get a “Permission denied, ask the project owner to grant you access” error on the run.file().download(), even though I followed the tutorial. I tried this in two different settings, (1) in a team where I am the admin and (2) on my personal account (note that these are the “team_name” I am using in the api.sweep).

It does find my sweep and the runs, I can also see the validation accuracies of all runs, it just doesn’t allow me to download the files.

Furthermore, and this might be unrelated, whenever I try to inspect the run elements in my pycharm, the debugger crashes. This has never happened before, but it’s consistent on my machine, crashing my debugger every time

Hey @tjobbertjob,

You should be able to access your artifact through run.logged_artifacts(). I’ve written a small script for you (though you might have to edit it a little bit) to achieve this for you:

api = wandb.Api()

sweep = api.sweep(f'{entity}/{project}/{sweep_id}')
runs = sweep.runs

runs = sorted(runs, key = lambda run: run.summary.get('val_loss'))
best_run = runs[0]

artifacts = best_run.logged_artifacts()

best_model = [artifact for artifact in artifacts if artifact.type == 'model'][0]

Please let me know if this solves your issue.

Weights and Biases Support

The artifacts list is empty, I suspect this is because I never configured it to log or send any artifacts during my sweep? Sadly though, this answer doesn’t fix the issue due to that fact. Still have not figured out why I am getting an access error when trying to download from my own account.

I also tried it on my Linux server (my PC is windows), to see if it was machine specific, but it wasn’t. I get the exact same issue on the Linux server.

I see. In that case, could you check if you are able to access the name of the file you want to download through run.file?

It would also help if you could send over the full stack trace you received and the link of the project you are trying to download the file for.


Hi Tobias,

We wanted to follow up with you regarding your support request as we have not heard back from you. Please let us know if we can be of further assistance or if your issue has been resolved.

Weights & Biases

Hi Tobias, since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!

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