Skip to content

Commit

Permalink
[ci] easy for use: auto publish package and image
Browse files Browse the repository at this point in the history
  • Loading branch information
yezhengmao1 committed Jul 3, 2024
1 parent c23badc commit 147f6eb
Show file tree
Hide file tree
Showing 25 changed files with 241 additions and 117 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/pr-clean-code-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[ci_test]
pip install lizard flake8 black isort mypy
- name: CCN with Lizard
run: |
lizard -l python ./mlora -C 12
lizard -l python ./mlora_cli -C 12
- name: Lint with flake8
run: |
flake8 ./mlora --count --show-source --statistics --max-line-length=88 --max-complexity 15 --ignore=E203,W503,E704
flake8 ./mlora_cli --count --show-source --statistics --max-line-length=88 --max-complexity 15 --ignore=E203,W503,E704
- name: Lint with black
run: |
black --check ./mlora
black --check ./mlora_cli
- name: Lint with isort
run: |
isort ./mlora --check --profile black
isort ./mlora_cli --check --profile black
- name: Static code check with mypy
run: |
mypy ./mlora --ignore-missing-imports --non-interactive --install-types --check-untyped-defs
mypy ./mlora_cli --ignore-missing-imports --non-interactive --install-types --check-untyped-defs
- name: Test with pytest
run: |
pytest
22 changes: 15 additions & 7 deletions .github/workflows/pre-commit
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#!/bin/bash

lizard -l python ./mlora -C 12
check_dir=(
"./mlora"
"./mlora_cli"
)

black --check ./mlora
for dir in ${check_dir[*]}; do
lizard -l python ${dir} -C 12

black --check ${dir}

isort ${dir} --check --profile black

flake8 ${dir} --count --show-source --statistics --max-line-length=88 --max-complexity 15 --ignore=E203,W503,E704

mypy ${dir} --ignore-missing-imports --non-interactive --install-types --check-untyped-defs
done

isort ./mlora --check --profile black

flake8 ./mlora --count --show-source --statistics --max-line-length=88 --max-complexity 15 --ignore=E203,W503,E704

mypy ./mlora --ignore-missing-imports --non-interactive --install-types --check-untyped-defs

pytest
13 changes: 13 additions & 0 deletions Dockerfile.deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM yezhengmaolove/mlora:latest

MAINTAINER YeZhengMao <[email protected]>

WORKDIR /mLoRA

RUN git pull \
&& /usr/bin/echo -e '#!/bin/bash\neval "$(pyenv init -)"\neval "$(pyenv virtualenv-init -)"\npython mlora_server.py --base_model $BASE_MODEL --root $STORAGE_DIR' | tee /opt/deploy.sh

ENV PYENV_ROOT=/root/.pyenv
ENV PATH "$PYENV_ROOT/bin/:$PATH"

CMD /bin/bash /opt/deploy.sh
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mLoRA (a.k.a Multi-LoRA Fine-Tune) is an open-source framework designed for effi
The end-to-end architecture of the mLoRA is shown in the figure:

<div align="center">
<img src="./docs/assets/architecture.jpg" width=50%">
<img src="./docs/assets/architecture.jpg" width=70%">
</div>


Expand All @@ -44,9 +44,9 @@ cd mLoRA
pip install .
```

The `mlora.py` code is a starting point for batch fine-tuning LoRA adapters.
The `mlora_train.py` code is a starting point for batch fine-tuning LoRA adapters.
```bash
python mlora.py \
python mlora_train.py \
--base_model TinyLlama/TinyLlama-1.1B-Chat-v0.4 \
--config demo/lora/lora_case_1.yaml
```
Expand All @@ -55,7 +55,7 @@ You can check the adapters' configuration in [demo](./demo/) folder, there are s

For further detailed usage information, please use `--help` option:
```bash
python mlora.py --help
python mlora_train.py --help
```

## Quickstart with Docker
Expand All @@ -79,34 +79,37 @@ ssh root@localhost -p <host_port>
# pull the latest code and run the mlora
cd /mLoRA
git pull
python mlora.py \
python mlora_train.py \
--base_model TinyLlama/TinyLlama-1.1B-Chat-v0.4 \
--config demo/lora/lora_case_1.yaml
```

## Deploy as service
## Deploy as service with Docker
We can deploy mLoAR as a service to continuously receive user requests and perform fine-tuning task.

