# Sweep main function with arguments

**URL:** <https://community.wandb.ai/t/sweep-main-function-with-arguments/4723>\
**Category:** W&B Help\
**Tags:** sweeps\
**Created:** [July 12, 2023, 5:47pm UTC](https://community.wandb.ai/t/sweep-main-function-with-arguments/4723 "2023-07-12T17:47:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aletl](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@aletl](https://community.wandb.ai/u/aletl)\
**Post date:** [July 12, 2023, 5:47pm UTC](https://community.wandb.ai/t/sweep-main-function-with-arguments/4723/1 "2023-07-12T17:47:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![raphael-sanandres](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@raphael-sanandres](https://community.wandb.ai/u/raphael-sanandres)\
**Post date:** [July 13, 2023, 8:02pm UTC](https://community.wandb.ai/t/sweep-main-function-with-arguments/4723/2 "2023-07-13T20:02:12Z")

</div>

Hello @aletl !

Firstly, our [Quickstart](https://docs.wandb.ai/guides/sweeps/quickstart) or [Add W&B to your code](https://docs.wandb.ai/guides/sweeps/add-w-and-b-to-your-code#original-training-script) 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.

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![raphael-sanandres](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@raphael-sanandres](https://community.wandb.ai/u/raphael-sanandres)\
**Post date:** [July 17, 2023, 5:33pm UTC](https://community.wandb.ai/t/sweep-main-function-with-arguments/4723/3 "2023-07-17T17:33:36Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/wandb/original/1X/366b649231631dbab896843020da0056074ac79d.png) [@system](https://community.wandb.ai/u/system)\
**Post date:** [September 11, 2023, 8:02pm UTC](https://community.wandb.ai/t/sweep-main-function-with-arguments/4723/4 "2023-09-11T20:02:23Z")

</div>

Closed on September 11, 2023, 8:02pm UTC

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