fix(tests): building not being isolated

We will need to fix this from BentoML

Signed-off-by: aarnphm-ec2-dev <29749331+aarnphm@users.noreply.github.com>
This commit is contained in:
aarnphm-ec2-dev
2023-07-11 17:28:00 +00:00
parent 2950cffd5b
commit e2ae24b74c
4 changed files with 14 additions and 70 deletions

View File

@@ -72,12 +72,12 @@ all = [
"openllm[falcon]",
"openllm[mpt]",
"openllm[starcoder]",
"openllm[openai]",
"openllm[flan-t5]",
"openllm[fine-tune]",
"openllm[agents]",
"openllm[playground]",
"openllm[ggml]",
"openllm[openai]",
]
chatglm = ["cpm-kernels", "sentencepiece"]
falcon = ["einops", "xformers", "safetensors"]

View File

@@ -1622,6 +1622,8 @@ class LLMConfig(_ConfigAttr):
**attrs: The attributes to be added to the new class. This will override
any existing attributes with the same name.
"""
if not hasattr(cls, "__config__"):
raise ValueError("Cannot derivate a LLMConfig without __config__")
_new_cfg = {k: v for k, v in attrs.items() if k in attr.fields_dict(_ModelSettingsAttr)}
attrs = {k: v for k, v in attrs.items() if k not in _new_cfg}
new_cls = types.new_class(

View File

@@ -1403,50 +1403,6 @@ def _start(
)
@overload
def _build(
model_name: str,
/,
*,
model_id: str | None = ...,
model_version: str | None = ...,
quantize: t.Literal["int8", "int4", "gptq"] | None = ...,
bettertransformer: bool | None = ...,
adapter_map: dict[str, str | None] | None = ...,
build_ctx: str | None = ...,
enable_features: tuple[str, ...] | None = ...,
workers_per_resource: int | float | None = ...,
runtime: t.Literal["ggml", "transformers"] = ...,
dockerfile_template: str | None = ...,
overwrite: bool = ...,
format: t.Literal["bento"] = "bento",
additional_args: list[str] | None = ...,
) -> bentoml.Bento:
...
@overload
def _build(
model_name: str,
/,
*,
model_id: str | None = ...,
model_version: str | None = ...,
quantize: t.Literal["int8", "int4", "gptq"] | None = ...,
bettertransformer: bool | None = ...,
adapter_map: dict[str, str | None] | None = ...,
build_ctx: str | None = ...,
enable_features: tuple[str, ...] | None = ...,
workers_per_resource: int | float | None = ...,
runtime: t.Literal["ggml", "transformers"] = ...,
dockerfile_template: str | None = ...,
overwrite: bool = ...,
format: t.Literal["container"] = ...,
additional_args: list[str] | None = ...,
) -> str:
...
def _build(
model_name: str,
/,
@@ -1464,7 +1420,7 @@ def _build(
overwrite: bool = False,
format: t.Literal["bento", "container"] = "bento",
additional_args: list[str] | None = None,
) -> bentoml.Bento | str:
) -> bentoml.Bento:
"""Package a LLM into a Bento.
The LLM will be built into a BentoService with the following structure:
@@ -1689,8 +1645,6 @@ def build_command(
> NOTE: To run a container built from this Bento with GPU support, make sure
> to have https://github.com/NVIDIA/nvidia-container-toolkit install locally.
"""
from bentoml_cli.cli import cli as bentoml_cli
from ._package import create_bento
adapter_map: dict[str, str | None] | None = None
@@ -1834,16 +1788,15 @@ def build_command(
else:
_echo(bento.tag)
if format == "bento":
return bento
if format == "container":
backend = os.getenv("BENTOML_CONTAINERIZE_BACKEND", "docker")
_echo(f"Building {bento} into a LLMContainer using backend '{backend}'", fg="magenta")
if not bentoml.container.health(backend):
raise OpenLLMException(f"Failed to use backend {backend}")
backend = os.getenv("BENTOML_CONTAINERIZE_BACKEND", "docker")
_echo(f"\nBuilding {bento} into a LLMContainer using backend '{backend}'", fg="magenta")
args = [str(bento.tag), "--backend", backend]
if get_debug_mode():
args.extend(["--opt", "progress=plain"])
bentoml_cli.commands["containerize"].main(standalone_mode=False, args=args)
return str(bento.tag)
bentoml.container.build(str(bento.tag), backend=backend, features=("grpc",))
return bento
@overload

View File

@@ -42,8 +42,6 @@ def test_general_build_with_internal_testing():
def test_general_build_from_local(tmp_path_factory: pytest.TempPathFactory):
bento_store = BentoMLContainer.bento_store.get()
local_path = tmp_path_factory.mktemp("local_t5")
llm = openllm.AutoLLM.for_model("flan-t5", model_id=HF_INTERNAL_T5_TESTING, ensure_available=True)
@@ -52,11 +50,7 @@ def test_general_build_from_local(tmp_path_factory: pytest.TempPathFactory):
llm.save_pretrained(local_path)
bento = openllm.build("flan-t5", model_id=local_path.resolve().__fspath__(), model_version="1")
assert len(bento_store.list(bento.tag)) == 1
bento = openllm.build("flan-t5", model_id=local_path.resolve().__fspath__(), model_version="1")
assert len(bento_store.list(bento.tag)) == 1
assert openllm.build("flan-t5", model_id=local_path.resolve().__fspath__(), model_version="local")
@pytest.fixture(name="dockerfile_template")
@@ -70,9 +64,4 @@ def fixture_dockerfile_template(tmp_path_factory: pytest.TempPathFactory):
@pytest.mark.usefixtures("dockerfile_template")
def test_build_with_custom_dockerfile(dockerfile_template: Path):
assert openllm.build(
"flan-t5",
model_id=HF_INTERNAL_T5_TESTING,
overwrite=True,
dockerfile_template=str(dockerfile_template),
)
assert openllm.build("flan-t5", model_id=HF_INTERNAL_T5_TESTING, dockerfile_template=str(dockerfile_template))