Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Refactor & Model Manager #101

Merged
merged 3 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ENV TZ=Europe/Amsterdam

WORKDIR /usr/src/app

COPY --chmod=0755 compile.sh .
COPY --chmod=0755 scripts/compile.sh .

# Install MongoDB and necessary tools
RUN apt update && \
Expand All @@ -23,11 +23,7 @@ RUN apt update && \
apt-get install -y mongodb-org && \
git clone https://github.com/ggerganov/llama.cpp.git --branch master-d5850c5


# copy & install python reqs
COPY ./api/requirements.txt api/requirements.txt
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r ./api/requirements.txt
RUN pip install --upgrade pip

# Dev environment
FROM base as dev
Expand All @@ -38,11 +34,7 @@ COPY --from=node_base /usr/local /usr/local
COPY ./web/package*.json ./
RUN npm ci

# Copy the rest of the project files
COPY web /usr/src/app/web
COPY ./api /usr/src/app/api

COPY --chmod=0755 dev.sh /usr/src/app/dev.sh
COPY --chmod=0755 scripts/dev.sh /usr/src/app/dev.sh
CMD ./dev.sh

# Build frontend
Expand All @@ -64,6 +56,7 @@ WORKDIR /usr/src/app
COPY --from=frontend_builder /usr/src/app/web/build /usr/src/app/api/static/
COPY ./api /usr/src/app/api

COPY --chmod=0755 deploy.sh /usr/src/app/deploy.sh
RUN pip install ./api

COPY --chmod=0755 scripts/deploy.sh /usr/src/app/deploy.sh
CMD ./deploy.sh
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ cd serge
docker compose up --build -d
docker compose exec serge python3 /usr/src/app/api/utils/download.py tokenizer 7B
```
Please note that the models occupy the following storage space: 7B requires 4.21G, 13B requires 8.14G, and 30B requires 20.3G

#### Windows

Expand Down
160 changes: 160 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 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/
2 changes: 2 additions & 0 deletions api/poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
create = false
66 changes: 66 additions & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[tool.poetry]
name = "serge"
description = "Serge API package"
version = "0.1.0"
license = "MIT"
authors = [
"Nathan Sarrazin <contact@nsarrazin.com>"
]

packages = [
{ include = "serge", from = "src" }
]

homepage = "https://serge.chat/"
repository = "https://github.com/nsarrazin/serge"

include = [{path="src"}]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.dependencies]
python=">=3.10,<4.0"
asyncio = "^3.4.3"
packaging = "^23.0"
pydantic = "^1.10.7"
pymongo = "^4.3.3"
python-dotenv = "^1.0.0"
python-multipart = "^0.0.6"
pyyaml = "^6.0"
rfc3986 = "^2.0.0"
sentencepiece = "^0.1.97"
sniffio = "^1.3.0"
sse-starlette = "^1.3.3"
starlette = "^0.26.1"
toml = "^0.10.2"
tqdm = "^4.65.0"
typing-extensions = "^4.5.0"
ujson = "^5.7.0"
urllib3 = "^1.26.15"
uvicorn = "^0.21.1"
uvloop = "^0.17.0"
watchfiles = "^0.19.0"
websockets = "^10.4"
anyio = "^3.6.2"
certifi = "^2022.12.7"
charset-normalizer = "^3.1.0"
click = "^8.1.3"
email-validator = "^1.3.1"
fastapi = "^0.95.0"
filelock = "^3.10.7"
h11 = "^0.14.0"
httpcore = "^0.17.0"
httptools = "^0.5.0"
huggingface-hub = "^0.13.3"
idna = "^3.4"
itsdangerous = "^2.1.2"
jinja2 = "^3.1.2"
markupsafe = "^2.1.2"
motor = "^3.1.1"
orjson = "^3.8.8"
beanie = "^1.17.0"
dnspython = "^2.3.0"
lazy-model = "^0.0.5"
requests = "^2.28.2"
44 changes: 0 additions & 44 deletions api/requirements.txt

This file was deleted.

8 changes: 8 additions & 0 deletions api/src/serge/dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .utils.convert import convert_all
import anyio


async def convert_model_files():
await anyio.to_thread.run_sync(
convert_all, "/usr/src/app/weights/", "/usr/src/app/weights/tokenizer.model"
)
Loading