路由批处理函数¶
routing_batch_function
¶
RoutingBatchFunc = Callable[[List[str]], List[str]]
module-attribute
¶
路由批处理函数的类型别名。它接受所有下游步骤的列表,并返回一个列表,其中包含应接收批次的步骤的名称。
RoutingBatchFunction
¶
基类: BaseModel
, _Serializable
围绕路由批处理函数的轻量级包装器,可用于将来自一个上游步骤的批次路由到特定的下游步骤。
属性
名称 | 类型 | 描述 |
---|---|---|
routing_function |
RoutingBatchFunc
|
路由函数,它接受所有下游步骤的列表,并返回一个列表,其中包含应接收批次的步骤的名称。 |
_step |
Union[_Step, None]
|
连接到路由批处理函数的上游步骤。 |
_routed_batch_registry |
Dict[str, Dict[int, List[str]]]
|
一个字典,用于跟踪已路由到特定下游步骤的批次。 |
源代码位于 src/distilabel/pipeline/routing_batch_function.py
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 234 235 236 |
|
route_batch(batch, steps)
¶
从 steps
返回一个选定的下游步骤列表,batch
应该路由到这些步骤。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
batch
|
_Batch
|
应该路由的批次。 |
必需 |
steps
|
List[str]
|
可以接收批次的所有下游步骤的列表。 |
必需 |
返回值
类型 | 描述 |
---|---|
List[str]
|
一个列表,其中包含应接收批次的步骤的名称。 |
源代码位于 src/distilabel/pipeline/routing_batch_function.py
set_factory_function(factory_function_module, factory_function_name, factory_function_kwargs)
¶
设置用于创建 routing_batch_function
的工厂函数。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
factory_function_module
|
str
|
定义工厂函数的模块名称。 |
必需 |
factory_function_name
|
str
|
用于创建 |
必需 |
factory_function_kwargs
|
Dict[str, Any]
|
调用工厂函数时使用的关键字参数。 |
必需 |
源代码位于 src/distilabel/pipeline/routing_batch_function.py
__call__(batch, steps)
¶
从 steps
返回一个选定的下游步骤列表,batch
应该路由到这些步骤。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
batch
|
_Batch
|
应该路由的批次。 |
必需 |
steps
|
List[str]
|
可以接收批次的所有下游步骤的列表。 |
必需 |
返回值
类型 | 描述 |
---|---|
List[str]
|
一个列表,其中包含应接收批次的步骤的名称。 |
源代码位于 src/distilabel/pipeline/routing_batch_function.py
__rshift__(other)
¶
将下游步骤列表连接到路由批处理函数的上游步骤。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
other
|
List[DownstreamConnectableSteps]
|
应连接到路由批处理函数的上游步骤的下游步骤列表。 |
必需 |
返回值
类型 | 描述 |
---|---|
List[DownstreamConnectableSteps]
|
已连接到上游步骤的下游步骤列表 |
List[DownstreamConnectableSteps]
|
路由批处理函数。 |
源代码位于 src/distilabel/pipeline/routing_batch_function.py
dump(**kwargs)
¶
将路由批处理函数转储到字典,以及用于创建此路由批处理函数的工厂函数的信息。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
**kwargs
|
Any
|
应包含在转储中的其他关键字参数。 |
{}
|
返回值
类型 | 描述 |
---|---|
Dict[str, Any]
|
包含路由批处理函数信息和工厂函数的字典 |
Dict[str, Any]
|
信息。 |
源代码位于 src/distilabel/pipeline/routing_batch_function.py
from_dict(data)
classmethod
¶
从字典加载路由批处理函数。它必须包含用于创建路由批处理函数的工厂函数的信息。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
data
|
Dict[str, Any]
|
包含路由批处理函数信息和工厂函数信息的字典。 |
必需 |
源代码位于 src/distilabel/pipeline/routing_batch_function.py
routing_batch_function(description=None)
¶
创建一个路由批处理函数,该函数可用于将来自一个上游步骤的批次路由到特定的下游步骤。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
description
|
Optional[str]
|
路由批处理函数的可选描述。 |
None
|
返回值
类型 | 描述 |
---|---|
Callable[[RoutingBatchFunc], RoutingBatchFunction]
|
一个 |
Callable[[RoutingBatchFunc], RoutingBatchFunction]
|
定义 pipeline 时的 |
示例
from distilabel.models import MistralLLM, OpenAILLM, VertexAILLM
from distilabel.pipeline import Pipeline, routing_batch_function
from distilabel.steps import LoadDataFromHub, GroupColumns
@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 = LoadDataFromHub()
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 = GroupColumns(columns=["generation", "model_name"])
load_data >> random_routing_batch >> generations >> combine_columns
源代码位于 src/distilabel/pipeline/routing_batch_function.py
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 321 322 323 |
|
sample_n_steps(n)
¶
一个简单的函数,用于创建一个路由批处理函数,该函数从所有下游步骤的列表中采样 n
个步骤。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
n
|
int
|
要从所有下游步骤的列表中采样的步骤数。 |
必需 |
返回值
类型 | 描述 |
---|---|
RoutingBatchFunction
|
一个 |
RoutingBatchFunction
|
定义 pipeline 时的 |
示例
from distilabel.models import MistralLLM, OpenAILLM, VertexAILLM
from distilabel.pipeline import Pipeline, sample_n_steps
from distilabel.steps import LoadDataFromHub, GroupColumns
random_routing_batch = sample_n_steps(2)
with Pipeline(name="routing-batch-function") as pipeline:
load_data = LoadDataFromHub()
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 = GroupColumns(columns=["generation", "model_name"])
load_data >> random_routing_batch >> generations >> combine_columns