Routing batch function¶
RoutingBatchFunc = Callable[[List[str]], List[str]]
module-attribute
¶
Type alias for a routing batch function. It takes a list of all the downstream steps and returns a list with the names of the steps that should receive the batch.
RoutingBatchFunction
¶
Bases: BaseModel
, _Serializable
A thin wrapper around a routing batch function that can be used to route batches from one upstream step to specific downstream steps.
Attributes:
Name | Type | Description |
---|---|---|
routing_function |
RoutingBatchFunc
|
The routing function that takes a list of all the downstream steps and returns a list with the names of the steps that should receive the batch. |
_step |
Union[_Step, None]
|
The upstream step that is connected to the routing batch function. |
_routed_batch_registry |
Dict[str, Dict[int, List[str]]]
|
A dictionary that keeps track of the batches that have been routed to specific downstream steps. |
Source code in src/distilabel/pipeline/routing_batch_function.py
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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
__call__(batch, steps)
¶
Returns a list of selected downstream steps from steps
to which the batch
should be routed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
_Batch
|
The batch that should be routed. |
required |
steps |
List[str]
|
A list of all the downstream steps that can receive the batch. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
A list with the names of the steps that should receive the batch. |
Source code in src/distilabel/pipeline/routing_batch_function.py
__rshift__(other)
¶
Connects a list of dowstream steps to the upstream step of the routing batch function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
List[DownstreamConnectableSteps]
|
A list of downstream steps that should be connected to the upstream step of the routing batch function. |
required |
Returns:
Type | Description |
---|---|
List[DownstreamConnectableSteps]
|
The list of downstream steps that have been connected to the upstream step of the |
List[DownstreamConnectableSteps]
|
routing batch function. |
Source code in src/distilabel/pipeline/routing_batch_function.py
dump(**kwargs)
¶
Dumps the routing batch function to a dictionary, and the information of the factory function used to create this routing batch function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
Any
|
Additional keyword arguments that should be included in the dump. |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary with the routing batch function information and the factory function |
Dict[str, Any]
|
information. |
Source code in src/distilabel/pipeline/routing_batch_function.py
from_dict(data)
classmethod
¶
Loads a routing batch function from a dictionary. It must contain the information of the factory function used to create the routing batch function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dict[str, Any]
|
A dictionary with the routing batch function information and the factory function information. |
required |
Source code in src/distilabel/pipeline/routing_batch_function.py
route_batch(batch, steps)
¶
Returns a list of selected downstream steps from steps
to which the batch
should be routed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
_Batch
|
The batch that should be routed. |
required |
steps |
List[str]
|
A list of all the downstream steps that can receive the batch. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
A list with the names of the steps that should receive the batch. |
Source code in src/distilabel/pipeline/routing_batch_function.py
set_factory_function(factory_function_module, factory_function_name, factory_function_kwargs)
¶
Sets the factory function that was used to create the routing_batch_function
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
factory_function_module |
str
|
The module name where the factory function is defined. |
required |
factory_function_name |
str
|
The name of the factory function that was used to create
the |
required |
factory_function_kwargs |
Dict[str, Any]
|
The keyword arguments that were used when calling the factory function. |
required |
Source code in src/distilabel/pipeline/routing_batch_function.py
routing_batch_function(description=None)
¶
Creates a routing batch function that can be used to route batches from one upstream step to specific downstream steps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description |
Optional[str]
|
An optional description for the routing batch function. |
None
|
Returns:
Type | Description |
---|---|
Callable[[RoutingBatchFunc], RoutingBatchFunction]
|
A |
Callable[[RoutingBatchFunc], RoutingBatchFunction]
|
the |
Example:
from distilabel.llms import MistralLLM, OpenAILLM, VertexAILLM
from distilabel.pipeline import Pipeline, routing_batch_function
from distilabel.steps import LoadHubDataset, CombineColumns
@routing_batch_function
def random_routing_batch(steps: List[str]) -> List[str]:
return random.sample(steps, 2)
with Pipeline(name="routing-batch-function") as pipeline:
load_data = LoadHubDataset()
generations = []
for llm in (
OpenAILLM(model="gpt-4-0125-preview"),
MistralLLM(model="mistral-large-2402"),
VertexAILLM(model="gemini-1.5-pro"),
):
task = TextGeneration(name=f"text_generation_with_{llm.model_name}", llm=llm)
generations.append(task)
combine_columns = CombineColumns(columns=["generation", "model_name"])
load_data >> random_routing_batch >> generations >> combine_columns
Source code in src/distilabel/pipeline/routing_batch_function.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
sample_n_steps(n)
¶
A simple function that creates a routing batch function that samples n
steps from
the list of all the downstream steps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
The number of steps to sample from the list of all the downstream steps. |
required |
Returns:
Type | Description |
---|---|
RoutingBatchFunction
|
A |
RoutingBatchFunction
|
the |
Example:
from distilabel.llms import MistralLLM, OpenAILLM, VertexAILLM
from distilabel.pipeline import Pipeline, sample_n_steps
from distilabel.steps import LoadHubDataset, CombineColumns
random_routing_batch = sample_n_steps(2)
with Pipeline(name="routing-batch-function") as pipeline:
load_data = LoadHubDataset()
generations = []
for llm in (
OpenAILLM(model="gpt-4-0125-preview"),
MistralLLM(model="mistral-large-2402"),
VertexAILLM(model="gemini-1.5-pro"),
):
task = TextGeneration(name=f"text_generation_with_{llm.model_name}", llm=llm)
generations.append(task)
combine_columns = CombineColumns(columns=["generation", "model_name"])
load_data >> random_routing_batch >> generations >> combine_columns