-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding LLM private fine-tuning example
- Loading branch information
1 parent
99cffa0
commit 5ed565c
Showing
59 changed files
with
352,497 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,2 @@ | ||
components/model-reference-relocation-server/models/gpt2-large/pytorch_model.bin filter=lfs diff=lfs merge=lfs -text | ||
components/model-relocation-server/models/gpt2/pytorch_model.bin filter=lfs diff=lfs merge=lfs -text |
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,162 @@ | ||
.DS_Store | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ |
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,86 @@ | ||
# Private Fine-Tuning | ||
|
||
Privately fine-tune a LLM using Parameter Efficient Fine-Tuning with private data. | ||
|
||
```mermaid | ||
graph TD; | ||
dataset-relocation-server-->dataset-pvc[(dataset-pvc)]; | ||
model-relocation-server-->base-model-pvc[(base-model-pvc)]; | ||
tokenizer-relocation-server-->base-tokenizer-pvc[(base-tokenizer-pvc)]; | ||
dataset-pvc-->model-peft-server; | ||
base-model-pvc-->model-peft-server; | ||
base-tokenizer-pvc-->model-peft-server; | ||
model-peft-server-->fine-tuned-model-pvc[(fine-tuned-model-pvc)]; | ||
model-reference-relocation-server-->reference-model-pvc[(reference-model-pvc)]; | ||
reference-model-pvc-->model-evaluation-server; | ||
tensorboard(((tensorboard)))-->fine-tuned-model-pvc; | ||
fine-tuned-model-pvc-->model-evaluation-server; | ||
fine-tuned-model-pvc-->inference-server; | ||
base-tokenizer-pvc-->inference-server; | ||
``` | ||
|
||
## [Pushing components to registries](docs/registries.md) | ||
|
||
## Updating the models | ||
|
||
Updating the base and reference models from GPT2 is a matter of updarting the files and the occurrences of `gpt2` in the code. | ||
|
||
> Because we are storing the full model, we need to track the large files using `git lfs` before pushing to a different GitHub repository: | ||
```bash | ||
git lfs track components/model-reference-relocation-server/models/gpt2-large/pytorch_model.bin | ||
git lfs track components/model-relocation-server/models/gpt2/pytorch_model.bin | ||
``` | ||
|
||
|
||
## Local development with KinD | ||
|
||
Single node required: | ||
|
||
```bash | ||
kind create cluster | ||
``` | ||
|
||
### Installing | ||
|
||
With skaffold everything can be built and run with one command for local iteration, the first time will take a while | ||
because all the images are being created. | ||
|
||
```bash | ||
skaffold run --port-forward=true | ||
``` | ||
|
||
> Note that the evaluation server takes over 80 minutes. | ||
But since the inference server is created in parallel, we can use it while evaluation happens. | ||
|
||
|
||
After running the `skaffold` command, it should display something like: | ||
```bash | ||
Waiting for deployments to stabilize... | ||
- deployment/model-inference-server is ready. | ||
Deployments stabilized in 4.135 seconds | ||
Port forwarding service/model-inference-service in namespace default, remote port 5000 -> http://127.0.0.1:5002 | ||
``` | ||
|
||
And the inference server is ready to receive requests: | ||
```bash | ||
curl -XPOST 127.0.0.1:5002/prompt -d '{"input_prompt":"What is the best hotel in Seville?"}' -H 'Content-Type: application/json' | ||
``` | ||
|
||
## Using KubeFlow | ||
|
||
KubeFlow automates all the creation of Kubernetes objects, their synchronization and adds utilities to help us with experiments and visualization. | ||
|
||
### Building the pipeline | ||
|
||
[Using the notebook](kubeflow/GeneratePipeline.ipynb) or running [pipeline.py](kubeflow/pipeline.py) | ||
|
||
### Visualising data in TensorBoard | ||
|
||
Select the PVC from `fine-tuned-model-pvc`. | ||
With the following mount path: `model/gpt2/logs/`. | ||
|
||
> Note that since some environments can't easily create Persistent Volumes with `ReadWriteMany`, we have to wait for completion or to delete the board once we analyzed it. |
1 change: 1 addition & 0 deletions
1
examples/llm_private_fine_tuning/components/dataset-relocation-server/.dockerignore
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 @@ | ||
k8s/ |
11 changes: 11 additions & 0 deletions
11
examples/llm_private_fine_tuning/components/dataset-relocation-server/Dockerfile
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,11 @@ | ||
FROM python:3.9 | ||
|
||
WORKDIR /code | ||
COPY ./requirements.txt /code/requirements.txt | ||
RUN pip install --upgrade pip | ||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt | ||
|
||
WORKDIR $HOME/app | ||
COPY . $HOME/app | ||
|
||
CMD ["python3", "app.py"] |
11 changes: 11 additions & 0 deletions
11
examples/llm_private_fine_tuning/components/dataset-relocation-server/app.py
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,11 @@ | ||
import argparse | ||
import shutil | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--dataset_destination_path', type=str, help='dataset destination path') | ||
|
||
opt = parser.parse_args() | ||
dataset_destination_path = opt.dataset_destination_path | ||
print("Relocating to: " + dataset_destination_path) | ||
shutil.copytree("./datasets", dataset_destination_path, dirs_exist_ok=True) |
Oops, something went wrong.