Skip to content

Commit

Permalink
🚧 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Parfeniuk committed Jul 12, 2024
1 parent ae61346 commit 6264afe
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 105 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
TODO
name: Code Quality Check

on:
pull_request:
branches:
- main

jobs:
code_quality:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tox
run: tox

31 changes: 21 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,59 @@
.PHONY: install
install:
python -m pip install -r requirements.txt
python -m pip install .


.PHONY: install.dev
install.dev:
python -m pip install -e .[dev]
python -m pip install .[dev]


.PHONY: build
build:
python setup.py sdist bdist_wheel

.PHONY: style
style:
python -m ruff format src tests
python -m isort src tests
python -m flake8 src tests --max-line-length 88


.PHONY: types
types:
python -m mypy --check-untyped-defs


.PHONY: quality
quality:
python -m ruff check src tests
python -m black --check src tests
python -m isort --check src tests
python -m flake8 src tests --max-line-length 88
python -m mypy src
python -m mypy --check-untyped-defs


.PHONY: style
style:
python -m ruff format src tests
python -m isort src tests
python -m flake8 src tests --max-line-length 88


.PHONY: test
test:
python -m pytest -s -vvv --cache-clear tests


.PHONY: test.unit
test.unit:
python -m pytest tests/unit


.PHONY: test.integration
test.integration:
python -m pytest tests/integration


.PHONY: test.e2e
test.e2e:
python -m pytest tests/e2e



.PHONY: clean
clean:
rm -rf build
Expand Down
77 changes: 74 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,94 @@
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"


[tool.setuptools.packages.find]
where = ["src"]
include = ["*"]

[tool.setuptools.package-data]
guidellm = ["*"]


# ************************************************
# ********** Project Metadata **********
# ************************************************

[project]
name = "guidellm"
version = "0.1.0"
description = "Guidance platform for deploying and managing large language models."
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.8.0,<4.0"
license = { file = "LICENSE" }
authors = [ { name = "Neuralmagic, Inc." } ]
urls = { homepage = "https://github.com/neuralmagic/guidellm" }
dependencies = [
"click",
"datasets",
"loguru",
"numpy",
"openai",
"requests",
"transformers",
]

[project.optional-dependencies]
dev = [
"black",
"isort",
"mypy",
"pre-commit",
"pytest",
"ruff",
"sphinx",
"tox",
]
code_quality = [
"black",
"isort",
"mypy",
"pytest",
"ruff",
]


[project.entry-points.console_scripts]
guidellm = "guidellm.main:main"


# ************************************************
# ********** Code Quality Tools **********
# ************************************************

[tool.black]
line-length = 88
target-version = ['py38']


[tool.isort]
profile = "black"


[tool.mypy]
files = "src/guidellm"
python_version = '3.8'
warn_redundant_casts = true
warn_unused_ignores = true
show_error_codes = true
namespace_packages = true
exclude = ["venv", ".tox"]

# Silint "type import errors" as our 3rd-party libs does not have types
# Check: https://mypy.readthedocs.io/en/latest/config_file.html#import-discovery
follow_imports = 'silent'


[tool.ruff]
line-length = 88
exclude = ["build", "dist", "env", ".venv"]
lint.select = ["E", "F", "W"]

[tool.flake8]
max-line-length = 88

[tool.pytest.ini_options]
addopts = '-s -vvv --cache-clear'
Expand All @@ -27,4 +99,3 @@ markers = [
"sanity: detailed tests to ensure major functions work correctly",
"regression: tests to ensure that new changes do not break existing functionality"
]

64 changes: 0 additions & 64 deletions setup.py

This file was deleted.

14 changes: 9 additions & 5 deletions src/guidellm/backend/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import Iterator, List, Optional, Type, Union
from typing import Dict, Iterator, List, Optional, Type

from loguru import logger

Expand Down Expand Up @@ -41,7 +41,7 @@ class Backend(ABC):
An abstract base class with template methods for generative AI backends.
"""

_registry = {}
_registry: Dict[BackendEngine, "Type[Backend]"] = {}

@classmethod
def register(cls, backend_type: BackendEngine):
Expand All @@ -59,7 +59,7 @@ def inner_wrapper(wrapped_class: Type["Backend"]):
return inner_wrapper

@classmethod
def create(cls, backend_type: Union[str, BackendEngine], **kwargs) -> "Backend":
def create(cls, backend_type: BackendEngine, **kwargs) -> "Backend":
"""
Factory method to create a backend based on the backend type.
Expand All @@ -77,7 +77,7 @@ def create(cls, backend_type: Union[str, BackendEngine], **kwargs) -> "Backend":
logger.error(f"Unsupported backend type: {backend_type}")
raise ValueError(f"Unsupported backend type: {backend_type}")

return cls._registry[backend_type](**kwargs)
return Backend._registry[backend_type](**kwargs)

def submit(self, request: TextGenerationRequest) -> TextGenerationResult:
"""
Expand All @@ -91,14 +91,18 @@ def submit(self, request: TextGenerationRequest) -> TextGenerationResult:

logger.info(f"Submitting request with prompt: {request.prompt}")

result = TextGenerationResult(request=request)
# TODO: Doublecheck why do we need the result id
# result_id = str(uuid.uuid4())

result = TextGenerationResult(TextGenerationRequest(prompt=request.prompt))
result.start(request.prompt)

for response in self.make_request(request): # GenerativeResponse
if response.type_ == "token_iter" and response.add_token:
result.output_token(response.add_token)
elif response.type_ == "final":
result.end(
response.output or "",
response.prompt_token_count,
response.output_token_count,
)
Expand Down
4 changes: 2 additions & 2 deletions src/guidellm/core/distribution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Union
from typing import List, Optional, Union

import numpy as np
from loguru import logger
Expand All @@ -16,7 +16,7 @@ class Distribution:
:type data: List[Union[int, float]], optional
"""

def __init__(self, data: List[Union[int, float]] = None):
def __init__(self, data: Optional[List[Union[int, float]]] = None):
"""
Initialize the Distribution with optional data.
Expand Down
Loading

0 comments on commit 6264afe

Please sign in to comment.