@step¶
This section contains the reference for the @step
decorator, used to create new Step
subclasses without having to manually define the class.
For more information check the Tutorial - Step page.
step(inputs=None, outputs=None, step_type='normal')
¶
Creates an Step
from a processing function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs |
Union[List[str], None]
|
a list containing the name of the inputs columns/keys expected by this step.
If not provided the default will be an empty list |
None
|
outputs |
Union[List[str], None]
|
a list containing the name of the outputs columns/keys that the step
will generate. If not provided the default will be an empty list |
None
|
step_type |
Literal['normal', 'global', 'generator']
|
the kind of step to create. Valid choices are: "normal" ( |
'normal'
|
Returns:
Type | Description |
---|---|
Callable[..., Type[_Step]]
|
A callable that will generate the type given the processing function. |
Example:
# Normal step
@step(inputs=["instruction"], outputs=["generation"])
def GenerationStep(inputs: StepInput, dummy_generation: RuntimeParameter[str]) -> StepOutput:
for input in inputs:
input["generation"] = dummy_generation
yield inputs
# Global step
@step(inputs=["instruction"], step_type="global")
def FilteringStep(inputs: StepInput, max_length: RuntimeParameter[int] = 256) -> StepOutput:
yield [
input
for input in inputs
if len(input["instruction"]) <= max_length
]
# Generator step
@step(outputs=["num"], step_type="generator")
def RowGenerator(num_rows: RuntimeParameter[int] = 500) -> GeneratorStepOutput:
data = list(range(num_rows))
for i in range(0, len(data), 100):
last_batch = i + 100 >= len(data)
yield [{"num": num} for num in data[i : i + 100]], last_batch
Source code in src/distilabel/steps/decorator.py
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 |
|