Weights & Biases
framework3.utils.wandb
¶
WandbAgent
¶
A class to create and run Weights & Biases agents for sweeps.
This class provides a callable interface to create and run Weights & Biases agents, which are used to execute sweep runs with specified configurations.
Key Features
- Create and run Weights & Biases agents for sweeps
- Execute custom functions with sweep configurations
- Automatically handle initialization and teardown of Weights & Biases runs
Usage
Methods:
Name | Description |
---|---|
__call__ |
str, project: str, function: Callable) -> None: Create and run a Weights & Biases agent for a specified sweep. |
Source code in framework3/utils/wandb.py
__call__(sweep_id, project, function)
staticmethod
¶
Create and run a Weights & Biases agent for a specified sweep.
This method initializes a Weights & Biases agent, executes the provided function with the sweep configuration, and handles the teardown of the Weights & Biases run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sweep_id
|
str
|
The ID of the sweep to run. |
required |
project
|
str
|
The name of the Weights & Biases project. |
required |
function
|
Callable
|
A function that takes a configuration dictionary and returns a result to be logged. |
required |
Returns:
Type | Description |
---|---|
None
|
(None) |
Source code in framework3/utils/wandb.py
WandbSweepManager
¶
A manager class for creating and handling Weights & Biases sweeps.
This class provides methods to generate sweep configurations, create sweeps, and manage sweep runs for hyperparameter optimization using Weights & Biases.
Key Features
- Generate sweep configurations from BaseFilter pipelines
- Create sweeps with customizable parameters and metrics
- Retrieve sweep information and best configurations
- Restart sweeps by deleting specific runs
Usage
from framework3.utils.wandb import WandbSweepManager
from framework3.base import BaseFilter, BaseMetric, XYData
# Create a WandbSweepManager instance
sweep_manager = WandbSweepManager()
# Create a sweep
pipeline = YourPipeline()
scorer = YourScorer()
x_data = XYData(...)
y_data = XYData(...)
sweep_id = sweep_manager.create_sweep(pipeline, "your_project", scorer, x_data, y_data)
# Get the best configuration from a sweep
best_config = sweep_manager.get_best_config("your_project", sweep_id, order="ascending")
# Restart a sweep
sweep = sweep_manager.get_sweep("your_project", sweep_id)
sweep_manager.restart_sweep(sweep, states=["failed", "crashed"])
Methods:
Name | Description |
---|---|
get_grid |
Dict[str, Any], config: Dict[str, Any]) -> None: Recursively extract grid search parameters from a pipeline configuration. |
generate_config_for_pipeline |
BaseFilter) -> Dict[str, Any]: Generate a Weights & Biases sweep configuration from a BaseFilter pipeline. |
create_sweep |
BaseFilter, project_name: str, scorer: BaseMetric, x: XYData, y: XYData | None = None) -> str: Create a new sweep in Weights & Biases. |
get_sweep |
str, sweep_id: str) -> Any: Retrieve a sweep object from Weights & Biases. |
get_best_config |
str, sweep_id: str, order: str) -> Dict[str, Any]: Get the best configuration from a completed sweep. |
restart_sweep |
Any, states: List[str] | Literal["all"] = "all") -> None: Restart a sweep by deleting runs with specified states. |
init |
str, name: str, reinit: bool = True) -> Any: Initialize a new Weights & Biases run. |
Source code in framework3/utils/wandb.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
create_sweep(pipeline, project_name, scorer, x, y=None)
¶
Create a new sweep in Weights & Biases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline
|
BaseFilter
|
The pipeline to be optimized. |
required |
project_name
|
str
|
The name of the Weights & Biases project. |
required |
scorer
|
BaseMetric
|
The metric used to evaluate the pipeline. |
required |
x
|
XYData
|
The input data. |
required |
y
|
XYData | None
|
The target data (optional). |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The ID of the created sweep. |
Source code in framework3/utils/wandb.py
generate_config_for_pipeline(pipeline)
staticmethod
¶
Generate a Weights & Biases sweep configuration from a BaseFilter pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline
|
BaseFilter
|
The pipeline to generate the configuration for. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A Weights & Biases sweep configuration. |
Source code in framework3/utils/wandb.py
get_best_config(project_name, sweep_id, order)
¶
Get the best configuration from a completed sweep.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_name
|
str
|
The name of the Weights & Biases project. |
required |
sweep_id
|
str
|
The ID of the sweep. |
required |
order
|
str
|
The order to use when selecting the best run ("ascending" or "descending"). |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
The configuration of the best run. |
Source code in framework3/utils/wandb.py
get_grid(aux, config)
staticmethod
¶
Recursively extract grid search parameters from a pipeline configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
aux
|
Dict[str, Any]
|
The input configuration dictionary. |
required |
config
|
Dict[str, Any]
|
The output configuration dictionary to be updated. |
required |
Source code in framework3/utils/wandb.py
get_sweep(project_name, sweep_id)
¶
Retrieve a sweep object from Weights & Biases.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_name
|
str
|
The name of the Weights & Biases project. |
required |
sweep_id
|
str
|
The ID of the sweep to retrieve. |
required |
Returns:
Type | Description |
---|---|
Any
|
The sweep object. |
Source code in framework3/utils/wandb.py
init(group, name, reinit=True)
¶
Initialize a new Weights & Biases run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group
|
str
|
The group name for the run. |
required |
name
|
str
|
The name of the run. |
required |
reinit
|
bool
|
Whether to reinitialize if a run is already in progress. |
True
|
Returns:
Type | Description |
---|---|
Any
|
The initialized run object. |
Source code in framework3/utils/wandb.py
restart_sweep(sweep, states='all')
¶
Restart a sweep by deleting runs with specified states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sweep
|
Any
|
The sweep object to restart. |
required |
states
|
List[str] | Literal['all']
|
The states of runs to delete, or "all" to delete all runs. |
'all'
|