Skip to content

Commit 7bcad36

Browse files
committed
introduce document for instructlab-sdk
Signed-off-by: Charlie Doern <[email protected]>
1 parent e12aeea commit 7bcad36

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

.spellcheck-en-custom.txt

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ agentic
66
Akash
77
AMDGPU
88
Anil
9+
annotater
10+
API
11+
api
912
arge
1013
args
1114
arXiv
@@ -215,6 +218,8 @@ Salawu
215218
scalable
216219
SDG
217220
sdg
221+
SDK
222+
sdk
218223
semvar
219224
sexualized
220225
SHA

docs/sdk/instructlab-sdk.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# InstructLab SDK
2+
3+
## Motivation
4+
5+
Today, the only way to "drive" the InstructLab opinionated workflow is via the `ilab` CLI. While this process provides a succinct way for everyday users to initialize a config, generate synthetic data, train a model, and evaluate it: the guardrails are quite limiting both in what a user can do and what the development team can add as features exposed directly to the user over time.
6+
7+
Additionally, current consumers of InstructLab are finding themselves importing different library private and public APIs in combination with CLI functionality to achieve the workflows they want. While these more advanced usage patterns are not for everyone, providing ways to run bespoke and piecemeal workflows in a standardized and safe way for the community is starting to seem like a necessity.
8+
9+
Unifying these various ranges of advanced workflows under an overarching `InstructLab SDK API` will allow for new usage patterns and a clearer story on what InstructLab can and should provide as user accessible endpoints.
10+
11+
While each library can and _should_ have their own publicly accessible API, not all functionality being added to SDG, Training, and Eval needs to be correlated directly to the "InstructLab workflow". This Python SDK should, as the CLI does, expose an opinionated flow that uses functionality from the various libraries. The InstructLab SDK should be derived from the library APIs, not the other way around. SDG, for example, currently has a `generate_data` method, meant to only be accessed by InstructLab. This method simply calls other publicly available SDG functionality. Orchestration of the InstructLab flow like this should not be of concern to the individual libraries and instead be handled by the overarching InstructLab SDK which will maintain the user contracts. The InstructLab SDK will need to work within the bounds of what the Libraries expose as public APIs.
12+
13+
The benefit of the above is that the opinionated flow can be accessed in a more nuanced and piecemeal way while also gaining the potential for more advanced features. Say a consumer wants to:
14+
15+
1. setup a custom config file for ilab (optional)
16+
2. initialize a taxonomy
17+
3. ensure their taxonomy is valid
18+
4. ingest some data for RAG and SDG (SDG coming soon)
19+
5. generate synthetic data using an InstructLab pipeline
20+
6. do some custom handling per their use case
21+
7. fine-tune a model using the custom config they initialized for their hardware
22+
23+
a user could do the following to accomplish this if they had an SDK:
24+
25+
```python
26+
instructlab.api.configuration.init(taxonomy=path_to_taxonomy)
27+
if instructlab.api.taxonomy.diff():
28+
instructlab.api.rag.ingest(...)
29+
instructlab.api.data.ingest(...)
30+
data_paths = instructlab.api.data.generate(...)
31+
some_custom_handling(data_paths)
32+
instructlab.api.model.train(data_path=..., strategy=lab_multiphase)
33+
```
34+
35+
However today, users are forced to run a sequence of commands tailored to only work with the proper directory structure on the system.
36+
37+
## Major Goals
38+
39+
1. Modularize the InstructLab workflow such that any part can be run independently
40+
2. Allow users to choose whether or not to take advantage of the config/system-profile method of running InstructLab. Meaning they do not need any pre-existing configuration to run the SDK.
41+
3. Standardize user contracts for the existing functionality of the InstructLab workflow. Existing CLI commands should be using the SDK once past click parsing, not separate code.
42+
4. Define Contracts loose enough that functionality can be expanded as more advanced features are released.
43+
5. Document SDK usage in upcoming InstructLab releases.
44+
45+
## Non-Goals
46+
47+
1. Exposing all library functionality immediately
48+
2. Replacing CLI
49+
3. Shipping an SDK that is generally available as opposed to v1alpha1 or v1beta1.
50+
51+
## Design
52+
53+
### Versioning
54+
55+
The SDK would start at version v1alpha1 such that it can change/break at any time for the first few iterations as libraries adjust their API surface.
56+
57+
### Structure
58+
59+
This SDK should live in a net new package inside of `instructlab/instructlab` preferably to limit unnecessary imports in a new repository. It could be imported as `instructlab.api...`
60+
61+
The user surface initially should look like this:
62+
63+
```console
64+
instructlab.api.configuration.init
65+
instructlab.api.taxonomy.diff
66+
instructlab.api.data.generate
67+
instructlab.api.data.list
68+
instructlab.api.model.train
69+
instructlab.api.model.evaluate
70+
instructlab.api.model.chat (one shot request probably)
71+
instructlab.api.model.serve (vLLM and llama-cpp-python)
72+
instructlab.api.model.download
73+
instructlab.api.model.list
74+
instructlab.api.system.info
75+
instructlab.api.rag.ingest
76+
instructlab.api.rag.convert
77+
```
78+
79+
These initial exposed functions can expand to include any new functionality that is more SDK oriented from the various libraries. For example, if SDG adds something like subset selection, teacher as annotater, data mixing, etc we could expose an `instructlab.api.data.annotate` or `instructlab.api.data.mix` that could be invoked in sequence in a user's script with other parts of the ilab workflow. Some things make _less_ sense to be exposed via a CLI, but still are critical to ensuring users get a good model and properly generated data.
80+
81+
There are certain things that only exist in `ilab` currently and functionality that is going to be moving these such as data ingestion, RAG, etc. Forming an SDK for `instructlab` allows us to capture all of these concerns under one API.
82+
83+
These endpoints in combination with the curated InstructLab Config File will open up these workflows to users and allow InstructLab to be easily incorporated into other projects. Allowing people to run things like data generation, and full fine-tuning via an SDK that pulls in their pre-existing config.yaml but also can be run independently will open new avenues for InstructLab adoption and extensibility.
84+
85+
## Changes to the CLI
86+
87+
The `ilab` CLI will need to adapt to this new structure. Commands like `ilab data generate` should, in terms of code, follow this flow:
88+
89+
1. `src/instructlab/cli/data/generate.py`
90+
2. `src/instructlab/data/generate.py`
91+
3. `src/instructlab/process.py`
92+
4. `src/instructlab/api/data/generate.py`
93+
94+
So generally: cli -> internal handling package -> process management package -> api -> library code, is the flow.
95+
96+
The flow of the CLI today is such that the cli package for a command (`src/instructlab/cli/data/generate.py`) parses the command line options, and passes control to the core code (`/src/instructlab/data/generate.py`). This then (if applicable), yields control to the `process` package which kicks off necessary processes for the given command.
97+
98+
The difference with an SDK is that we would eventually want to end up executing `api/data/generate.py`, the actual publicly consumable python SDK. This will ensure that the CLI can do whatever custom handling it needs to do on top, but eventually it must boil down to the `api` package which uses publicly available methods from the various libraries.
99+
100+
## Scope of work
101+
102+
In upcoming releases the InstructLab team should aim to:
103+
104+
1. Design the SDK given the structure above
105+
2. Converse with Library maintainers to negotiate user contracts
106+
3. Begin work to re-architect how the CLI works using the SDK
107+
4. Publish an alpha SDK for public consumption
108+
109+
After this initial work, the team can scope adding net new functionality that is not in the CLI to the SDK.

0 commit comments

Comments
 (0)