> For the complete documentation index, see [llms.txt](https://arig23498.gitbook.io/aritra-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://arig23498.gitbook.io/aritra-documentation/ref/python/sweep.md).

# wandb.sweep

[![](https://www.tensorflow.org/images/GitHub-Mark-32px.png)View source on GitHub](https://www.github.com/wandb/client/tree/v0.10.31.dev1/wandb/wandb_controller.py#L740-L806)

Initialize a hyperparameter sweep.

```python
sweep(
    sweep, entity=None, project=None
)
```

To generate hyperparameter suggestions from the sweep and use them to train a model, call `wandb.agent` with the sweep\_id returned by this command. For command line functionality, see the command line tool `wandb sweep` (<https://docs.wandb.ai/ref/cli/wandb-sweep>).

| Args      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `sweep`   | dict, SweepConfig, or callable. The sweep configuration (or configuration generator). If a dict or SweepConfig, should conform to the W\&B sweep config specification (<https://docs.wandb.ai/guides/sweeps/configuration>). If a callable, should take no arguments and return a dict that conforms to the W\&B sweep config spec.                                                                                                                                                                                                                                      |
| `entity`  | str (optional). An entity is a username or team name where you're sending runs. This entity must exist before you can send runs there, so make sure to create your account or team in the UI before starting to log runs. If you don't specify an entity, the run will be sent to your default entity, which is usually your username. Change your default entity in [Settings](https://github.com/ariG23498/Aritra-Documentation/tree/e42c5da5fca12cc96212fd417dfb12ddb2c8f5a5/ref/python/wandb.ai/settings/README.md) under "default location to create new projects". |
| `project` | str (optional). The name of the project where you're sending the new run. If the project is not specified, the run is put in an "Uncategorized" project.                                                                                                                                                                                                                                                                                                                                                                                                                 |

| Returns    |                                         |
| ---------- | --------------------------------------- |
| `sweep_id` | str. A unique identifier for the sweep. |

## Examples:

Basic usage

```python
# this line initializes the sweep
sweep_id = wandb.sweep({'name': 'my-awesome-sweep',
                        'metric': 'accuracy',
                        'method': 'grid',
                        'parameters': {'a': {'values': [1, 2, 3, 4]}}})

# this line actually runs it -- parameters are available to
# my_train_func via wandb.config
wandb.agent(sweep_id, function=my_train_func)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://arig23498.gitbook.io/aritra-documentation/ref/python/sweep.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
