Clarity on wandb offline

Hi,

I was using wandb offline on kaggle. During submission time Internet has to be disabled I noticed that even if you mention the wandb key in secrets, it won’t be able to fetch it because

user_secrets = UserSecretsClient()
wandb_api = user_secrets.get_secret("wandb_api")

user_secrets.get_secret requires an active internet connection.

It took me some time to find out that we can specify a dummy key like this to login in offline mode:

key='X'*40
wandb.login(key=key)

If my understanding is correct, Can we please update the same information on wandb offline documentation page with a subsection on kaggle?

Thanks!

2 Likes

Hey, you are correct that Kaggle User Secrets cannot be used when the internet is turned off. I tried it myself and running a cell with the code snippet shown below throw the ConnectionError: Connection error trying to communicate with service error.

I don’t think you need to log in to use W&B offline. The whole idea of using offline mode is to write metrics easily on a disk which can later be synced online with a single command line.

Over Kaggle, if you have turned off the internet (submission kernel) you simply need to do these steps:

import wandb
print(wandb.__version__)
>>> 0.10.33 # Note that the Kaggle W&B version is always few versions old but we can't pip install. 

!wandb offline
>>> W&B offline, running your script from this directory will only write metadata locally.

# Example logging
wandb.init()
for i in range(10):
    wandb.log({"i": i})
wandb.finish()

>>> wandb sync /kaggle/working/wandb/offline-run-20210906_152752-3mkpi45e # You get the path to the directory where the run is saved. 

I made this kernel to show the flow. Let me know if it’s what you are trying to do.

I have a question from you - Why do you want to use W&B with the submission kernel? Would love to know your thoughts.

2 Likes

Thanks for the notebook. 2 kernels are good but that’s not always the case. :smiley:

Sometimes when I create a baseline, I tend to create a single kernel to keep it simple just like here. If you edit, you will be able to see the below code I used to setup wandb.

#Intialize wandb run

if config['use_wandb']:
    import wandb
    from wandb.keras import WandbCallback
    from kaggle_secrets import UserSecretsClient
    

    if config['wandb_mode'] == 'offline':
        os.environ["WANDB_MODE"] = "offline"
        key='X'*40
        wandb.login(key=key)
    else:
        user_secrets = UserSecretsClient()
        wandb_api = user_secrets.get_secret("wandb_api")
        wandb.login(key=wandb_api)

    run = wandb.init(project='chaii', 
                     group =config['group'], 
                     job_type='train',
                     config = config)

    LOGGER.info("Wandb is initialized")
1 Like

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