Downloading file in a subfolder, from a run

I have saved a folder to a run. Now how can I download a file from a subfolder?

This is my code:

import wandb
api_key = 'my_key'
wandb.login(key=api_key)
project_name = 'lexicap'
run_name = 'faithful-hill-1'
file_path = 'cwd/state_dict_1_audio.pt'
api = wandb.Api()
runs = api.runs(project_name)
run = [r for r in runs if r.name == run_name][0]
wandb.download(run.file(file_path))

By the last line I get:

Traceback (most recent call last):
  File "/root/lexicap/.venv/lib/python3.11/site-packages/wandb/sdk/lib/retry.py", line 131, in __call__
    result = self._call_fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/lexicap/.venv/lib/python3.11/site-packages/wandb/apis/public.py", line 2793, in download
    util.download_file_from_url(path, self.url, Api().api_key)
  File "/root/lexicap/.venv/lib/python3.11/site-packages/wandb/util.py", line 1299, in download_file_from_url
    response.raise_for_status()
  File "/root/lexicap/.venv/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.wandb.ai/files/majdoddin/lexicap/faithful-hill-1/cwd/state_dict_1_audio.pt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/root/lexicap/.venv/lib/python3.11/site-packages/wandb/apis/normalize.py", line 73, in wrapper
    raise err
  File "/root/lexicap/.venv/lib/python3.11/site-packages/wandb/apis/normalize.py", line 41, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/lexicap/.venv/lib/python3.11/site-packages/wandb/sdk/lib/retry.py", line 212, in wrapped_fn
    return retrier(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/lexicap/.venv/lib/python3.11/site-packages/wandb/sdk/lib/retry.py", line 147, in __call__
    retry_timedelta_triggered = check_retry_fn(e)
                                ^^^^^^^^^^^^^^^^^
  File "/root/lexicap/.venv/lib/python3.11/site-packages/wandb/util.py", line 888, in no_retry_auth
    raise CommError(
wandb.errors.CommError: It appears that you do not have permission to access the requested resource. Please reach out to the project owner to grant you access. If you have the correct permissions, verify that there are no issues with your networking setup.(Error 404: Not Found)

and f is
<File cwd/state_dict_1_audio.pt (None) 0.0B>

I think the problem is the subfolder, otherwise I can download the files in the root.

Your final line should be modified to something along the lines of the following:

run.file('state_dict_1_audio.pt').download()

Documentation

import wandb

api_key = 'my_key'
wandb.login(key=api_key)

project_name = 'lexicap'
run_name = 'faithful-hill-1'
file_path = 'cwd/state_dict_1_audio.pt'

api = wandb.Api()
runs = api.runs(project_name)
run = [r for r in runs if r.name == run_name][0]
run.file('state_dict_1_audio.pt').download()

Hi Ruhollah,

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.

Best,

Uma

Hi Uma,
I resolved the issue. The solution is on github repo

Great to hear, I will close out this ticket for now, but feel free to write back in if you have any other questions.

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