How to deal with artifact.wait() when running in mode "DISABLED"

During the preparation for a training (in prepare_data in pytorch lightning) I either create or update local data (download, prepare different encodings). I then create a W&B artifact and wait for the upload to be complete. Later in the code (in setup() in pytorch lightning) I use the data. Strictly speaking, this is not necessary, because I have the files locally, but I want to track the usage of the data (and the IDs of the data used for training, validation, …). I added the wait() statement, because wandb would download the previous version (v=n-1) of the data /without the enoding just added). In mode ONLINE this works nicely. However, in mode DISABLED I get this error: ValueError: Cannot call wait on an artifact before it has been logged or in offline mode. How am I supposed to handle wait()in order to have it work in all modes? (it would be nice if wait() would do it).

This is the sample code:

# Upload the data
artifact = wandb.Artifact(name=..., type=...)
artifact.description = ...
artifact.metadata = ...
artifact.add_file(local_path=...)  # I think I don't need this, playing around because of this issue
# Use (Download) the data
artifact = + ":latest")
artifact_entry = artifact.get_path(...)

Hey @hogru, “disabled” mode returns mocked objects and prevents all network communication. So when you call the log_artifact function, nothing will be logged which causes the error message when calling artifact.wait().

Hi @armanharutyunyan, I understand what’s going on and the technical reason for it, but what is your suggested way to deal with it? I need artifact.wait() when online, but need the code to work when offline. Is there a simple way to check the mode of wandb or see whether there are pending uploads or…? My question is how to handle the situation properly.

Hey @hogru, sorry about the late response. Runs have a disabled attribute. Here is a code snippet you can use:

run = wandb.init(mode="disabled")
if run.disabled:
    // your code

Ah, that definitely helps, thank you. And apparently there’s also run.offline. Thanks!

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