Sweep main function with arguments

Hello,

I am trying to use the sweeps for doing hyperparameter search. I have a problem that is that my main function receives two arguments: config and data. Therefore, my call should be something like: wandb.agent(sweep_id, function=train_hparams_sweep(data), count=10). But in that case, wandb.config is empty. While if I call wandb.agent(sweep_id, function=train_hparams_sweep, count=10), if returns error cause there’s an argument missing.

Which is the right way of handling this?

Hello @aletl !

Firstly, our Quickstart or Add W&B to your code guides should be very helpful for you.

Iff your data is consistent, I would advise grabbing your data from within the function itself and letting wandb.config store your config values.

import wandb
wandb.login()

def main():
    wandb.init(project='my-first-sweep')
    # Import data here and do training here
    # If you want to grab x from the config, write in `config['x']` 
    wandb.log({'score': score})

sweep_configuration = {
    # Your sweep configuration over two hyper parameters, x and y
}

sweep_id = wandb.sweep(
    sweep=sweep_configuration, 
    project='my-first-sweep'
    )

wandb.agent(sweep_id, function=main, count=10)
1 Like

Hi aletl, 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.