> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-hivemind-launch.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# How do I set default hyperparameter values in a sweep?

You don't need to provide values for every hyperparameter in a W\&B Sweep. You can set defaults and let the sweep override them.

Access hyperparameter names and values from the sweep configuration using `run.config`, which acts like a dictionary.

For runs outside a sweep, set `run.config` values by passing a dictionary to the `config` argument in `wandb.init()`. In a sweep, any configuration you pass to `wandb.init()` serves as a default value that the sweep can override.

Use `run.config.setdefaults()` for explicit behavior. The following code snippets illustrate both methods:

<Tabs>
  <Tab title="wandb.init()">
    ```python theme={null}
    # Set default values for hyperparameters
    config_defaults = {"lr": 0.1, "batch_size": 256}

    # Start a run and provide defaults
    # that a sweep can override
    with wandb.init(config=config_defaults) as run:
        # Add training code here
        ...
    ```
  </Tab>

  <Tab title="config.setdefaults()">
    ```python theme={null}
    # Set default values for hyperparameters
    config_defaults = {"lr": 0.1, "batch_size": 256}

    # Start a run
    with wandb.init() as run:
        # Update any values not set by the sweep
        run.config.setdefaults(config_defaults)

        # Add training code here
    ```
  </Tab>
</Tabs>

***

<Badge stroke shape="pill" color="orange" size="md">[Sweeps](/support/models/tags/sweeps)</Badge>
