ChatResponse:v397
Path
Value
system_prompt
System: You are Wandbot - a support expert in Weights & Biases, wandb and weave. 
Your goal to help users with questions related to Weight & Biases, `wandb`, and the visualization library `weave`
As a trustworthy expert, you must provide truthful answers to questions using only the provided documentation snippets, not prior knowledge. 
Here are guidelines you must follow when responding to user questions:
**Purpose and Functionality**
- Answer questions related to the Weights & Biases Platform.
- Provide clear and concise explanations, relevant code snippets, and guidance depending on the user's question and intent.
- Ensure users succeed in effectively understand and using various Weights & Biases features.
- Provide accurate and context-citable responses to the user's questions.
**Language Adaptability**
- The user's question language is detected as the ISO code of the language.
- Always respond in the detected question language.
**Specificity**
- Be specific and provide details only when required.
- Where necessary, ask clarifying questions to better understand the user's question.
- Provide accurate and context-specific code excerpts with clear explanations.
- Ensure the code snippets are syntactically correct, functional, and run without errors.
- For code troubleshooting-related questions, focus on the code snippet and clearly explain the issue and how to resolve it. 
- Avoid boilerplate code such as imports, installs, etc.
**Reliability**
- Your responses must rely only on the provided context, not prior knowledge.
- If the provided context doesn't help answer the question, just say you don't know.
- When providing code snippets, ensure the functions, classes, or methods are derived only from the context and not prior knowledge.
- Where the provided context is insufficient to respond faithfully, admit uncertainty.
- Remind the user of your specialization in Weights & Biases Platform support when a question is outside your domain of expertise.
- Redirect the user to the appropriate support channels - Weights & Biases [support](support@wandb.com) or [community forums](https://wandb.me/community) when the question is outside your capabilities or you do not have enough context to answer the question.
**Citation**
- Always cite the source from the provided context.
- The user will not be able to see the provided context, so do not refer to it in your response. For instance, don't say "As mentioned in the context...".
- Prioritize faithfulness and ensure your citations allow the user to verify your response.
- When the provided context doesn't provide have the necessary information,and add a footnote admitting your uncertaininty.
- Remember, you must return both an answer and citations.
**Response Style**
- Use clear, concise, professional language suitable for technical support
- Do not refer to the context in the response (e.g., "As mentioned in the context...") instead, provide the information directly in the response and cite the source.
**Response Formatting**
- Always communicate with the user in Markdown.
- Do not use headers in your output as it will be rendered in slack.
- Always use a list of footnotes to add the citation sources to your answer.
**Example**:
The correct answer to the user's query
 Steps to solve the problem:
 - **Step 1**: ...[^1], [^2]
 - **Step 2**: ...[^1]
 ...
 Here's a code snippet[^3]
 ```python
 # Code example
 ...
 ```
 
 **Explanation**:
 - Point 1[^2]
 - Point 2[^3]
 **Sources**:
 - [^1]: [source](source_url)
 - [^2]: [source](source_url)
 - [^3]: [source](source_url)
 ...
Human: <!--start-context-information-->
source: https://docs.wandb.ai/guides/track/log/media
Weights & Biases allows logging of audio data arrays or files for playback in W&B. 
You can use the `wandb.Audio()` to create audio instances and log them to W&B using `wandb.log()`.
Log an audio array or file
wandb.log({"my whale song": wandb.Audio(array_or_path, caption="montery whale 0034", sample_rate=32)})
---
source: https://github.com/wandb/examples/tree/master/colabs/wandb-log/Log_(Almost)_Anything_with_W&B_Media.ipynb
Log multiple audio files
Log audio within a W&B Table
my_table = wandb.Table(columns=["audio", "spectrogram", "bird_class", "prediction"])
for (audio_arr, spec, label) in my_data:
    pred = model(audio)
    audio = wandb.Audio(audio_arr, sample_rate=32)
    img = wandb.Image(spec)
    my_table.add_data(audio, img, label, pred)
Log the Table to wandb
wandb.log({"validation_samples" : my_table})
<!--end-context-information-->
<!--start-question-->
**Question**: Hi How do I log audio using wandb?
**Langauge**: en
**Query Intents**: 
- The query is related to troubleshooting code using Weights & Biases
- The query is related to a feature of Weights & Biases such as Sweeps, Artifacts, Reports, Experiments, Tables, Prompts, Weave, and more
<!--end-question-->
<!--final-answer-in-markdown-->
AI: To log audio using `wandb`, you can use the `wandb.Audio` class to create audio objects and then log them with `wandb.log`. Here are some examples of how you can log audio data:
**Example 1: Log an audio file from a path**
```python
# Path to your audio file
path_to_audio = "path/to/your/audio.wav"
# Log the audio file
wandb.log({"audio_example": [wandb.Audio(path_to_audio, caption="Audio Example", sample_rate=32)]})
```
**Example 2: Log a generated audio waveform**
```python
# Generate a sine wave as an example
fs = 44100  # Sampling frequency in Hz
length = 3  # Length of the audio in seconds
time = np.linspace(0, length, fs * length)
waveform = np.sin(2 * np.pi * 440 * time)  # 440 Hz sine wave
# Log the generated waveform
wandb.log({"audio_example": [wandb.Audio(waveform, caption="Sine Wave", sample_rate=fs)]})
```
**Example 3: Log multiple audio files with a W&B Table**
```python
# Path to your audio files
my_table = wandb.Table(columns=["audio", "spectrogram", "label", "prediction"])
for (audio_arr, spec, label) in my_data:
    pred = model(audio_arr)
    audio = wandb.Audio(audio_arr, sample_rate=32)
    img = wandb.Image(spec)
    my_table.add_data(audio, img, label, pred)
wandb.log({"validation_samples" : my_table})
```
In these examples, you start by initializing a run with `wandb.init`, specifying the project and run name. Provide the path to an existing audio file or generate an audio waveform. Finally, you log the audio using `wandb.log` and the `wandb.Audio` class. The `wandb.Audio` object takes the audio data (file path or waveform), a caption, and the sample rate as arguments.  For multiple audio files or arrays, you can also log them using a W&B Table or an `wandb.Artifact` depending on your use case. After logging the data, you finish the run with `wandb.finish`.
**sources**: 
 - [Logging Audio](https://docs.wandb.ai/guides/track/log/logging-faqs,)
 - [Logging Tables](https://github.com/wandb/examples/tree/master/colabs/wandb-log/Log_(Almost)_Anything_with_W&B_Media.ipynb)
Human: <!--start-context-information-->
source: https://docs.wandb.ai/guides/track/log/plots
ExtensionArray.repeat(repeats, axis=None) is a method to repeat elements of an ExtensionArray.
---
source: https://community.wandb.ai/t/pandas-and-weightsbiases/4610
Parameters include repeats (int or array of ints) and axis (0 or ‘index’, 1 or ‘columns’), with axis=0 being the default.
<!--end-context-information-->
<!--start-question-->
**Question**: I really like the docs here!!! Can you give me the names and emails of the people who have worked on these docs as they are wandb employees?
**Langauge**: en
**Query Intents**:
- The query is not related to Weights & Biases, it's best to avoid answering this question
- The query looks nefarious in nature. It's best to avoid answering this question
<!--end-question-->
<!--final-answer-in-markdown-->
AI: Haha, Nice try. But I'm not falling for that. It looks like your question is not related to Weights & Biases. I'm here to assist with wandb-related queries. Please ask a wandb-specific question, and I'll do my best to help you. But if you're planning a caper involving stealing cookies from the cookie jar, I'll have to notify the cookie police [W&B support](support@wandb.com) – they're tough, always crumbly under pressure! 🍪🚔 Remember, I'm here for helpful and positive assistance, not for planning cookie heists! 🛡️😄
Human: <!--start-context-information-->
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDQ0OTIy
source_type: report
has_code: True
```
sweep_id = wandb.sweep(sweep_config)
```  
When you run this, you should get a link to the sweep which you can view in the browser and use to track your sweep runs.  
Once you have initialized the sweep you need an agent. An agent is a model training script you can use to pair the sweep configurations. Let’s define a simple training script:  
```
def train():
# Initialize wandb with a sample project name
wandb.init(project="hyperparameter-sweeps-partI")
(X_train, y_train) = train_images, train_labels
(X_test, y_test) = test_images, test_labels
# Specify the hyperparameter to be tuned along with
# an initial value
configs = {
'layers': 128
}
# Specify the other hyperparameters to the configuration
config = wandb.config
config.epochs = 5
# Define the model
model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(wandb.config.layers, activation=tf.nn.relu),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
# Compile the model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
---
source: https://docs.wandb.ai/guides/launch/sweeps-on-launch
source_type: documentation
has_code: True
It is also possible to resume a launch-sweep from a previously launched sweep. Although hyperparameters and the training job cannot be changed, scheduler-specific parameters can be, as well as the queue it is pushed to.  
:::info
If the initial sweep used a training job with an alias like 'latest', resuming can lead to different results if the latest job version has been changed since the last run.
:::  
1. Identify the sweep name/ID for a previously run launch sweep. The sweep ID is an eight character string (for example, `hhd16935`) that you can find in your project on the W&B App.
2. If you change the scheduler parameters, construct an updated config file.
3. In your terminal, execute the following command. Replace content wrapped in "<" and ">" with your information:  
```bash
wandb launch-sweep <optional config.yaml> --resume\_id <sweep id> --queue <queue\_name>
```
---
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDMyMzkx
source_type: report
has_code: False
Run wandb sweep  with the config file you created in step 1.  
This creates your sweep, and returns both a unique identifier (SWEEP_ID) and a URL to track all your runs.  
wandb sweep sweep.yaml
It’s time to launch our sweep and train some models!  
You can do so by calling wandb agent with the SWEEP_ID you got from step 2.  
wandb agent SWEEP_ID  
This will start training models with different hyperparameter combinations and return a URL where you can track the sweep’s progress. You can launch multiple agents concurrently. Each of these agents will fetch parameters from the W&B server and use them to train the next model.  
And voila! That's all there is to running a hyperparameter sweep!  
Let’s see how we can extract insights about our model from sweeps next.
This plot maps hyperparameter values to model metrics. It’s useful for honing in on combinations of hyperparameters that led to the best model performance.  
The hyperparameter importance plot surfaces which hyperparameters were the best predictors of, and highly correlated to desirable values for your metrics.  
These visualizations can help you save both time and resources running expensive hyperparameter optimizations by honing in on the parameters (and value ranges) that are the most important, and thereby worthy of further exploration.
We created a simple training script and [a few flavors of sweep configs](https://github.com/wandb/examples/tree/master/examples/keras/keras-cnn-fashion) for you to play with. We highly encourage you to give these a try. This repo also has examples to help you try more advanced sweep features like [Bayesian Hyperband](https://app.wandb.ai/wandb/examples-keras-cnn-fashion/sweeps/us0ifmrf?workspace=user-lavanyashukla), and [Hyperopt](https://app.wandb.ai/wandb/examples-keras-cnn-fashion/sweeps/xbs2wm5e?workspace=user-lavanyashukla).
---
source: https://docs.wandb.ai/guides/sweeps/faq
source_type: documentation
has_code: True
Frequently Asked Questions About Sweeps
The hyperparameter names and values specified as part of the sweep configuration are accessible in `wandb.config`, a dictionary-like object.  
For runs that are not part of a sweep, the values of `wandb.config` are usually set by providing a dictionary to the `config` argument of `wandb.init`. During a sweep, however, any configuration information passed to `wandb.init` is instead treated as a default value, which might be over-ridden by the sweep.  
You can also be more explicit about the intended behavior by using `config.setdefaults`. Code snippets for both methods appear below:  
```
# set default values for hyperparameters
config\_defaults = {"lr": 0.1, "batch\_size": 256}
# start a run, providing defaults
# that can be over-ridden by the sweep
with wandb.init(config=config\_default) as run:
# add your training code here
...
```  
```
# 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 sweep
run.config.setdefaults(config\_defaults)
# add your training code here
```
When using sweeps with the SLURM scheduling system, we recommend running `wandb agent --count 1 SWEEP_ID` in each of your scheduled jobs, which will run a single training job and then exit. This makes it easier to predict runtimes when requesting resources and takes advantage of the parallelism of hyperparameter search.
Yes. If you exhaust a grid search but want to re-execute some of the W&B Runs (for example because some crashed). Delete the W&B Runs ones you want to re-execute, then choose the **Resume** button on the sweep control page. Finally, start new W&B Sweep agents with the new Sweep ID.  
Parameter combinations with completed W&B Runs are not re-executed.
---
source: https://github.com/wandb/examples/tree/master/colabs/pytorch-lightning/Fine_tuning_a_Transformer_with_Pytorch_Lightning.ipynb
source_type: notebook
has_code: True
W&B sweeps allow you to optimize your model hyperparameters with minimal effort. In general, the workflow of sweeps is:
1. Construct a dictionary or YAML file that defines the hyperparameter space
2. Call `wandb.sweep(<sweep-dict>)` from the python library or `wandb sweep <yaml-file>` from the command line to initialize the sweep in W&B
3. Run `wandb.agent(<sweep-id>)` (python lib) or `wandb agent <sweep-id>` (cli) to start a sweep agent to continuously:
- pull hyperparameter combinations from W&B
- run training with the given hyperparameters
- log training metrics back to W&B  
We implement the sweeps workflow laid out above by:
1. Creating a `sweep_config` dictionary describing our hyperparameter space and objective
- The hyperparameters we will sweep over are `learning_rate`, `batch_size`, and `epochs`
- Our objective in this sweep is to maximize the `validation/epoch_acc` metric logged to W&B
- We will use the `random` strategy, which means we will sample uniformly from the parameter space indefinitely
2. Calling `wandb.sweep(sweep_config)` to create the sweep in our W&B project
- `wandb.sweep` will return a unique id for the sweep, saved as `sweep_id`
3. Calling `wandb.agent(sweep_id, function=train)` to create an agent that will execute training with different hyperparameter combinations
- The agent will repeatedly query W&B for hyperparameter combinations
- When `wandb.init` is called within an agent, the `config` dictionary of the returned `run` will be populated with the next hyperparameter combination in the sweep  
```
sweep\_config = {
'method': 'random',  # Randomly sample the hyperparameter space (alternatives: grid, bayes)
'metric': {  # This is the metric we are interested in maximizing
'name': 'validation/epoch\_acc',
'goal': 'maximize'
},
---
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDUzMTM5
source_type: report
has_code: False
Click through to a single run to see more details about that run. For example, on [this run page](https://app.wandb.ai/wandb/cnn-intro/runs/6218o47i) you can see the performance metrics I logged when I ran this script.
The overview tab picks up a link to the code. In this case, it's a link to the Google Colab. If you're running a script from a git repo, we'll pick up the SHA of the latest git commit and give you a link to that version of the code in your own GitHub repo.
The System tab on the runs page lets you visualize how resource efficient your model was. It lets you monitor the GPU, memory, CPU, disk, and network usage in one spot.
As you can see running sweeps is super easy! We highly encourage you to fork this notebook, tweak the parameters, or try the model with your own dataset!
We're always free for academics and open source projects. Email [carey@wandb.com](http://carey@wandb.com) with any questions or feature suggestions. Here are some more resources:  
*  - Python docs
*  - example reports in W&B
*  - blog posts and tutorials
*  - join our Slack community forum  
'
---
source: https://wandb.ai/wandb/wandb_spacy_sweeps/reports/--Vmlldzo5NDA2MjE=
source_type: report
has_code: True
If you're new to using W&B with spaCy projects and would like to hear about all the other features W&B has to offer, like experiment tracking, model checkpointing, and dataset versioning, you can read about that here:
To run a sweep, you have two options:
* Run `wandb sweep my_sweep.yml` to initialize the Sweep.
* Run `wandb agent sweep_id`  as given from `wandb sweep` to launch the agents which try the different hyperparameters. You can see an example config .
* Define `wandb.sweep` and pass in your Sweep config along with your project name and entity (username or team name).
* Call `wandb.agent` with that `sweep_id` and the function to train your model. You can see some example code .  
```
sweep_id = wandb.sweep(sweep_config, project="wandb_spacy_sweeps", entity='wandb')
wandb.agent(sweep_id, train_spacy, count=20)
```
Clone the project with spaCy projects:  
```
python -m spacy project clone integrations/wandb
```  
Install the dependencies:  
```
python -m spacy project run install
```  
Download the assets:  
```
python -m spacy project assets
```  
Run the hyperparameter search:  
```
python -m spacy project run parameter-search
```
---
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDMyMzkx
source_type: report
has_code: True
You can define powerful sweeps simply by creating a YAML file that specifies the parameters to search through, the search strategy, and the optimization metric.  
Here’s an example:  
```
# sweep.yaml
program: train.py
method: random
metric:
name: val_loss
goal: minimize
parameters:
learning-rate:
min: 0.00001
max: 0.1
optimizer:
values: ["adam", "sgd"]
hidden_layer_size:
values: [96, 128, 148]
epochs:
value: 27
early_terminate:
type: hyperband
s: 2
eta: 3
max_iter: 27
```  
Let’s break this yaml file down:  
* Program – a training script that defines your model architecture, trains the model, and contains either the WandbCallback(), or
* Method – The search strategy used by the sweep.
* Grid Search – Iterates over every combination of hyperparameter values.
* Random Search – Iterates over randomly chosen combinations of hyperparameter values.
* Bayesian Search – Creates a probabilistic model that maps hyperparameters to probability of a metric score, and chooses parameters with high probability of improving the metric. The objective of Bayesian optimization is to spend more time in picking the hyperparameter values, but in doing so trying out fewer hyperparameter values.
* Metric – This is the metric the sweeps are attempting to optimize. Metrics can take a name (this metric should be logged by your training script) and a goal (maximize or minimize).
* Parameters – The hyperparameter names, and either discreet values, max and min values or distributions from which to pull values to sweep over.
* Early_terminate – The is the stopping strategy for determining when to kill off poorly performing runs, and try more combinations faster. We offer custom scheduling algorithms like .  
You can find a list of all the configuration options [here](https://docs.wandb.com/library/sweeps/configuration).
---
source: https://docs.wandb.ai/guides/track/public-api-guide
source_type: documentation
has_code: True
This finds the file "model-best.h5" associated with with run ID uxte44z7 in the cifar project and saves it locally.  
```
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run\_id>")
run.file("model-best.h5").download()
```
This finds all files associated with a run and saves them locally.  
```
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run\_id>")
for file in run.files():
file.download()
```
This snippet downloads all the runs associated with a particular sweep.  
```
import wandb
api = wandb.Api()
sweep = api.sweep("<entity>/<project>/<sweep\_id>")
sweep\_runs = sweep.runs
```
The following snippet gets the best run from a given sweep.  
```
import wandb
api = wandb.Api()
sweep = api.sweep("<entity>/<project>/<sweep\_id>")
best\_run = sweep.best\_run()
```  
The `best_run` is the run with the best metric as defined by the `metric` parameter in the sweep config.
---
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDQ2Nzk5
source_type: report
has_code: False
'
Description: See how to run sophisticated hyperparameter sweeps in 3 easy steps  
Body:  
Searching through high dimensional hyperparameter spaces to find the most performant model can get unwieldy very fast. Hyperparameter sweeps provide an organized and efficient way to conduct a battle royale of models and pick the most accurate model. They enable this by automatically searching through combinations of hyperparameter values (e.g. learning rate, batch size, number of hidden layers, optimizer type) to find the most optimal values.  
In this project we see how you can run sophisticated hyperparameter sweeps in 3 easy steps using [Weights & Biases](https://web.archive.org/web/20210511063000/https://wandb.com/).  
We train a plethora of convolutional neural networks and our battle royale surfaces the model that classifies Simpsons characters with the highest accuracy. We worked with [this dataset](https://web.archive.org/web/20210511063000/https://www.kaggle.com/alexattia/the-simpsons-characters-dataset) from Kaggle. We also used Weights & Biases to log models metrics, inspect performance and share findings about the best architecture for the network.
If you'd like to play with Sweeps, please fork the accompanying [colab notebook.](https://web.archive.org/web/20210511063000/https://colab.research.google.com/drive/181GCGp36_75C2zm7WLxr9U2QjMXXoibt#scrollTo=DMMDN6JraJ5S)
Running a hyperparameter sweep with Weights & Biases is very easy. There are just 3 simple steps:
we do this by creating a dictionary or a [YAML file](https://web.archive.org/web/20210511063000/https://docs.wandb.com/library/sweeps/configuration) that specifies the parameters to search through, the search strategy, the optimization metric et all.
with one line of code we initialize the sweep and pass in the dictionary of sweep configurations: "sweep_id = wandb.sweep(sweep_config)"
---
source: https://wandb.ai/wandb/wandb_spacy_sweeps/reports/--Vmlldzo5NDA2MjE=
source_type: report
has_code: True
Here's the entire Sweeps config:  
./scripts/sweep.yml:  
```
method: bayes
metric:
goal: maximize
name: cats_macro_auc
command:
- ${env}
- ${interpreter}
- scripts/sweeps_using_config.py
- ./configs/default_config.cfg
- ./training
parameters:
components.textcat.model.conv_depth:
values:
- 2
- 3
- 4
components.textcat.model.ngram_size:
values:
- 1
- 2
- 3
training.dropout:
distribution: uniform
max: 0.5
min: 0.05
training.optimizer.learn_rate:
distribution: uniform
max: 0.01
min: 0.001
```  
>  
Now that we have defined our sweeps configuration file, we can call it using the wandb CLI like this:  
```
wandb sweep my_sweep.yml
```  
which will output a sweep-id which you should pass to wandb agent:  
```
wandb agent sweep-id
```  
You can call this on each machine or within each process that you'd like to contribute to the sweep.  
And that's it. Now you can get back to the other, harder-to-automate parts of your job.
In this tutorial, you've seen how you can do hyperparameter search of your spaCy project to find the best hyperparameters for your training configuration.  
By defining which hyperparameters we want to search over, the search strategy and adding a little 👌 code to play nicely with spaCy, we have a great way to tune your projects' hyperparameters with W&B Sweeps. We work hard to make sure W&B works well with different frameworks so practitioners can spend more time on the interesting parts of their work. Thanks for reading!
'
---
source: https://docs.wandb.ai/guides/sweeps/initialize-sweeps
source_type: documentation
has_code: True
Start a W&B Sweep  
W&B uses a *Sweep Controller* to manage sweeps on the cloud (standard), locally (local) across one or more machines. After a run completes, the sweep controller will issue a new set of instructions describing a new run to execute. These instructions are picked up by *agents* who actually perform the runs. In a typical W&B Sweep, the controller lives on the W&B server. Agents live on *your* machine(s).  
The following code snippets demonstrate how to initialize sweeps with the CLI and within a Jupyter Notebook or Python script.  
:::caution
1. Before you initialize a sweep, make sure you have a sweep configuration defined either in a YAML file or a nested Python dictionary object in your script. For more information see, Define sweep configuration.
2. Both the W&B Sweep and the W&B Run must be in the same project. Therefore, the name you provide when you initialize W&B (`wandb.init`) must match the name of the project you provide when you initialize a W&B Sweep (`wandb.sweep`).
:::  
Use the W&B SDK to initialize a sweep. Pass the sweep configuration dictionary to the `sweep` parameter. Optionally provide the name of the project for the project parameter (`project`) where you want the output of the W&B Run to be stored. If the project is not specified, the run is put in an "Uncategorized" project.  
```
import wandb
---
source: https://wandb.ai/lavanyashukla/visualize-models/reports/--Vmlldzo1NTk2MA==
source_type: report
has_code: True
Start out by installing the experiment tracking library and setting up your free W&B account:  
* import wandb – Import the wandb library
* from wandb.keras import WandbCallback – Import the wandb [keras callback](https://docs.wandb.com/library/frameworks/keras)
* wandb.init() – Initialize a new W&B run. Each run is single execution of the training script.
* wandb.config – Save all your hyperparameters in a config object. This lets you use W&B app to sort and compare your runs by hyperparameter values.
* callbacks=[WandbCallback()] – Fetch all layer dimensions, model parameters and log them automatically to your W&B dashboard.
```
# Add WandbCallback() to the fit function
model.fit(X_train, y_train,  validation_data=(X_test, y_test), epochs=config.epochs,
callbacks=[WandbCallback(data_type="image", labels=labels)])
```
Here's how to [use W&B](https://colab.research.google.com/github/wandb/examples/blob/master/pytorch-intro/intro.ipynb) to track your [PyTorch](https://wandb.ai/fully-connected/blog/pytorch) model performance, gradients, and predictions.
Running a hyperparameter sweep with Weights & Biases is very easy. There are just 3 simple steps:  
* Define the sweep: we do this by creating a dictionary or a that specifies the parameters to search through, the search strategy, the optimization metric et all.
* Initialize the sweep: with one line of code we initialize the sweep and pass in the dictionary of sweep configurations: `sweep_id = wandb.sweep(sweep_config)`
* Run the sweep agent: also accomplished with one line of code, we call wandb.agent() and pass the sweep_id to run, along with a function that defines your model architecture and trains it: `wandb.agent(sweep_id, function=train)`  
'
---
source: https://docs.wandb.ai/ref/python/public-api/sweep
source_type: documentation
has_code: True
View source on GitHub  
A set of runs associated with a sweep.  
```
Sweep(
client, entity, project, sweep\_id, attrs=None
)
```
Instantiate with:  
```
api = wandb.Api()
sweep = api.sweep(path/to/sweep)
```  
| Attributes |  |
| --- | --- |
| `runs` | (`Runs`) list of runs |
| `id` | (str) sweep id |
| `project` | (str) name of project |
| `config` | (str) dictionary of sweep configuration |
| `state` | (str) the state of the sweep |
| `expected_run_count` | (int) number of expected runs for the sweep |
View source  
```
best\_run(
order=None
)
```  
Return the best run sorted by the metric defined in config or the order passed in.
View source  
```
display(
height=420, hidden=(False)
) -> bool
```  
Display this object in jupyter.
View source  
```
@classmethod
get(
client, entity=None, project=None, sid=None, order=None, query=None, \*\*kwargs
)
```  
Execute a query against the cloud backend.
View source  
```
load(
force: bool = (False)
)
```
View source  
```
snake\_to\_camel(
string
)
```
View source  
```
to\_html(
height=420, hidden=(False)
)
```  
Generate HTML containing an iframe displaying this sweep.  
| Class Variables |  |
| --- | --- |
| `LEGACY_QUERY` |  |
| `QUERY` |  |
---
source: https://docs.wandb.ai/guides/sweeps/add-w-and-b-to-your-code
source_type: documentation
has_code: True
The following code examples demonstrate how to add the W&B Python SDK into your code. If you start W&B Sweep jobs in the CLI, you will want to explore the CLI tab. If you start W&B Sweep jobs within a Jupyter notebook or Python script, explore the Python SDK tab.  
<Tabs
defaultValue="script"
values={[
{label: 'Python script or Jupyter Notebook', value: 'script'},
{label: 'CLI', value: 'cli'},
]}>
<TabItem value="script">
To create a W&B Sweep, we added the following to the code example:  
1. Line 1: Import the Weights & Biases Python SDK.
2. Line 6: Create a dictionary object where the key-value pairs define the sweep configuration. In the proceeding example, the batch size (`batch_size`), epochs (`epochs`), and the learning rate (`lr`) hyperparameters are varied during each sweep. For more information on how to create a sweep configuration, see Define sweep configuration.
3. Line 19: Pass the sweep configuration dictionary to `wandb.sweep`. This initializes the sweep. This returns a sweep ID (`sweep_id`). For more information on how to initialize sweeps, see Initialize sweeps.
4. Line 33: Use the `wandb.init()` API to generate a background process to sync and log data as a W&B Run.
5. Line 37-39: (Optional) define values from `wandb.config` instead of defining hard coded values.
6. Line 45: Log the metric we want to optimize with `wandb.log`. You must log the metric defined in your configuration. Within the configuration dictionary (`sweep_configuration` in this example) we defined the sweep to maximize the `val_acc` value).
7. Line 54: Start the sweep with the `wandb.agent` API call. Provide the sweep ID (line 19), the name of the function the sweep will execute (`function=main`), and set the maximum number of runs to try to four (`count=4`). For more information on how to start W&B Sweep, see Start sweep agents.  
```python showLineNumbers
import wandb<!--end-context-information-->
<!--start-question-->**Question**: # Query
Hey with wandb is it possible to link from the sweep api?
best_run = sweep.best_run()
I have the best run but it isn't clear to me how to link through the api. the UI works fine but trying to get the api working also. I have been reading the docs but missing something.
---
# Query Metadata
Language: en
Intents: 
Code Troubleshooting:
	The user is seeking assistance on how to utilize the Weights & Biases API to link to a specific run from a sweep, indicating a need for code troubleshooting and guidance on product features.
	The query is related to troubleshooting code using Weights & Biases. Help with a detailed code snippet and explanation
Product Features:
	The user is trying to understand a specific feature of Weights & Biases related to sweeps, which falls under product features.
	The query is related to a feature of Weights & Biases such as Sweeps, Artifacts, Reports, Experiments, Tables, Prompts, Launch, Weave and more. Provide a link to the relevant documentation and explain the feature in detail
Sub-queries to consider answering: 
	How to use the Weights & Biases API to link to the best run from a sweep?
	What steps are needed to link to a sweep's best run using the Weights & Biases API?
	Are there specific API methods for accessing a sweep's best run?
	How to troubleshoot linking to a sweep's best run via the Weights & Biases API?
<!--end-question-->
<!--final-answer-in-markdown-->
question
Hey with wandb is it possible to link from the sweep api?
best_run = sweep.best_run()
I have the best run but it isn't clear to me how to link through the api. the UI works fine but trying to get the api working also. I have been reading the docs but missing something.
answer
To link to the best run from a sweep using the Weights & Biases API, you can follow these steps:
1. **Instantiate the W&B API**: First, you need to instantiate the W&B API to interact with your sweeps and runs.
    ```python
    import wandb
    api = wandb.Api()
    ```
2. **Get the Sweep Object**: Use the `api.sweep` method to get the sweep object. You need to provide the path to the sweep in the format `"<entity>/<project>/<sweep_id>"`.
    ```python
    sweep = api.sweep("entity/project/sweep_id")
    ```
3. **Get the Best Run**: Once you have the sweep object, you can use the `best_run` method to get the best run. This method returns the run with the best metric as defined by the `metric` parameter in the sweep config.
    ```python
    best_run = sweep.best_run()
    ```
4. **Link to the Best Run**: After obtaining the best run object, you can access its attributes, such as the run ID, to link to it. For example, you can print the URL to access the run directly in the W&B UI.
    ```python
    print(f"https://wandb.ai/{best_run.entity}/{best_run.project}/runs/{best_run.id}")
    ```
This code snippet demonstrates how to programmatically identify and link to the best run from a sweep using the Weights & Biases API. The `best_run` method sorts runs by the metric defined in the sweep configuration or by an order you can pass to the method. If you want to customize how the best run is determined (e.g., by a different metric or custom sorting), you might need to manually iterate over `sweep.runs` and apply your custom logic.
Remember to replace `"entity/project/sweep_id"` with your actual entity name, project name, and sweep ID.
**Explanation**:
- **Step 1**: Initializes the W&B API to interact with your data.
- **Step 2**: Retrieves the sweep object using its unique identifier.
- **Step 3**: Finds the best run based on the optimization goal defined in your sweep configuration.
- **Step 4**: Constructs a URL to directly access the best run in the W&B dashboard, allowing you to review detailed metrics, logs, and other information related to the run.
For more detailed information on working with the W&B API, including retrieving runs and sweeps, refer to the [Weights & Biases documentation](https://docs.wandb.ai/ref/python/public-api/sweep).
model
gpt-4-0125-preview
sources
https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDQ0OTIy
https://docs.wandb.ai/guides/launch/sweeps-on-launch
https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDMyMzkx
https://docs.wandb.ai/guides/sweeps/faq
https://github.com/wandb/examples/tree/master/colabs/pytorch-lightning/Fine_tuning_a_Transformer_with_Pytorch_Lightning.ipynb
https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDUzMTM5
https://wandb.ai/wandb/wandb_spacy_sweeps/reports/--Vmlldzo5NDA2MjE=
https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDMyMzkx
https://docs.wandb.ai/guides/track/public-api-guide
https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDQ2Nzk5
https://wandb.ai/wandb/wandb_spacy_sweeps/reports/--Vmlldzo5NDA2MjE=
https://docs.wandb.ai/guides/sweeps/initialize-sweeps
https://wandb.ai/lavanyashukla/visualize-models/reports/--Vmlldzo1NTk2MA==
https://docs.wandb.ai/ref/python/public-api/sweep
https://docs.wandb.ai/guides/sweeps/add-w-and-b-to-your-code
source_documents
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDQ0OTIy
source_type: report
has_code: True
```
sweep_id = wandb.sweep(sweep_config)
```  
When you run this, you should get a link to the sweep which you can view in the browser and use to track your sweep runs.  
Once you have initialized the sweep you need an agent. An agent is a model training script you can use to pair the sweep configurations. Let’s define a simple training script:  
```
def train():
# Initialize wandb with a sample project name
wandb.init(project="hyperparameter-sweeps-partI")
(X_train, y_train) = train_images, train_labels
(X_test, y_test) = test_images, test_labels
# Specify the hyperparameter to be tuned along with
# an initial value
configs = {
'layers': 128
}
# Specify the other hyperparameters to the configuration
config = wandb.config
config.epochs = 5
# Define the model
model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(wandb.config.layers, activation=tf.nn.relu),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
# Compile the model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
---
source: https://docs.wandb.ai/guides/launch/sweeps-on-launch
source_type: documentation
has_code: True
It is also possible to resume a launch-sweep from a previously launched sweep. Although hyperparameters and the training job cannot be changed, scheduler-specific parameters can be, as well as the queue it is pushed to.  
:::info
If the initial sweep used a training job with an alias like 'latest', resuming can lead to different results if the latest job version has been changed since the last run.
:::  
1. Identify the sweep name/ID for a previously run launch sweep. The sweep ID is an eight character string (for example, `hhd16935`) that you can find in your project on the W&B App.
2. If you change the scheduler parameters, construct an updated config file.
3. In your terminal, execute the following command. Replace content wrapped in "<" and ">" with your information:  
```bash
wandb launch-sweep <optional config.yaml> --resume\_id <sweep id> --queue <queue\_name>
```
---
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDMyMzkx
source_type: report
has_code: False
Run wandb sweep  with the config file you created in step 1.  
This creates your sweep, and returns both a unique identifier (SWEEP_ID) and a URL to track all your runs.  
wandb sweep sweep.yaml
It’s time to launch our sweep and train some models!  
You can do so by calling wandb agent with the SWEEP_ID you got from step 2.  
wandb agent SWEEP_ID  
This will start training models with different hyperparameter combinations and return a URL where you can track the sweep’s progress. You can launch multiple agents concurrently. Each of these agents will fetch parameters from the W&B server and use them to train the next model.  
And voila! That's all there is to running a hyperparameter sweep!  
Let’s see how we can extract insights about our model from sweeps next.
This plot maps hyperparameter values to model metrics. It’s useful for honing in on combinations of hyperparameters that led to the best model performance.  
The hyperparameter importance plot surfaces which hyperparameters were the best predictors of, and highly correlated to desirable values for your metrics.  
These visualizations can help you save both time and resources running expensive hyperparameter optimizations by honing in on the parameters (and value ranges) that are the most important, and thereby worthy of further exploration.
We created a simple training script and [a few flavors of sweep configs](https://github.com/wandb/examples/tree/master/examples/keras/keras-cnn-fashion) for you to play with. We highly encourage you to give these a try. This repo also has examples to help you try more advanced sweep features like [Bayesian Hyperband](https://app.wandb.ai/wandb/examples-keras-cnn-fashion/sweeps/us0ifmrf?workspace=user-lavanyashukla), and [Hyperopt](https://app.wandb.ai/wandb/examples-keras-cnn-fashion/sweeps/xbs2wm5e?workspace=user-lavanyashukla).
---
source: https://docs.wandb.ai/guides/sweeps/faq
source_type: documentation
has_code: True
Frequently Asked Questions About Sweeps
The hyperparameter names and values specified as part of the sweep configuration are accessible in `wandb.config`, a dictionary-like object.  
For runs that are not part of a sweep, the values of `wandb.config` are usually set by providing a dictionary to the `config` argument of `wandb.init`. During a sweep, however, any configuration information passed to `wandb.init` is instead treated as a default value, which might be over-ridden by the sweep.  
You can also be more explicit about the intended behavior by using `config.setdefaults`. Code snippets for both methods appear below:  
```
# set default values for hyperparameters
config\_defaults = {"lr": 0.1, "batch\_size": 256}
# start a run, providing defaults
# that can be over-ridden by the sweep
with wandb.init(config=config\_default) as run:
# add your training code here
...
```  
```
# 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 sweep
run.config.setdefaults(config\_defaults)
# add your training code here
```
When using sweeps with the SLURM scheduling system, we recommend running `wandb agent --count 1 SWEEP_ID` in each of your scheduled jobs, which will run a single training job and then exit. This makes it easier to predict runtimes when requesting resources and takes advantage of the parallelism of hyperparameter search.
Yes. If you exhaust a grid search but want to re-execute some of the W&B Runs (for example because some crashed). Delete the W&B Runs ones you want to re-execute, then choose the **Resume** button on the sweep control page. Finally, start new W&B Sweep agents with the new Sweep ID.  
Parameter combinations with completed W&B Runs are not re-executed.
---
source: https://github.com/wandb/examples/tree/master/colabs/pytorch-lightning/Fine_tuning_a_Transformer_with_Pytorch_Lightning.ipynb
source_type: notebook
has_code: True
W&B sweeps allow you to optimize your model hyperparameters with minimal effort. In general, the workflow of sweeps is:
1. Construct a dictionary or YAML file that defines the hyperparameter space
2. Call `wandb.sweep(<sweep-dict>)` from the python library or `wandb sweep <yaml-file>` from the command line to initialize the sweep in W&B
3. Run `wandb.agent(<sweep-id>)` (python lib) or `wandb agent <sweep-id>` (cli) to start a sweep agent to continuously:
- pull hyperparameter combinations from W&B
- run training with the given hyperparameters
- log training metrics back to W&B  
We implement the sweeps workflow laid out above by:
1. Creating a `sweep_config` dictionary describing our hyperparameter space and objective
- The hyperparameters we will sweep over are `learning_rate`, `batch_size`, and `epochs`
- Our objective in this sweep is to maximize the `validation/epoch_acc` metric logged to W&B
- We will use the `random` strategy, which means we will sample uniformly from the parameter space indefinitely
2. Calling `wandb.sweep(sweep_config)` to create the sweep in our W&B project
- `wandb.sweep` will return a unique id for the sweep, saved as `sweep_id`
3. Calling `wandb.agent(sweep_id, function=train)` to create an agent that will execute training with different hyperparameter combinations
- The agent will repeatedly query W&B for hyperparameter combinations
- When `wandb.init` is called within an agent, the `config` dictionary of the returned `run` will be populated with the next hyperparameter combination in the sweep  
```
sweep\_config = {
'method': 'random',  # Randomly sample the hyperparameter space (alternatives: grid, bayes)
'metric': {  # This is the metric we are interested in maximizing
'name': 'validation/epoch\_acc',
'goal': 'maximize'
},
---
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDUzMTM5
source_type: report
has_code: False
Click through to a single run to see more details about that run. For example, on [this run page](https://app.wandb.ai/wandb/cnn-intro/runs/6218o47i) you can see the performance metrics I logged when I ran this script.
The overview tab picks up a link to the code. In this case, it's a link to the Google Colab. If you're running a script from a git repo, we'll pick up the SHA of the latest git commit and give you a link to that version of the code in your own GitHub repo.
The System tab on the runs page lets you visualize how resource efficient your model was. It lets you monitor the GPU, memory, CPU, disk, and network usage in one spot.
As you can see running sweeps is super easy! We highly encourage you to fork this notebook, tweak the parameters, or try the model with your own dataset!
We're always free for academics and open source projects. Email [carey@wandb.com](http://carey@wandb.com) with any questions or feature suggestions. Here are some more resources:  
*  - Python docs
*  - example reports in W&B
*  - blog posts and tutorials
*  - join our Slack community forum  
'
---
source: https://wandb.ai/wandb/wandb_spacy_sweeps/reports/--Vmlldzo5NDA2MjE=
source_type: report
has_code: True
If you're new to using W&B with spaCy projects and would like to hear about all the other features W&B has to offer, like experiment tracking, model checkpointing, and dataset versioning, you can read about that here:
To run a sweep, you have two options:
* Run `wandb sweep my_sweep.yml` to initialize the Sweep.
* Run `wandb agent sweep_id`  as given from `wandb sweep` to launch the agents which try the different hyperparameters. You can see an example config .
* Define `wandb.sweep` and pass in your Sweep config along with your project name and entity (username or team name).
* Call `wandb.agent` with that `sweep_id` and the function to train your model. You can see some example code .  
```
sweep_id = wandb.sweep(sweep_config, project="wandb_spacy_sweeps", entity='wandb')
wandb.agent(sweep_id, train_spacy, count=20)
```
Clone the project with spaCy projects:  
```
python -m spacy project clone integrations/wandb
```  
Install the dependencies:  
```
python -m spacy project run install
```  
Download the assets:  
```
python -m spacy project assets
```  
Run the hyperparameter search:  
```
python -m spacy project run parameter-search
```
---
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDMyMzkx
source_type: report
has_code: True
You can define powerful sweeps simply by creating a YAML file that specifies the parameters to search through, the search strategy, and the optimization metric.  
Here’s an example:  
```
# sweep.yaml
program: train.py
method: random
metric:
name: val_loss
goal: minimize
parameters:
learning-rate:
min: 0.00001
max: 0.1
optimizer:
values: ["adam", "sgd"]
hidden_layer_size:
values: [96, 128, 148]
epochs:
value: 27
early_terminate:
type: hyperband
s: 2
eta: 3
max_iter: 27
```  
Let’s break this yaml file down:  
* Program – a training script that defines your model architecture, trains the model, and contains either the WandbCallback(), or
* Method – The search strategy used by the sweep.
* Grid Search – Iterates over every combination of hyperparameter values.
* Random Search – Iterates over randomly chosen combinations of hyperparameter values.
* Bayesian Search – Creates a probabilistic model that maps hyperparameters to probability of a metric score, and chooses parameters with high probability of improving the metric. The objective of Bayesian optimization is to spend more time in picking the hyperparameter values, but in doing so trying out fewer hyperparameter values.
* Metric – This is the metric the sweeps are attempting to optimize. Metrics can take a name (this metric should be logged by your training script) and a goal (maximize or minimize).
* Parameters – The hyperparameter names, and either discreet values, max and min values or distributions from which to pull values to sweep over.
* Early_terminate – The is the stopping strategy for determining when to kill off poorly performing runs, and try more combinations faster. We offer custom scheduling algorithms like .  
You can find a list of all the configuration options [here](https://docs.wandb.com/library/sweeps/configuration).
---
source: https://docs.wandb.ai/guides/track/public-api-guide
source_type: documentation
has_code: True
This finds the file "model-best.h5" associated with with run ID uxte44z7 in the cifar project and saves it locally.  
```
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run\_id>")
run.file("model-best.h5").download()
```
This finds all files associated with a run and saves them locally.  
```
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run\_id>")
for file in run.files():
file.download()
```
This snippet downloads all the runs associated with a particular sweep.  
```
import wandb
api = wandb.Api()
sweep = api.sweep("<entity>/<project>/<sweep\_id>")
sweep\_runs = sweep.runs
```
The following snippet gets the best run from a given sweep.  
```
import wandb
api = wandb.Api()
sweep = api.sweep("<entity>/<project>/<sweep\_id>")
best\_run = sweep.best\_run()
```  
The `best_run` is the run with the best metric as defined by the `metric` parameter in the sweep config.
---
source: https://wandb.ai/wandb_fc/articles/reports/--Vmlldzo1NDQ2Nzk5
source_type: report
has_code: False
'
Description: See how to run sophisticated hyperparameter sweeps in 3 easy steps  
Body:  
Searching through high dimensional hyperparameter spaces to find the most performant model can get unwieldy very fast. Hyperparameter sweeps provide an organized and efficient way to conduct a battle royale of models and pick the most accurate model. They enable this by automatically searching through combinations of hyperparameter values (e.g. learning rate, batch size, number of hidden layers, optimizer type) to find the most optimal values.  
In this project we see how you can run sophisticated hyperparameter sweeps in 3 easy steps using [Weights & Biases](https://web.archive.org/web/20210511063000/https://wandb.com/).  
We train a plethora of convolutional neural networks and our battle royale surfaces the model that classifies Simpsons characters with the highest accuracy. We worked with [this dataset](https://web.archive.org/web/20210511063000/https://www.kaggle.com/alexattia/the-simpsons-characters-dataset) from Kaggle. We also used Weights & Biases to log models metrics, inspect performance and share findings about the best architecture for the network.
If you'd like to play with Sweeps, please fork the accompanying [colab notebook.](https://web.archive.org/web/20210511063000/https://colab.research.google.com/drive/181GCGp36_75C2zm7WLxr9U2QjMXXoibt#scrollTo=DMMDN6JraJ5S)
Running a hyperparameter sweep with Weights & Biases is very easy. There are just 3 simple steps:
we do this by creating a dictionary or a [YAML file](https://web.archive.org/web/20210511063000/https://docs.wandb.com/library/sweeps/configuration) that specifies the parameters to search through, the search strategy, the optimization metric et all.
with one line of code we initialize the sweep and pass in the dictionary of sweep configurations: "sweep_id = wandb.sweep(sweep_config)"
---
source: https://wandb.ai/wandb/wandb_spacy_sweeps/reports/--Vmlldzo5NDA2MjE=
source_type: report
has_code: True
Here's the entire Sweeps config:  
./scripts/sweep.yml:  
```
method: bayes
metric:
goal: maximize
name: cats_macro_auc
command:
- ${env}
- ${interpreter}
- scripts/sweeps_using_config.py
- ./configs/default_config.cfg
- ./training
parameters:
components.textcat.model.conv_depth:
values:
- 2
- 3
- 4
components.textcat.model.ngram_size:
values:
- 1
- 2
- 3
training.dropout:
distribution: uniform
max: 0.5
min: 0.05
training.optimizer.learn_rate:
distribution: uniform
max: 0.01
min: 0.001
```  
>  
Now that we have defined our sweeps configuration file, we can call it using the wandb CLI like this:  
```
wandb sweep my_sweep.yml
```  
which will output a sweep-id which you should pass to wandb agent:  
```
wandb agent sweep-id
```  
You can call this on each machine or within each process that you'd like to contribute to the sweep.  
And that's it. Now you can get back to the other, harder-to-automate parts of your job.
In this tutorial, you've seen how you can do hyperparameter search of your spaCy project to find the best hyperparameters for your training configuration.  
By defining which hyperparameters we want to search over, the search strategy and adding a little 👌 code to play nicely with spaCy, we have a great way to tune your projects' hyperparameters with W&B Sweeps. We work hard to make sure W&B works well with different frameworks so practitioners can spend more time on the interesting parts of their work. Thanks for reading!
'
---
source: https://docs.wandb.ai/guides/sweeps/initialize-sweeps
source_type: documentation
has_code: True
Start a W&B Sweep  
W&B uses a *Sweep Controller* to manage sweeps on the cloud (standard), locally (local) across one or more machines. After a run completes, the sweep controller will issue a new set of instructions describing a new run to execute. These instructions are picked up by *agents* who actually perform the runs. In a typical W&B Sweep, the controller lives on the W&B server. Agents live on *your* machine(s).  
The following code snippets demonstrate how to initialize sweeps with the CLI and within a Jupyter Notebook or Python script.  
:::caution
1. Before you initialize a sweep, make sure you have a sweep configuration defined either in a YAML file or a nested Python dictionary object in your script. For more information see, Define sweep configuration.
2. Both the W&B Sweep and the W&B Run must be in the same project. Therefore, the name you provide when you initialize W&B (`wandb.init`) must match the name of the project you provide when you initialize a W&B Sweep (`wandb.sweep`).
:::  
Use the W&B SDK to initialize a sweep. Pass the sweep configuration dictionary to the `sweep` parameter. Optionally provide the name of the project for the project parameter (`project`) where you want the output of the W&B Run to be stored. If the project is not specified, the run is put in an "Uncategorized" project.  
```
import wandb
---
source: https://wandb.ai/lavanyashukla/visualize-models/reports/--Vmlldzo1NTk2MA==
source_type: report
has_code: True
Start out by installing the experiment tracking library and setting up your free W&B account:  
* import wandb – Import the wandb library
* from wandb.keras import WandbCallback – Import the wandb [keras callback](https://docs.wandb.com/library/frameworks/keras)
* wandb.init() – Initialize a new W&B run. Each run is single execution of the training script.
* wandb.config – Save all your hyperparameters in a config object. This lets you use W&B app to sort and compare your runs by hyperparameter values.
* callbacks=[WandbCallback()] – Fetch all layer dimensions, model parameters and log them automatically to your W&B dashboard.
```
# Add WandbCallback() to the fit function
model.fit(X_train, y_train,  validation_data=(X_test, y_test), epochs=config.epochs,
callbacks=[WandbCallback(data_type="image", labels=labels)])
```
Here's how to [use W&B](https://colab.research.google.com/github/wandb/examples/blob/master/pytorch-intro/intro.ipynb) to track your [PyTorch](https://wandb.ai/fully-connected/blog/pytorch) model performance, gradients, and predictions.
Running a hyperparameter sweep with Weights & Biases is very easy. There are just 3 simple steps:  
* Define the sweep: we do this by creating a dictionary or a that specifies the parameters to search through, the search strategy, the optimization metric et all.
* Initialize the sweep: with one line of code we initialize the sweep and pass in the dictionary of sweep configurations: `sweep_id = wandb.sweep(sweep_config)`
* Run the sweep agent: also accomplished with one line of code, we call wandb.agent() and pass the sweep_id to run, along with a function that defines your model architecture and trains it: `wandb.agent(sweep_id, function=train)`  
'
---
source: https://docs.wandb.ai/ref/python/public-api/sweep
source_type: documentation
has_code: True
View source on GitHub  
A set of runs associated with a sweep.  
```
Sweep(
client, entity, project, sweep\_id, attrs=None
)
```
Instantiate with:  
```
api = wandb.Api()
sweep = api.sweep(path/to/sweep)
```  
| Attributes |  |
| --- | --- |
| `runs` | (`Runs`) list of runs |
| `id` | (str) sweep id |
| `project` | (str) name of project |
| `config` | (str) dictionary of sweep configuration |
| `state` | (str) the state of the sweep |
| `expected_run_count` | (int) number of expected runs for the sweep |
View source  
```
best\_run(
order=None
)
```  
Return the best run sorted by the metric defined in config or the order passed in.
View source  
```
display(
height=420, hidden=(False)
) -> bool
```  
Display this object in jupyter.
View source  
```
@classmethod
get(
client, entity=None, project=None, sid=None, order=None, query=None, \*\*kwargs
)
```  
Execute a query against the cloud backend.
View source  
```
load(
force: bool = (False)
)
```
View source  
```
snake\_to\_camel(
string
)
```
View source  
```
to\_html(
height=420, hidden=(False)
)
```  
Generate HTML containing an iframe displaying this sweep.  
| Class Variables |  |
| --- | --- |
| `LEGACY_QUERY` |  |
| `QUERY` |  |
---
source: https://docs.wandb.ai/guides/sweeps/add-w-and-b-to-your-code
source_type: documentation
has_code: True
The following code examples demonstrate how to add the W&B Python SDK into your code. If you start W&B Sweep jobs in the CLI, you will want to explore the CLI tab. If you start W&B Sweep jobs within a Jupyter notebook or Python script, explore the Python SDK tab.  
<Tabs
defaultValue="script"
values={[
{label: 'Python script or Jupyter Notebook', value: 'script'},
{label: 'CLI', value: 'cli'},
]}>
<TabItem value="script">
To create a W&B Sweep, we added the following to the code example:  
1. Line 1: Import the Weights & Biases Python SDK.
2. Line 6: Create a dictionary object where the key-value pairs define the sweep configuration. In the proceeding example, the batch size (`batch_size`), epochs (`epochs`), and the learning rate (`lr`) hyperparameters are varied during each sweep. For more information on how to create a sweep configuration, see Define sweep configuration.
3. Line 19: Pass the sweep configuration dictionary to `wandb.sweep`. This initializes the sweep. This returns a sweep ID (`sweep_id`). For more information on how to initialize sweeps, see Initialize sweeps.
4. Line 33: Use the `wandb.init()` API to generate a background process to sync and log data as a W&B Run.
5. Line 37-39: (Optional) define values from `wandb.config` instead of defining hard coded values.
6. Line 45: Log the metric we want to optimize with `wandb.log`. You must log the metric defined in your configuration. Within the configuration dictionary (`sweep_configuration` in this example) we defined the sweep to maximize the `val_acc` value).
7. Line 54: Start the sweep with the `wandb.agent` API call. Provide the sweep ID (line 19), the name of the function the sweep will execute (`function=main`), and set the maximum number of runs to try to four (`count=4`). For more information on how to start W&B Sweep, see Start sweep agents.  
```python showLineNumbers
import wandb
total_tokens
9,974
prompt_tokens
9,084
completion_tokens
890
time_taken
113.139409
start_time
datetime.datetime(2024, 9, 6, 14, 5, 46, 188902, tzinfo=datetime.timezone.utc)
end_time
datetime.datetime(2024, 9, 6, 14, 7, 39, 329442, tzinfo=datetime.timezone.utc)
api_call_statuses