Providing agents with functions that need arguments

I’m not sure how to do this correctly but the answer provided in this post is wrong:

I want to raise this because this is the first result that comes up.

If I have a function train that requires arguments, the following will raise an error.

wandb.agent(
            sweep_id=sweep_id,
            function=train,
            count=count,
        )

Following the advice in the post I linked

wandb.agent(
            sweep_id=sweep_id,
            function=train(args),
            count=count,
        )

does NOT work. This will execute the train function! I do not want to execute the train function myself, I want wandb.agent to do that for me. My hack was to define global variables and have my train function use those, but I don’t love that solution. Either way, if you can still edit this answer or update the post, please do so @luis_bergua1

Hi @nishantaswani ,
To pass args to your training script, you can use command in your sweep config as follows.

For example:

program: main.py
metric:
  name: val_loss
  goal: minimize

method: bayes
parameters:
  optimizer.config.learning_rate:
    min: !!float 1e-5
    max: 0.1
  experiment:
    values: [expt001, expt002]
  optimizer:
    values: [sgd, adagrad, adam]

command:
- ${env}
- ${interpreter}
- ${program}
- ${args}

The ${args} key expands to all the parameters in the sweep configuration file, expanded so they can be parsed by argparse: --param1 value1 --param2 value2

Docs link for reference.

Please let us know if this helps.

Hi @nishantaswani , I wanted to follow up on this request. Please let us know if we can be of further assistance or if your issue has been resolved.

Hi @nishantaswani , 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!