[![asciicast](https://asciinema.org/a/IifqdtBoJAVP4r8wg1lrcm9LI.svg)](https://asciinema.org/a/IifqdtBoJAVP4r8wg1lrcm9LI)
First, you should pull the latest image (for deploy):

```bash
# Install requirements for deploy
pip install .[deploy]
# Start the server
python mlora_server.py \
--base_model /data/TinyLlama-1.1B-Chat-v1.0/ \
--root /tmp/mlora
docker pull yezhengmaolove/mlora:deploy_latest
```
For further detailed usage information, please use `--help` option:

Deploy our mLoRA server:
```bash
python mlora_server.py --help
docker run -itd --runtime nvidia --gpus all \
-v ~/your_dataset_cache_dir:/cache \
-v ~/your_model_dir:/model \
-p <host_port>:8000 \
--name mlora_server \
-e "BASE_MODEL=TinyLlama/TinyLlama-1.1B-Chat-v0.4" \
-e "STORAGE_DIR=/cache" \
yezhengmaolove/mlora:deploy_latest
```

Once the service is deployed, use `mlora_cli.py` to interact with the server.
Once the service is deployed, install and use `mlora_cli.py` to interact with the server.

```bash
python mlora_cli.py
# install the client tools
pip install mlora-cli
```

## Why you should use mLoRA
Expand Down
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

ln -sf pyproject.cli.toml pyproject.toml
python -m build .

ln -sf pyproject.mlora.toml pyproject.toml
python -m build .
Binary file modified docs/assets/architecture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 0 additions & 9 deletions mlora/cli/setting.py

This file was deleted.

1 change: 0 additions & 1 deletion mlora/utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import torch

import mlora
import mlora.profiler


Expand Down
38 changes: 0 additions & 38 deletions mlora_cli.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions mlora_cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "mlora_cli"
version = "0.2"
description = "A cli tool for mLoRA system."
readme = "README.md"
requires-python = ">=3.12"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
]
dependencies = ["rich", "InquirerPy"]

[project.urls]
"Homepage" = "https://github.com/TUDB-Labs/mLoRA"
"Bug Tracker" = "https://github.com/TUDB-Labs/mLoRA/issues"

[tool.setuptools.packages.find]
include = [".*"]
32 changes: 32 additions & 0 deletions mlora_cli/setting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
G_PORT = 8000
G_HOST = "http://127.0.0.1"


def url() -> str:
global G_HOST
global G_PORT

return G_HOST + ":" + str(G_PORT)


def help_set():
print("Usage of a set:")
print(" host")
print(" set the host.")
print(" port")
print(" set the port.")


def do_set(_, args):
args = args.split(" ")

global G_PORT
global G_HOST

if args[0] == "host":
G_HOST = args[1]
elif args[0] == "port":
# convert to int to check
G_PORT = int(args[1])
else:
help_set()
46 changes: 46 additions & 0 deletions mlora_cli/shell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import cmd

from .adapter import do_adapter, help_adapter
from .dataset import do_dataset, help_dataset
from .dispatcher import do_dispatcher, help_dispatcher
from .file import do_file, help_file
from .setting import do_set, help_set
from .task import do_task, help_task


def help_quit(_):
print("Quit the cli")


def do_quit(*_):
exit(0)


class mLoRAShell(cmd.Cmd):
intro = "Welcome to the mLoRA CLI. Type help or ? to list commands.\n"
prompt = "(mLoRA) "

help_quit = help_quit
do_quit = do_quit

help_dispatcher = help_dispatcher
do_dispatcher = do_dispatcher

help_file = help_file
do_file = do_file

help_dataset = help_dataset
do_dataset = do_dataset

help_adapter = help_adapter
do_adapter = do_adapter

help_task = help_task
do_task = do_task

help_set = help_set
do_set = do_set


def cmd_loop():
mLoRAShell().cmdloop()
File renamed without changes.
4 changes: 4 additions & 0 deletions mlora_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from mlora_cli.shell import cmd_loop

if __name__ == "__main__":
cmd_loop()
6 changes: 5 additions & 1 deletion mlora_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def backend_server_run_fn(args):
mLoRAServer.include_router(mlora.server.adapter_router)
mLoRAServer.include_router(mlora.server.task_router)

web_thread = threading.Thread(target=uvicorn.run, args=(mLoRAServer,))
web_thread = threading.Thread(
target=uvicorn.run,
args=(mLoRAServer,),
kwargs={"host": "0.0.0.0", "port": 8000},
)

logging.info("Start the backend web server run thread")
web_thread.start()
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions pyproject.cli.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[project]
name = "mlora_cli"
version = "0.2.1"
description = "The cli tools for mLoRA system."
readme = "README.md"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
]
dependencies = ["requests", "rich", "InquirerPy"]

[project.urls]
"Homepage" = "https://github.com/TUDB-Labs/mLoRA"
"Bug Tracker" = "https://github.com/TUDB-Labs/mLoRA/issues"

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
include = ["mlora_cli", "mlora_cli.*"]

[project.scripts]
mlora_cli = "mlora_cli.shell:cmd_loop"
Loading

0 comments on commit 147f6eb

Please sign in to comment.