Skip to content

Commit b4e8df2

Browse files
authored
Merge pull request #98 from oindrillac/sdg-api
added sdg api library design
2 parents c859a4b + 2be6833 commit b4e8df2

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

.spellcheck-en-custom.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Containerfile
2424
cpp
2525
cuBLAS
2626
CUDA
27+
customizations
2728
CWD
2829
dataset
2930
DCO

docs/images/sdg-api-interface.png

264 KB
Loading

docs/sdg/sdg-api-interface.md

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# SDG Library Design
2+
3+
## Objective
4+
5+
Library called `instructlab-sdg` that can be called per seed example that includes question and answer pairs, and context for grounded skills.
6+
7+
## Structure of the SDG Library
8+
9+
We propose the following structure for the SDG library. There will be config files that contain all the prompt templates for the pipelines.
10+
11+
```markdown
12+
- src/instructlab/sdg/
13+
- configs/
14+
- gen_q.yaml
15+
- gen_a.yaml
16+
- ...
17+
- init.py
18+
- block.py
19+
- llmblock.py
20+
- pipeline.py
21+
- sdg.py
22+
```
23+
24+
![example API interface](../images/sdg-api-interface.png)
25+
26+
## CLI
27+
28+
The CLI client uses the instructlab SDG library and provides it a run configuration with input parameters. The following represents a sample of what Library usage could look like.
29+
30+
```python
31+
# cli_driver.py
32+
33+
from sdg import SDG
34+
from run_config import SynthDataFlow
35+
from pipeline import Pipeline
36+
import yaml
37+
38+
client = openai_client(endpoint)
39+
model = "model-version"
40+
41+
synth_skills_flow = SynthDataFlow(client, model).get_flow()
42+
skills_pipe = Pipeline(synth_skills_flow)
43+
44+
cli_sdg = SDG([synth_skills_flow]) # run config has all the variables like num_samples, pipelinesteps etc
45+
generated_samples = cli_sdg.generate()
46+
```
47+
48+
As an initial integration milestone, we will modify the `generate_data` function in `instructlab.sdg.generate_data` to make use of the updated SDG API. This is the function the `ilab` CLI already uses, so modifying this implementation will allow us to get the updated SDG API in place without disrupting the CLI integration.
49+
50+
CLI integration will require additional changes later to allow passing in customizations to the SDG pipeline, but we will treat that as a follow-up implementation milestone.
51+
52+
The run configuration includes the necessary parameters for executing the SDG code library. It specifies the templates required for running the SDG code, the prompt template, and the default model system prompt template.
53+
54+
* `num_samples` is the number of synthetic samples that you wish to generate per seed example.
55+
* `num_procs` is the number of parallel processes that you want to run
56+
* `max_retry` is the maximum number of non-greedy retries you want to make if the `num_samples` is not reached. The number of samples in the generated output will be the samples achieved until `max_retry` is reached.
57+
* Pipeline steps contains the steps that you want to invoke in the SDG pipeline and the prompt configurations per step. The variable names of the blocks can be anything and the prompt configurations must be compatible with the teacher model.
58+
* `max_new_tokens` is the maximum number of tokens we want to generate. In other words, the size of the output sequence, not including the tokens in the prompt.
59+
* `model` is the name of the served up teacher model we would want to use to generate the synthetic data.
60+
* `model_prompt`: the default model prompt for the model.
61+
* `client` points to an OpenAI client used to interface with the model. Example of a client:
62+
63+
```python
64+
client = OpenAI(
65+
api_key=openai_api_key,
66+
base_url=openai_api_base,
67+
)
68+
```
69+
70+
```python
71+
# run_config.py
72+
class Flow(ABC):
73+
def __init__(self, client, model_id) -> None:
74+
self.client = client
75+
self.model_id = model_id
76+
77+
@abstractmethod
78+
def get_flow(self) -> list:
79+
pass
80+
81+
82+
class SynthDataFlow(Flow):
83+
def get_flow(self) -> list:
84+
return [
85+
{
86+
'block_type': LLMBlock,
87+
'block_config': {
88+
'block_name': "gen_q",
89+
'config_path': "configs/gen_q.yaml",
90+
'client': self.client,
91+
'model_id': self.model_id,
92+
'model_prompt': '<s> [INST] {prompt} [/INST]',
93+
'output_cols': ['question'],
94+
'batch_kwargs': {
95+
'num_procs': 8,
96+
'num_samples': 30,
97+
'batched': True,
98+
},
99+
'max_retry' : 5,
100+
'max_new_tokens': 10000
101+
```

0 commit comments

Comments
 (0)