Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add step decorator #387

Merged
merged 8 commits into from
Mar 7, 2024
Merged

Add step decorator #387

merged 8 commits into from
Mar 7, 2024

Conversation

gabrielmbmb
Copy link
Member

@gabrielmbmb gabrielmbmb commented Mar 6, 2024

Description

This PR adds the step decorator which allows to create an Step, GlobalStep or GeneratorStep defining its process function. It will allow creating simpler steps more easily, but for more complex steps the recommended way is to use the inheritance method.

Closes #374

# 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

@gabrielmbmb gabrielmbmb self-assigned this Mar 7, 2024
@gabrielmbmb gabrielmbmb added the enhancement New feature or request label Mar 7, 2024
@gabrielmbmb gabrielmbmb added this to the 1.0.0 milestone Mar 7, 2024
@gabrielmbmb gabrielmbmb marked this pull request as ready for review March 7, 2024 09:25
@gabrielmbmb gabrielmbmb linked an issue Mar 7, 2024 that may be closed by this pull request
@gabrielmbmb gabrielmbmb merged commit 5c256a1 into core-refactor Mar 7, 2024
4 checks passed
@gabrielmbmb gabrielmbmb deleted the step_decorator branch March 7, 2024 11:16
alvarobartt added a commit that referenced this pull request Mar 8, 2024
alvarobartt added a commit that referenced this pull request Mar 8, 2024
* Add `input` propagation through `Task.process`

* Fix `StepInput` import not updated as of #387

* Use `list` over `set` to preserve order in `combine_dicts`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@step decorator to easily create steps
1 participant