Skip to content

Commit

Permalink
Fixes for pip install, rename classes to standardize for requests and…
Browse files Browse the repository at this point in the history
… responses, restructure tests and begin working to get them passing
  • Loading branch information
markurtz committed Jun 14, 2024
1 parent 297d480 commit 2287517
Show file tree
Hide file tree
Showing 48 changed files with 1,309 additions and 1,445 deletions.
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
install:
pip install -r requirements.txt

install-dev:
pip install -e .[dev]

quality:
ruff check src tests
isort --check-only src tests
flake8 src tests --max-line-length 88
mypy src

style:
ruff format src tests
isort src tests
flake8 src tests --max-line-length 88

# test:
# pytest tests

build:
python setup.py sdist bdist_wheel

clean:
rm -rf __pycache__
rm -rf build
rm -rf dist
rm -rf *.egg-info
find . -type f -name "*.pyc" -delete
find . -type d -name "__pycache__" -exec rm -r {} +
rm -rf .mypy_cache
rm -rf .pytest_cache

.PHONY: install install-dev quality style test test-unit test-integration test-e2e test-smoke test-sanity test-regression build clean
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

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

[tool.isort]
profile = "black"

[tool.mypy]
files = "src/guidellm"

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

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

[tool.pytest.ini_options]
markers = [
"smoke: quick tests to check basic functionality",
"sanity: detailed tests to ensure major functions work correctly",
"regression: tests to ensure that new changes do not break existing functionality"
]

63 changes: 63 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from setuptools import setup, find_packages
from typing import Tuple


def _setup_long_description() -> Tuple[str, str]:
return open("README.md", "r", encoding="utf-8").read(), "text/markdown"


setup(
name='guidellm',
version='0.1.0',
author='Neuralmagic, Inc.',
description='Guidance platform for deploying and managing large language models.',
long_description=_setup_long_description()[0],
long_description_content_type=_setup_long_description()[1],
license="Apache",
url="https://github.com/neuralmagic/guidellm",
packages=find_packages(where='src'),
package_dir={'': 'src'},
include_package_data=True,
install_requires=[
'datasets',
'loguru',
'numpy',
'openai',
'requests',
'transformers',
],
extras_require={
'dev': [
'pytest',
'sphinx',
'ruff',
'mypy',
'black',
'isort',
'flake8',
'pre-commit',
],
},
entry_points={
'console_scripts': [
'guidellm=guidellm.main:main',
],
},
python_requires=">=3.8.0",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Intended Audience :: Developers",
"Intended Audience :: Education",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX :: Linux",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
11 changes: 9 additions & 2 deletions src/guidellm/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
from .base import *
from .openai import *
from .base import Backend, BackendTypes, GenerativeResponse
from .openai import OpenAIBackend

__all__ = [
"Backend",
"BackendTypes",
"GenerativeResponse",
"OpenAIBackend",
]
32 changes: 18 additions & 14 deletions src/guidellm/backend/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import uuid
from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import Iterator, List, Optional, Type, Union
from dataclasses import dataclass
import uuid

from loguru import logger
from guidellm.core.result import BenchmarkResult
from guidellm.core.request import BenchmarkRequest

from guidellm.core.request import TextGenerationRequest
from guidellm.core.result import TextGenerationResult

__all__ = ["Backend", "BackendTypes", "GenerativeResponse"]

Expand Down Expand Up @@ -69,18 +71,18 @@ def create_backend(backend_type: Union[str, BackendTypes], **kwargs) -> "Backend
raise ValueError(f"Unsupported backend type: {backend_type}")
return Backend._registry[backend_type](**kwargs)

def submit(self, request: BenchmarkRequest) -> BenchmarkResult:
def submit(self, request: TextGenerationRequest) -> TextGenerationResult:
"""
Submit a benchmark request and populate the BenchmarkResult.
Submit a result request and populate the BenchmarkResult.
:param request: The benchmark request to submit.
:type request: BenchmarkRequest
:return: The populated benchmark result.
:rtype: BenchmarkResult
:param request: The result request to submit.
:type request: TextGenerationRequest
:return: The populated result result.
:rtype: TextGenerationResult
"""
logger.info(f"Submitting request with prompt: {request.prompt}")
result_id = str(uuid.uuid4())
result = BenchmarkResult(result_id)
result = TextGenerationResult(result_id)
result.start(request.prompt)

for response in self.make_request(request):
Expand All @@ -98,12 +100,14 @@ def submit(self, request: BenchmarkRequest) -> BenchmarkResult:
return result

@abstractmethod
def make_request(self, request: BenchmarkRequest) -> Iterator[GenerativeResponse]:
def make_request(
self, request: TextGenerationRequest
) -> Iterator[GenerativeResponse]:
"""
Abstract method to make a request to the backend.
:param request: The benchmark request to submit.
:type request: BenchmarkRequest
:param request: The result request to submit.
:type request: TextGenerationRequest
:return: An iterator over the generative responses.
:rtype: Iterator[GenerativeResponse]
"""
Expand Down
26 changes: 17 additions & 9 deletions src/guidellm/backend/openai.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from typing import Any, Iterator, List, Optional

import openai
from typing import Iterator, List, Optional, Dict, Any
from transformers import AutoTokenizer
from loguru import logger
from transformers import AutoTokenizer

from guidellm.backend import Backend, BackendTypes, GenerativeResponse
from guidellm.core.request import BenchmarkRequest
from guidellm.core.request import TextGenerationRequest

__all__ = ["OpenAIBackend"]


@Backend.register_backend(BackendTypes.OPENAI_SERVER)
class OpenAIBackend(Backend):
"""
An OpenAI backend implementation for the generative AI benchmark.
An OpenAI backend implementation for the generative AI result.
:param target: The target URL string for the OpenAI server.
:type target: str
Expand Down Expand Up @@ -58,15 +60,18 @@ def __init__(
self.model = self.default_model()

logger.info(
f"Initialized OpenAIBackend with target: {self.target} and model: {self.model}"
f"Initialized OpenAIBackend with target: {self.target} "
f"and model: {self.model}"
)

def make_request(self, request: BenchmarkRequest) -> Iterator[GenerativeResponse]:
def make_request(
self, request: TextGenerationRequest
) -> Iterator[GenerativeResponse]:
"""
Make a request to the OpenAI backend.
:param request: The benchmark request to submit.
:type request: BenchmarkRequest
:param request: The result request to submit.
:type request: TextGenerationRequest
:return: An iterator over the generative responses.
:rtype: Iterator[GenerativeResponse]
"""
Expand All @@ -84,7 +89,10 @@ def make_request(self, request: BenchmarkRequest) -> Iterator[GenerativeResponse
request_args.update(self.request_args)

response = openai.Completion.create(
engine=self.model, prompt=request.prompt, stream=True, **request_args,
engine=self.model,
prompt=request.prompt,
stream=True,
**request_args,
)

for chunk in response:
Expand Down
22 changes: 19 additions & 3 deletions src/guidellm/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
from .distribution import *
from .request import *
from .result import *
from .distribution import Distribution
from .request import TextGenerationRequest
from .result import (
RequestConcurrencyMeasurement,
TextGenerationBenchmark,
TextGenerationBenchmarkReport,
TextGenerationError,
TextGenerationResult,
)

__all__ = [
"Distribution",
"TextGenerationRequest",
"TextGenerationResult",
"TextGenerationError",
"TextGenerationBenchmark",
"TextGenerationBenchmarkReport",
"RequestConcurrencyMeasurement",
]
Loading

0 comments on commit 2287517

Please sign in to comment.