Skip to content

Commit

Permalink
prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasMoutawwakil committed Feb 20, 2024
1 parent 25593b1 commit 8c3e23d
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 87 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/publish_to_pypi.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

on:
release:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install requirements
run: |
pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload --repository pypi dist/*
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name: CPU Test
name: Test

on:
push:
branches: [main]
branches:
- main
pull_request:
branches: [main]
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
cpu_test:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -20,12 +22,12 @@ jobs:
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'
python-version: "3.10"

- name: Install requirements
run: |
pip install --upgrade pip
pip install -e .
- name: Run sanity check
run: python tests/sanity.py
- name: Run test
run: python tests/test.py
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# List of targets that are not associated with files
.PHONY: quality style install

quality:
ruff check .
ruff format --check .

style:
ruff format .
ruff check --fix .

install:
pip install -e .
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ pip install py-tgi
Running a TGI server with a batched inference client:

```python
# from logging import basicConfig, INFO
# basicConfig(level=INFO)
from logging import basicConfig, INFO
basicConfig(level=INFO) # to stream tgi container logs to stdout

from py_tgi import TGI

llm = TGI(model="TheBloke/Mistral-7B-Instruct-v0.1-AWQ", quantize="awq")

try:
output = llm.generate(["Hi, I'm an example 1", "Hi, I'm an example 2"])
print("Output:", output)
output = llm.generate(["Hi, I'm a language model", "I'm fine, how are you?"])
print(output)
except Exception as e:
print(e)
finally:
# make sure to close the server
llm.close()
```

Output: [".\n\nHi, I'm an example 2.\n\nHi, I'm", ".\n\nI'm a simple example of a class that has a method that returns a value"]
Output: ```[" and I'm here to help you with any questions you have. What can I help you with", "\nUser 0: I'm doing well, thanks for asking. I'm just a"]```
14 changes: 0 additions & 14 deletions example.py

This file was deleted.

20 changes: 6 additions & 14 deletions py_tgi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import time
from logging import getLogger
from concurrent.futures import ThreadPoolExecutor
from typing import Optional, Literal, List, Union
from logging import getLogger
from typing import List, Literal, Optional, Union

import docker
import docker.types
import docker.errors
import docker.types
from huggingface_hub import InferenceClient
from huggingface_hub.inference._text_generation import TextGenerationResponse

Expand Down Expand Up @@ -67,9 +67,7 @@ def __init__(
LOGGER.info("\t+ Checking if TGI image exists")
self.docker_client.images.get(f"{self.image}:{self.version}")
except docker.errors.ImageNotFound:
LOGGER.info(
"\t+ TGI image not found, downloading it (this may take a while)"
)
LOGGER.info("\t+ TGI image not found, downloading it (this may take a while)")
self.docker_client.images.pull(f"{self.image}:{self.version}")

env = {}
Expand Down Expand Up @@ -103,11 +101,7 @@ def __init__(
device_ids = get_nvidia_gpu_devices()

LOGGER.info(f"\t+ Using GPU(s): {device_ids}")
self.device_requests = [
docker.types.DeviceRequest(
device_ids=[device_ids], capabilities=[["gpu"]]
)
]
self.device_requests = [docker.types.DeviceRequest(device_ids=[device_ids], capabilities=[["gpu"]])]
except Exception:
LOGGER.info("\t+ No GPU detected")
self.device_requests = None
Expand Down Expand Up @@ -172,9 +166,7 @@ def generate(
elif isinstance(prompt, list):
with ThreadPoolExecutor(max_workers=len(prompt)) as executor:
futures = [
executor.submit(
self.tgi_client.text_generation, prompt=prompt[i], **kwargs
)
executor.submit(self.tgi_client.text_generation, prompt=prompt[i], **kwargs)
for i in range(len(prompt))
]

Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.ruff]
line-length = 120
lint.ignore = ["C901", "E501"]
lint.select = ["C", "E", "F", "I", "W", "I001"]

[tool.ruff.format]
line-ending = "auto"
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false

[tool.pytest.ini_options]
log_cli = true
log_cli_level = "INFO"
log_cli_format = "[%(asctime)s][%(name)s][%(levelname)s] - %(message)s"
15 changes: 7 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from setuptools import setup, find_packages
from pathlib import Path

PY_TGI_VERSION = "0.1.0"
from setuptools import find_packages, setup

PY_TGI_VERSION = "0.1.2"

common_setup_kwargs = {
"author": "Ilyas Moutawwakil",
Expand All @@ -10,22 +11,20 @@
"keywords": ["python", "tgi", "llm", "huggingface", "docker"],
"url": "https://github.com/IlyasMoutawwakil/py-tgi",
"long_description_content_type": "text/markdown",
"long_description": (Path(__file__).parent / "README.md").read_text(
encoding="UTF-8"
),
"long_description": (Path(__file__).parent / "README.md").read_text(encoding="UTF-8"),
"platforms": ["linux", "windows", "macos"],
"classifiers": [
"Environment :: GPU :: NVIDIA CUDA :: 11.8",
"Environment :: GPU :: NVIDIA CUDA :: 12",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Natural Language :: English",
],
}


setup(
name="py-tgi",
version=PY_TGI_VERSION,
packages=find_packages(),
install_requires=["docker", "huggingface-hub"],
extras_require={"quality": ["ruff"]},
**common_setup_kwargs,
)
3 changes: 2 additions & 1 deletion tests/sanity.py → tests/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from logging import basicConfig, INFO
from logging import INFO, basicConfig

from py_tgi import TGI

basicConfig(level=INFO)
Expand Down

0 comments on commit 8c3e23d

Please sign in to comment.