-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: awaelchli <[email protected]>
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
LitGPT developer documentation files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# LitGPT High-level Python API | ||
|
||
This is a work-in-progress draft for a high-level LitGPT Pyhon API. | ||
|
||
| ||
## Model loading & saving | ||
|
||
The `LLM.load` command loads an `llm` object, which contains both the model object (a PyTorch module) and a preprocessor. | ||
|
||
```python | ||
from litgpt import LLM | ||
|
||
llm = LLM.load( | ||
source="url | local_path", | ||
# high-level user only needs to care about those: | ||
memory_reduction="none | medium | strong" | ||
# advanced options for technical users: | ||
hub="hf | local | other" | ||
quantize="bnb.nf4", | ||
precision="bf16-true", | ||
device=""auto | cuda | cpu", | ||
) | ||
``` | ||
|
||
Here, | ||
|
||
- `llm.model` contains the PyTorch Module | ||
- and `llm.preprocessor.tokenizer` contains the tokenizer | ||
|
||
The `llm.save` command saves the model weights, tokenizer, and configuration information. | ||
|
||
|
||
```python | ||
llm.save(checkpoint_dir, format="lightning | ollama | hf") | ||
``` | ||
|
||
|
||
| ||
## Inference / Chat | ||
|
||
``` | ||
response = llm.generate( | ||
prompt="What do Llamas eat?", | ||
temperature=0.1, | ||
top_p=0.8, | ||
... | ||
) | ||
``` | ||
|
||
|
||
| ||
## Dataset | ||
|
||
The `llm.prepare_dataset` command prepares a dataset for training. | ||
|
||
``` | ||
llm.download_dataset( | ||
URL, | ||
... | ||
) | ||
``` | ||
|
||
``` | ||
dataset = llm.prepare_dataset( | ||
path, | ||
task="pretrain | instruction_finetune", | ||
test_portion=0.1, | ||
... | ||
) | ||
``` | ||
|
||
| ||
## Training | ||
|
||
|
||
```python | ||
llm.instruction_finetune( | ||
config=None, | ||
dataset=dataset, | ||
max_iter=10, | ||
method="full | lora | adapter | adapter_v2" | ||
) | ||
``` | ||
|
||
```python | ||
llm.pretrain(config=None, dataset=dataset, max_iter=10, ...) | ||
``` | ||
|
||
| ||
## Serving | ||
|
||
|
||
```python | ||
llm.serve(port=8000) | ||
``` | ||
|
||
Then in another Python session: | ||
|
||
```python | ||
import requests, json | ||
|
||
response = requests.post( | ||
"http://127.0.0.1:8000/predict", | ||
json={"prompt": "Fix typos in the following sentence: Exampel input"} | ||
) | ||
|
||
print(response.json()["output"]) | ||
``` |