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

Propose simplifications to the SDG API design #113

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .spellcheck-en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Colab
compositional
Conda
config
configs
Containerfile
cpp
cuBLAS
Expand All @@ -28,6 +29,7 @@ customizations
CWD
Cynefin
dataset
datasets
DCO
Dependabot
dev
Expand Down Expand Up @@ -100,9 +102,9 @@ PLOS
PNG
Podman
podman
PR's
pre
preprint
PR's
pyenv
PyPI
PyTorch
Expand All @@ -117,6 +119,7 @@ Ren
repo
ROCm
RTX
runtime
RX
SaaS
safetensors
Expand Down Expand Up @@ -144,8 +147,8 @@ tl
tox
traigers
triager
triager's
Triagers
triager's
triagers
UI
ui
Expand Down
64 changes: 64 additions & 0 deletions docs/sdg/sdg-api-simplification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SDG API Simplification

## Objective

Identify simplifications to [the original SDG API design](sdg-api-interface.md) based on retrospective insights from working with the implementation of that design.

## Original API Design

Consider the original API sketch:

```python
from sdg import SDG
from run_config import SynthDataFlow
from pipeline import Pipeline
import yaml

client = openai_client(endpoint)
model = "model-version"

synth_skills_flow = SynthDataFlow(client, model).get_flow()
skills_pipe = Pipeline(synth_skills_flow)

cli_sdg = SDG([synth_skills_flow]) # run config has all the variables like num_samples, pipelinesteps etc
generated_samples = cli_sdg.generate()
```

The nouns above are:

* Dataset - this is from Hugging Face's datasets library - used for the return value from `SDG.generate()`, but also what is passed between elements of the data generation pipeline
* Block - not shown in the code above, but required to understand a pipeline - a block provides a `generate()` method transforms an input dataset and returns an output dataset
* Block config - a description of how to instantiate and invoke a block, a sequence of these is returned from `get_flow()` above
* Flow - a class which describes how to render a sequence of block configs for a pipeline
* Pipeline - a pipeline is created from a sequence of block configs, and provides a generate() method in which it instantiates and invokes blocks in turn, passing the input dataset and collecting the output
* SDG - an SDG is created from a list of pipelines, and its generate() method calls pipelines in turn

## Simplification Proposals

### Remove `SDG`

We don't need both SDG and Pipeline since Pipeline can already do everything SDG can do. If more advanced orchestration of multiple pipelines is required later, an orchestration abstraction can be added then.

### Remove `Flow`

With flows migrating to a YAML file format (#109), their purpose becomes more clear - they are simply an expression of the configuration of a sequence of blocks, used to create a pipeline. We can simply refer to these YAML files as pipeline descriptions.

### Add PipelineContext

A number of runtime parameters are required by blocks in a pipeline - e.g. every `LLMBlock` requires an OpenAI API client and a model name. These parameters are distinct from configuration that is specified by a pipeline author.

It would be much more straightforward if `Block` were able to access these runtime parameters via their parent `Pipeline`.

In the case where multiple pipelines with the same runtime context is desired, it would also be beneficial to abstract these runtime parameters into a `PipelineContext` class.

## New API Design

```python
ds = Dataset.from_list(samples)

ctx = PipelineContext(client, "mixtral", teacher_model)

knowledge_pipe = Pipeline.from_configs(ctx, [MMLU_BENCH_PIPELINE, SYNTH_KNOWLEDGE_PIPELINE])

gen_data = knowledge_pipe.generate(ds)
```