Skip to content

Commit

Permalink
fix: persistent styling between ruff and yapf (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnphm authored Aug 30, 2023
1 parent f678f71 commit c9cef1d
Show file tree
Hide file tree
Showing 145 changed files with 1,049 additions and 393 deletions.
1 change: 1 addition & 0 deletions cz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tokenize

from tabulate import tabulate

TOKEN_WHITELIST = [token.OP, token.NAME, token.NUMBER, token.STRING]

def run_cz(dir: str, package: str):
Expand Down
1 change: 1 addition & 0 deletions examples/bentoml-demo/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import bentoml
import openllm

model = "dolly-v2"

llm_config = openllm.AutoConfig.for_model(model)
Expand Down
1 change: 1 addition & 0 deletions examples/langchain-tools-demo/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import bentoml
from bentoml.io import Text

SAMPLE_INPUT = "What is the weather in San Francisco?"

llm = OpenLLM(model_name="dolly-v2", model_id="databricks/dolly-v2-7b", embedded=False,)
Expand Down
8 changes: 6 additions & 2 deletions openllm-client/src/openllm_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import annotations

from . import benmin as benmin
from ._base import BaseAsyncClient as BaseAsyncClient, BaseClient as BaseClient
from .client import AsyncGrpcClient as AsyncGrpcClient, AsyncHTTPClient as AsyncHTTPClient, GrpcClient as GrpcClient, HTTPClient as HTTPClient
from ._base import BaseAsyncClient as BaseAsyncClient
from ._base import BaseClient as BaseClient
from .client import AsyncGrpcClient as AsyncGrpcClient
from .client import AsyncHTTPClient as AsyncHTTPClient
from .client import GrpcClient as GrpcClient
from .client import HTTPClient as HTTPClient
22 changes: 17 additions & 5 deletions openllm-client/src/openllm_client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import functools
import logging
import typing as t

from http import HTTPStatus
from urllib.parse import urljoin

Expand All @@ -12,14 +13,23 @@
import orjson

import openllm_core
from openllm_core._typing_compat import LiteralString, overload
from openllm_core.utils import bentoml_cattr, ensure_exec_coro, is_transformers_available, is_transformers_supports_agent

from .benmin import AsyncClient as AsyncBentoClient, Client as BentoClient
from openllm_core._typing_compat import LiteralString
from openllm_core._typing_compat import overload
from openllm_core.utils import bentoml_cattr
from openllm_core.utils import ensure_exec_coro
from openllm_core.utils import is_transformers_available
from openllm_core.utils import is_transformers_supports_agent

from .benmin import AsyncClient as AsyncBentoClient
from .benmin import Client as BentoClient

if t.TYPE_CHECKING:
import transformers

from openllm_core._typing_compat import DictStrAny, LiteralRuntime
from openllm_core._typing_compat import DictStrAny
from openllm_core._typing_compat import LiteralRuntime

logger = logging.getLogger(__name__)

@attr.define(slots=False, init=False)
Expand Down Expand Up @@ -204,7 +214,9 @@ async def ask_agent(self, task: str, *, return_code: bool = False, remote: bool
async def _run_hf_agent(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
if not is_transformers_supports_agent(): raise RuntimeError('This version of transformers does not support agent.run. Make sure to upgrade to transformers>4.30.0')
if len(args) > 1: raise ValueError("'args' should only take one positional argument.")
from transformers.tools.agents import clean_code_for_run, get_tool_creation_code, resolve_tools
from transformers.tools.agents import clean_code_for_run
from transformers.tools.agents import get_tool_creation_code
from transformers.tools.agents import resolve_tools
from transformers.tools.python_interpreter import evaluate

task = kwargs.pop('task', args[0])
Expand Down
5 changes: 4 additions & 1 deletion openllm-client/src/openllm_client/benmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
"""
from __future__ import annotations
import typing as t

from abc import abstractmethod

import attr
import httpx

import bentoml
if t.TYPE_CHECKING: from bentoml._internal.service.inference_api import InferenceAPI

if t.TYPE_CHECKING:
from bentoml._internal.service.inference_api import InferenceAPI

__all__ = ['Client', 'AsyncClient']

Expand Down
18 changes: 14 additions & 4 deletions openllm-client/src/openllm_client/benmin/_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@
import typing as t

import bentoml

from bentoml._internal.service.inference_api import InferenceAPI
from bentoml.grpc.utils import import_generated_stubs, load_from_file
from openllm_client.benmin import AsyncClient, Client
from openllm_core._typing_compat import NotRequired, overload
from openllm_core.utils import ensure_exec_coro, is_grpc_available, is_grpc_health_available
from bentoml.grpc.utils import import_generated_stubs
from bentoml.grpc.utils import load_from_file
from openllm_client.benmin import AsyncClient
from openllm_client.benmin import Client
from openllm_core._typing_compat import NotRequired
from openllm_core._typing_compat import overload
from openllm_core.utils import ensure_exec_coro
from openllm_core.utils import is_grpc_available
from openllm_core.utils import is_grpc_health_available

if not is_grpc_available() or not is_grpc_health_available(): raise ImportError("gRPC is required to use gRPC client. Install with 'pip install \"openllm-client[grpc]\"'.")
import grpc
import grpc_health.v1.health_pb2 as pb_health
import grpc_health.v1.health_pb2_grpc as services_health

from google.protobuf import json_format
from grpc import aio

pb, services = import_generated_stubs('v1')

if t.TYPE_CHECKING:
from bentoml.grpc.v1.service_pb2 import ServiceMetadataResponse

logger = logging.getLogger(__name__)

class ClientCredentials(t.TypedDict):
Expand Down
6 changes: 5 additions & 1 deletion openllm-client/src/openllm_client/benmin/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import typing as t
import urllib.error

from urllib.parse import urlparse

import httpx
Expand All @@ -14,9 +15,12 @@
import starlette.responses

import bentoml

from bentoml._internal.service.inference_api import InferenceAPI
from openllm_client.benmin import AsyncClient, Client
from openllm_client.benmin import AsyncClient
from openllm_client.benmin import Client
from openllm_core.utils import ensure_exec_coro

logger = logging.getLogger(__name__)

class HttpClient(Client):
Expand Down
5 changes: 4 additions & 1 deletion openllm-client/src/openllm_client/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import annotations
import logging

from urllib.parse import urlparse

from ._base import BaseAsyncClient, BaseClient
from ._base import BaseAsyncClient
from ._base import BaseClient

logger = logging.getLogger(__name__)

def process_http_address(self: AsyncHTTPClient | HTTPClient, address: str) -> None:
Expand Down
73 changes: 42 additions & 31 deletions openllm-core/src/openllm_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
from __future__ import annotations

from . import exceptions as exceptions, utils as utils
from ._configuration import GenerationConfig as GenerationConfig, LLMConfig as LLMConfig, SamplingParams as SamplingParams
from ._schema import EmbeddingsOutput as EmbeddingsOutput, GenerationInput as GenerationInput, GenerationOutput as GenerationOutput, HfAgentInput as HfAgentInput, MetadataOutput as MetadataOutput, unmarshal_vllm_outputs as unmarshal_vllm_outputs
from ._strategies import AmdGpuResource as AmdGpuResource, CascadingResourceStrategy as CascadingResourceStrategy, LiteralResourceSpec as LiteralResourceSpec, NvidiaGpuResource as NvidiaGpuResource, available_resource_spec as available_resource_spec, get_resource as get_resource
from .config import (
CONFIG_MAPPING as CONFIG_MAPPING,
CONFIG_MAPPING_NAMES as CONFIG_MAPPING_NAMES,
START_BAICHUAN_COMMAND_DOCSTRING as START_BAICHUAN_COMMAND_DOCSTRING,
START_CHATGLM_COMMAND_DOCSTRING as START_CHATGLM_COMMAND_DOCSTRING,
START_DOLLY_V2_COMMAND_DOCSTRING as START_DOLLY_V2_COMMAND_DOCSTRING,
START_FALCON_COMMAND_DOCSTRING as START_FALCON_COMMAND_DOCSTRING,
START_FLAN_T5_COMMAND_DOCSTRING as START_FLAN_T5_COMMAND_DOCSTRING,
START_GPT_NEOX_COMMAND_DOCSTRING as START_GPT_NEOX_COMMAND_DOCSTRING,
START_LLAMA_COMMAND_DOCSTRING as START_LLAMA_COMMAND_DOCSTRING,
START_MPT_COMMAND_DOCSTRING as START_MPT_COMMAND_DOCSTRING,
START_OPT_COMMAND_DOCSTRING as START_OPT_COMMAND_DOCSTRING,
START_STABLELM_COMMAND_DOCSTRING as START_STABLELM_COMMAND_DOCSTRING,
START_STARCODER_COMMAND_DOCSTRING as START_STARCODER_COMMAND_DOCSTRING,
AutoConfig as AutoConfig,
BaichuanConfig as BaichuanConfig,
ChatGLMConfig as ChatGLMConfig,
DollyV2Config as DollyV2Config,
FalconConfig as FalconConfig,
FlanT5Config as FlanT5Config,
GPTNeoXConfig as GPTNeoXConfig,
LlamaConfig as LlamaConfig,
MPTConfig as MPTConfig,
OPTConfig as OPTConfig,
StableLMConfig as StableLMConfig,
StarCoderConfig as StarCoderConfig,
)
from . import exceptions as exceptions
from . import utils as utils
from ._configuration import GenerationConfig as GenerationConfig
from ._configuration import LLMConfig as LLMConfig
from ._configuration import SamplingParams as SamplingParams
from ._schema import EmbeddingsOutput as EmbeddingsOutput
from ._schema import GenerationInput as GenerationInput
from ._schema import GenerationOutput as GenerationOutput
from ._schema import HfAgentInput as HfAgentInput
from ._schema import MetadataOutput as MetadataOutput
from ._schema import unmarshal_vllm_outputs as unmarshal_vllm_outputs
from ._strategies import AmdGpuResource as AmdGpuResource
from ._strategies import CascadingResourceStrategy as CascadingResourceStrategy
from ._strategies import LiteralResourceSpec as LiteralResourceSpec
from ._strategies import NvidiaGpuResource as NvidiaGpuResource
from ._strategies import available_resource_spec as available_resource_spec
from ._strategies import get_resource as get_resource
from .config import CONFIG_MAPPING as CONFIG_MAPPING
from .config import CONFIG_MAPPING_NAMES as CONFIG_MAPPING_NAMES
from .config import START_BAICHUAN_COMMAND_DOCSTRING as START_BAICHUAN_COMMAND_DOCSTRING
from .config import START_CHATGLM_COMMAND_DOCSTRING as START_CHATGLM_COMMAND_DOCSTRING
from .config import START_DOLLY_V2_COMMAND_DOCSTRING as START_DOLLY_V2_COMMAND_DOCSTRING
from .config import START_FALCON_COMMAND_DOCSTRING as START_FALCON_COMMAND_DOCSTRING
from .config import START_FLAN_T5_COMMAND_DOCSTRING as START_FLAN_T5_COMMAND_DOCSTRING
from .config import START_GPT_NEOX_COMMAND_DOCSTRING as START_GPT_NEOX_COMMAND_DOCSTRING
from .config import START_LLAMA_COMMAND_DOCSTRING as START_LLAMA_COMMAND_DOCSTRING
from .config import START_MPT_COMMAND_DOCSTRING as START_MPT_COMMAND_DOCSTRING
from .config import START_OPT_COMMAND_DOCSTRING as START_OPT_COMMAND_DOCSTRING
from .config import START_STABLELM_COMMAND_DOCSTRING as START_STABLELM_COMMAND_DOCSTRING
from .config import START_STARCODER_COMMAND_DOCSTRING as START_STARCODER_COMMAND_DOCSTRING
from .config import AutoConfig as AutoConfig
from .config import BaichuanConfig as BaichuanConfig
from .config import ChatGLMConfig as ChatGLMConfig
from .config import DollyV2Config as DollyV2Config
from .config import FalconConfig as FalconConfig
from .config import FlanT5Config as FlanT5Config
from .config import GPTNeoXConfig as GPTNeoXConfig
from .config import LlamaConfig as LlamaConfig
from .config import MPTConfig as MPTConfig
from .config import OPTConfig as OPTConfig
from .config import StableLMConfig as StableLMConfig
from .config import StarCoderConfig as StarCoderConfig
39 changes: 33 additions & 6 deletions openllm-core/src/openllm_core/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,50 @@ class GenerationConfig:
import inflection
import orjson

# NOTE: Using internal API from attr here, since we are actually allowing subclass of openllm_core.LLMConfig to become 'attrs'-ish
from attr._compat import set_closure_cell
from attr._make import _CountingAttr, _make_init, _transform_attrs
from cattr.gen import make_dict_structure_fn, make_dict_unstructure_fn, override
from attr._make import _CountingAttr
from attr._make import _make_init
from attr._make import _transform_attrs
from cattr.gen import make_dict_structure_fn
from cattr.gen import make_dict_unstructure_fn
from cattr.gen import override
from deepmerge.merger import Merger

import openllm_core

from ._strategies import LiteralResourceSpec, available_resource_spec, resource_spec
from ._typing_compat import AdapterType, AnyCallable, At, DictStrAny, ListStr, LiteralRuntime, LiteralString, NotRequired, Required, Self, overload
from ._strategies import LiteralResourceSpec
from ._strategies import available_resource_spec
from ._strategies import resource_spec
from ._typing_compat import AdapterType
from ._typing_compat import AnyCallable
from ._typing_compat import At
from ._typing_compat import DictStrAny
from ._typing_compat import ListStr
from ._typing_compat import LiteralRuntime
from ._typing_compat import LiteralString
from ._typing_compat import NotRequired
from ._typing_compat import Required
from ._typing_compat import Self
from ._typing_compat import overload
from .exceptions import ForbiddenAttributeError
from .utils import ENV_VARS_TRUE_VALUES, MYPY, LazyLoader, ReprMixin, bentoml_cattr, codegen, dantic, field_env_key, first_not_none, lenient_issubclass
from .utils import ENV_VARS_TRUE_VALUES
from .utils import MYPY
from .utils import LazyLoader
from .utils import ReprMixin
from .utils import bentoml_cattr
from .utils import codegen
from .utils import dantic
from .utils import field_env_key
from .utils import first_not_none
from .utils import lenient_issubclass
from .utils.import_utils import BACKENDS_MAPPING

if t.TYPE_CHECKING:
import click
import peft
import transformers
import vllm

from transformers.generation.beam_constraints import Constraint
else:
Constraint = t.Any
Expand Down Expand Up @@ -781,6 +807,7 @@ def __attrs_init__(self, *args: t.Any, **attrs: t.Any) -> None:
'''Optional tokenizer class for this given LLM. See Llama for example.'''

# update-config-stubs.py: special stop

class _ConfigBuilder:
"""A modified version of attrs internal _ClassBuilder, and should only be called within __init_subclass__ of LLMConfig.
Expand Down
7 changes: 5 additions & 2 deletions openllm-core/src/openllm_core/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import attr
import inflection

from openllm_core._configuration import GenerationConfig, LLMConfig
from openllm_core._configuration import GenerationConfig
from openllm_core._configuration import LLMConfig

from .utils import bentoml_cattr
if t.TYPE_CHECKING: import vllm

if t.TYPE_CHECKING:
import vllm

@attr.frozen(slots=True)
class GenerationInput:
Expand Down
19 changes: 14 additions & 5 deletions openllm-core/src/openllm_core/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
import psutil

import bentoml
from bentoml._internal.resource import get_resource, system_resources

from bentoml._internal.resource import get_resource
from bentoml._internal.resource import system_resources
from bentoml._internal.runner.strategy import THREAD_ENVS

from ._typing_compat import overload
from .utils import DEBUG, ReprMixin
from .utils import DEBUG
from .utils import ReprMixin

class DynResource(t.Protocol):
resource_id: t.ClassVar[str]
Expand Down Expand Up @@ -98,10 +101,12 @@ def _from_system(cls: type[DynResource]) -> list[str]:
# we don't want to use CLI because parsing is a pain.
sys.path.append('/opt/rocm/libexec/rocm_smi')
try:
from ctypes import byref, c_uint32
from ctypes import byref
from ctypes import c_uint32

# refers to https://github.com/RadeonOpenCompute/rocm_smi_lib/blob/master/python_smi_tools/rsmiBindings.py
from rsmiBindings import rocmsmi, rsmi_status_t
from rsmiBindings import rocmsmi
from rsmiBindings import rsmi_status_t

device_count = c_uint32(0)
ret = rocmsmi.rsmi_num_monitor_devices(byref(device_count))
Expand Down Expand Up @@ -149,7 +154,11 @@ def _from_spec(cls: type[DynResource], spec: t.Any) -> list[str]:
raise TypeError(f"'{cls.__name__}.from_spec' only supports parsing spec of type int, str, or list, got '{type(spec)}' instead.")

def _raw_device_uuid_nvml() -> list[str] | None:
from ctypes import CDLL, byref, c_int, c_void_p, create_string_buffer
from ctypes import CDLL
from ctypes import byref
from ctypes import c_int
from ctypes import c_void_p
from ctypes import create_string_buffer

try:
nvml_h = CDLL('libnvidia-ml.so.1')
Expand Down
Loading

0 comments on commit c9cef1d

Please sign in to comment.