How can I extract params from sweep and add them into name of wandb.init()

I am tuning hyper-params with wandb.sweep(). As I know the params are defined in sweep_id and insert into wandb.sweep() like this:

    sweep_configuration = {
    'method': 'bayes',
    'name': 'I dont believe that I can not just give you a name!',
    'metric': {'goal': 'minimize', 'name': 'Valid/final_ber'},
        'batch_size': {'distribution': 'int_uniform','min': 10,'max': 12},
        'lr': {'distribution': 'int_uniform','max': -3,'min': -4}
    sweep_id = wandb.sweep(sweep=sweep_configuration, project=args.project, entity=args.entity)

Now I what I want to do is to extract the params batch_size and lr from each sweep into the name of wand.init(), because I need these information in name of each run to identify them.
But in wandb frame, I cannot get access to the params in wandb.config before wandb.init(). As a result I cannot define argument name in wandb.init() with params which are given during each sweep.


Run wnb56ush errored: Error('You must call wandb.init() before')
wandb: ERROR Run wnb56ush errored: Error('You must call wandb.init() before')

Is there a way to get the params given by wandb.sweep() before wandb.init()?
Thanks at advance

Hi @1060111768 , it’s not possible to get the sweep parameters before calling wandb.init().

When you run wandb.sweep() to define a hyperparameter sweep, it generates a unique sweep ID that is used to link the sweep to the subsequent runs that are generated by the sweep. This sweep ID is used to retrieve the sweep parameters when you initialize WandB by calling wandb.init(). The wandb.init() function retrieves the sweep parameters from the WandB servers using the sweep ID, and uses them to configure the run. Once you have called wandb.init(), you can access the sweep parameters using the config object.

Instead of specifying a name in wandb init, rename the run immediately after initializing the run.

run =  wandb.init(config=config)"{}_{wandb.config.batch_size}"

Hi, @mohammadbakir
thanks very much for your advice! It works in my case :slight_smile:

1 Like

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