Skip to content

Commit 49e6fc5

Browse files
committed
Propose simplifications to the SDG API design
See instructlab/sdg#61 for some of the discussion on this, but I've tried to summarize those discussions in the design doc. Signed-off-by: Mark McLoughlin <[email protected]>
1 parent 88f2461 commit 49e6fc5

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

.spellcheck-en-custom.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Colab
2020
compositional
2121
Conda
2222
config
23+
configs
2324
Containerfile
2425
cpp
2526
cuBLAS
@@ -28,6 +29,7 @@ customizations
2829
CWD
2930
Cynefin
3031
dataset
32+
datasets
3133
DCO
3234
Dependabot
3335
dev
@@ -100,9 +102,9 @@ PLOS
100102
PNG
101103
Podman
102104
podman
103-
PR's
104105
pre
105106
preprint
107+
PR's
106108
pyenv
107109
PyPI
108110
PyTorch
@@ -117,6 +119,7 @@ Ren
117119
repo
118120
ROCm
119121
RTX
122+
runtime
120123
RX
121124
SaaS
122125
safetensors
@@ -144,8 +147,8 @@ tl
144147
tox
145148
traigers
146149
triager
147-
triager's
148150
Triagers
151+
triager's
149152
triagers
150153
UI
151154
ui

docs/sdg/sdg-api-simplification.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SDG API Simplification
2+
3+
## Objective
4+
5+
Identify simplifications to [the original SDG API design](sdg-api-interface.md) based on retrospective insights from working with the implementation of that design.
6+
7+
## Original API Design
8+
9+
Consider the original API sketch:
10+
11+
```python
12+
from sdg import SDG
13+
from run_config import SynthDataFlow
14+
from pipeline import Pipeline
15+
import yaml
16+
17+
client = openai_client(endpoint)
18+
model = "model-version"
19+
20+
synth_skills_flow = SynthDataFlow(client, model).get_flow()
21+
skills_pipe = Pipeline(synth_skills_flow)
22+
23+
cli_sdg = SDG([synth_skills_flow]) # run config has all the variables like num_samples, pipelinesteps etc
24+
generated_samples = cli_sdg.generate()
25+
```
26+
27+
The nouns above are:
28+
29+
* 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
30+
* 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
31+
* Block config - a description of how to instantiate and invoke a block, a sequence of these is returned from `get_flow()` above
32+
* Flow - a class which describes how to render a sequence of block configs for a pipeline
33+
* 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
34+
* SDG - an SDG is created from a list of pipelines, and its generate() method calls pipelines in turn
35+
36+
## Simplification Proposals
37+
38+
### Remove `SDG`
39+
40+
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.
41+
42+
### Remove `Flow`
43+
44+
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.
45+
46+
### Add PipelineContext
47+
48+
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.
49+
50+
It would be much more straightforward if `Block` were able to access these runtime parameters via their parent `Pipeline`.
51+
52+
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.
53+
54+
## New API Design
55+
56+
```python
57+
ds = Dataset.from_list(samples)
58+
59+
ctx = PipelineContext(client, "mixtral", teacher_model)
60+
61+
knowledge_pipe = Pipeline.from_configs(ctx, [MMLU_BENCH_PIPELINE, SYNTH_KNOWLEDGE_PIPELINE])
62+
63+
gen_data = knowledge_pipe.generate(ds)
64+
```

0 commit comments

Comments
 (0)