2023-05-15 15:36:30 -06:00
|
|
|
import asyncio
|
2024-06-25 01:23:12 -06:00
|
|
|
import contextlib
|
2023-05-16 12:22:11 -06:00
|
|
|
import json
|
|
|
|
import math
|
2024-06-25 01:23:12 -06:00
|
|
|
import os
|
|
|
|
import random
|
2024-05-28 01:25:14 -06:00
|
|
|
import shutil
|
2024-06-25 01:23:12 -06:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2024-05-28 01:25:14 -06:00
|
|
|
import tempfile
|
2023-05-16 12:22:11 -06:00
|
|
|
import time
|
2024-06-25 01:23:12 -06:00
|
|
|
import docker
|
|
|
|
import pytest
|
2024-10-16 04:49:33 -06:00
|
|
|
import base64
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Dict, List, Optional
|
2024-06-25 01:23:12 -06:00
|
|
|
from aiohttp import ClientConnectorError, ClientOSError, ServerDisconnectedError
|
2023-05-15 15:36:30 -06:00
|
|
|
from docker.errors import NotFound
|
2023-05-16 12:22:11 -06:00
|
|
|
from syrupy.extensions.json import JSONSnapshotExtension
|
2024-10-16 04:49:33 -06:00
|
|
|
|
2023-05-15 15:36:30 -06:00
|
|
|
from text_generation import AsyncClient
|
2024-02-15 02:28:10 -07:00
|
|
|
from text_generation.types import (
|
|
|
|
BestOfSequence,
|
2024-09-11 10:10:40 -06:00
|
|
|
Message,
|
2024-02-28 03:10:27 -07:00
|
|
|
ChatComplete,
|
|
|
|
ChatCompletionChunk,
|
2024-03-21 10:45:56 -06:00
|
|
|
ChatCompletionComplete,
|
2024-04-17 02:41:12 -06:00
|
|
|
Completion,
|
2024-06-25 01:23:12 -06:00
|
|
|
Details,
|
|
|
|
Grammar,
|
|
|
|
InputToken,
|
|
|
|
Response,
|
|
|
|
Token,
|
2024-02-15 02:28:10 -07:00
|
|
|
)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
|
|
|
DOCKER_IMAGE = os.getenv("DOCKER_IMAGE", None)
|
2024-06-25 01:23:12 -06:00
|
|
|
HF_TOKEN = os.getenv("HF_TOKEN", None)
|
2023-05-15 15:36:30 -06:00
|
|
|
DOCKER_VOLUME = os.getenv("DOCKER_VOLUME", "/data")
|
2024-06-24 10:08:34 -06:00
|
|
|
DOCKER_DEVICES = os.getenv("DOCKER_DEVICES")
|
2023-05-15 15:36:30 -06:00
|
|
|
|
|
|
|
|
2024-06-25 08:53:20 -06:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption(
|
|
|
|
"--release", action="store_true", default=False, help="run release tests"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_configure(config):
|
|
|
|
config.addinivalue_line("markers", "release: mark test as a release-only test")
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_collection_modifyitems(config, items):
|
|
|
|
if config.getoption("--release"):
|
|
|
|
# --release given in cli: do not skip release tests
|
|
|
|
return
|
|
|
|
skip_release = pytest.mark.skip(reason="need --release option to run")
|
|
|
|
for item in items:
|
|
|
|
if "release" in item.keywords:
|
|
|
|
item.add_marker(skip_release)
|
|
|
|
|
|
|
|
|
2023-05-16 12:22:11 -06:00
|
|
|
class ResponseComparator(JSONSnapshotExtension):
|
2023-11-28 13:22:35 -07:00
|
|
|
rtol = 0.2
|
2024-05-28 03:51:31 -06:00
|
|
|
ignore_logprob = False
|
2023-12-11 06:49:52 -07:00
|
|
|
|
2023-05-16 12:22:11 -06:00
|
|
|
def serialize(
|
|
|
|
self,
|
|
|
|
data,
|
|
|
|
*,
|
2024-09-06 03:00:52 -06:00
|
|
|
include=None,
|
2023-05-16 12:22:11 -06:00
|
|
|
exclude=None,
|
|
|
|
matcher=None,
|
|
|
|
):
|
2024-03-21 10:45:56 -06:00
|
|
|
if (
|
|
|
|
isinstance(data, Response)
|
|
|
|
or isinstance(data, ChatComplete)
|
|
|
|
or isinstance(data, ChatCompletionChunk)
|
|
|
|
or isinstance(data, ChatCompletionComplete)
|
|
|
|
):
|
|
|
|
data = data.model_dump()
|
2024-02-21 06:15:22 -07:00
|
|
|
|
2023-05-16 12:22:11 -06:00
|
|
|
if isinstance(data, List):
|
2024-03-21 10:45:56 -06:00
|
|
|
data = [d.model_dump() for d in data]
|
2023-05-16 12:22:11 -06:00
|
|
|
|
|
|
|
data = self._filter(
|
2024-09-06 03:00:52 -06:00
|
|
|
data=data,
|
|
|
|
depth=0,
|
|
|
|
path=(),
|
|
|
|
exclude=exclude,
|
|
|
|
include=include,
|
|
|
|
matcher=matcher,
|
2023-05-16 12:22:11 -06:00
|
|
|
)
|
|
|
|
return json.dumps(data, indent=2, ensure_ascii=False, sort_keys=False) + "\n"
|
|
|
|
|
|
|
|
def matches(
|
|
|
|
self,
|
|
|
|
*,
|
|
|
|
serialized_data,
|
|
|
|
snapshot_data,
|
|
|
|
) -> bool:
|
|
|
|
def convert_data(data):
|
|
|
|
data = json.loads(data)
|
2024-09-11 10:10:40 -06:00
|
|
|
return _convert_data(data)
|
2023-05-16 12:22:11 -06:00
|
|
|
|
2024-09-11 10:10:40 -06:00
|
|
|
def _convert_data(data):
|
2023-05-16 12:22:11 -06:00
|
|
|
if isinstance(data, Dict):
|
2024-09-11 10:10:40 -06:00
|
|
|
if "choices" in data:
|
|
|
|
data["choices"] = list(
|
|
|
|
sorted(data["choices"], key=lambda x: x["index"])
|
|
|
|
)
|
|
|
|
choices = data["choices"]
|
|
|
|
if isinstance(choices, List) and len(choices) >= 1:
|
|
|
|
if "delta" in choices[0]:
|
|
|
|
return ChatCompletionChunk(**data)
|
|
|
|
if "text" in choices[0]:
|
|
|
|
return Completion(**data)
|
|
|
|
return ChatComplete(**data)
|
|
|
|
else:
|
|
|
|
return Response(**data)
|
2023-05-16 12:22:11 -06:00
|
|
|
if isinstance(data, List):
|
2024-09-11 10:10:40 -06:00
|
|
|
return [_convert_data(d) for d in data]
|
2023-05-16 12:22:11 -06:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def eq_token(token: Token, other: Token) -> bool:
|
|
|
|
return (
|
|
|
|
token.id == other.id
|
|
|
|
and token.text == other.text
|
2024-05-28 03:51:31 -06:00
|
|
|
and (
|
|
|
|
self.ignore_logprob
|
2024-08-16 05:21:44 -06:00
|
|
|
or (token.logprob == other.logprob and token.logprob is None)
|
2024-05-28 03:51:31 -06:00
|
|
|
or math.isclose(token.logprob, other.logprob, rel_tol=self.rtol)
|
|
|
|
)
|
2023-05-16 12:22:11 -06:00
|
|
|
and token.special == other.special
|
|
|
|
)
|
|
|
|
|
2023-06-02 09:12:30 -06:00
|
|
|
def eq_prefill_token(prefill_token: InputToken, other: InputToken) -> bool:
|
2023-05-16 12:22:11 -06:00
|
|
|
try:
|
|
|
|
return (
|
|
|
|
prefill_token.id == other.id
|
|
|
|
and prefill_token.text == other.text
|
|
|
|
and (
|
2024-05-28 03:51:31 -06:00
|
|
|
self.ignore_logprob
|
|
|
|
or math.isclose(
|
|
|
|
prefill_token.logprob,
|
|
|
|
other.logprob,
|
|
|
|
rel_tol=self.rtol,
|
2023-12-11 06:49:52 -07:00
|
|
|
)
|
2023-05-16 12:22:11 -06:00
|
|
|
if prefill_token.logprob is not None
|
|
|
|
else prefill_token.logprob == other.logprob
|
|
|
|
)
|
|
|
|
)
|
|
|
|
except TypeError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def eq_best_of(details: BestOfSequence, other: BestOfSequence) -> bool:
|
|
|
|
return (
|
|
|
|
details.finish_reason == other.finish_reason
|
|
|
|
and details.generated_tokens == other.generated_tokens
|
|
|
|
and details.seed == other.seed
|
|
|
|
and len(details.prefill) == len(other.prefill)
|
|
|
|
and all(
|
|
|
|
[
|
|
|
|
eq_prefill_token(d, o)
|
|
|
|
for d, o in zip(details.prefill, other.prefill)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
and len(details.tokens) == len(other.tokens)
|
|
|
|
and all([eq_token(d, o) for d, o in zip(details.tokens, other.tokens)])
|
|
|
|
)
|
|
|
|
|
|
|
|
def eq_details(details: Details, other: Details) -> bool:
|
|
|
|
return (
|
|
|
|
details.finish_reason == other.finish_reason
|
|
|
|
and details.generated_tokens == other.generated_tokens
|
|
|
|
and details.seed == other.seed
|
|
|
|
and len(details.prefill) == len(other.prefill)
|
|
|
|
and all(
|
|
|
|
[
|
|
|
|
eq_prefill_token(d, o)
|
|
|
|
for d, o in zip(details.prefill, other.prefill)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
and len(details.tokens) == len(other.tokens)
|
|
|
|
and all([eq_token(d, o) for d, o in zip(details.tokens, other.tokens)])
|
|
|
|
and (
|
|
|
|
len(details.best_of_sequences)
|
|
|
|
if details.best_of_sequences is not None
|
|
|
|
else 0
|
|
|
|
)
|
|
|
|
== (
|
|
|
|
len(other.best_of_sequences)
|
|
|
|
if other.best_of_sequences is not None
|
|
|
|
else 0
|
|
|
|
)
|
|
|
|
and (
|
|
|
|
all(
|
|
|
|
[
|
|
|
|
eq_best_of(d, o)
|
|
|
|
for d, o in zip(
|
|
|
|
details.best_of_sequences, other.best_of_sequences
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
if details.best_of_sequences is not None
|
|
|
|
else details.best_of_sequences == other.best_of_sequences
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-04-17 02:41:12 -06:00
|
|
|
def eq_completion(response: Completion, other: Completion) -> bool:
|
|
|
|
return response.choices[0].text == other.choices[0].text
|
|
|
|
|
2024-02-28 03:10:27 -07:00
|
|
|
def eq_chat_complete(response: ChatComplete, other: ChatComplete) -> bool:
|
|
|
|
return (
|
|
|
|
response.choices[0].message.content == other.choices[0].message.content
|
|
|
|
)
|
|
|
|
|
|
|
|
def eq_chat_complete_chunk(
|
|
|
|
response: ChatCompletionChunk, other: ChatCompletionChunk
|
|
|
|
) -> bool:
|
|
|
|
return response.choices[0].delta.content == other.choices[0].delta.content
|
|
|
|
|
2023-05-16 12:22:11 -06:00
|
|
|
def eq_response(response: Response, other: Response) -> bool:
|
|
|
|
return response.generated_text == other.generated_text and eq_details(
|
|
|
|
response.details, other.details
|
|
|
|
)
|
|
|
|
|
|
|
|
serialized_data = convert_data(serialized_data)
|
|
|
|
snapshot_data = convert_data(snapshot_data)
|
|
|
|
|
|
|
|
if not isinstance(serialized_data, List):
|
|
|
|
serialized_data = [serialized_data]
|
|
|
|
if not isinstance(snapshot_data, List):
|
|
|
|
snapshot_data = [snapshot_data]
|
|
|
|
|
2024-04-17 02:41:12 -06:00
|
|
|
if isinstance(serialized_data[0], Completion):
|
|
|
|
return len(snapshot_data) == len(serialized_data) and all(
|
|
|
|
[eq_completion(r, o) for r, o in zip(serialized_data, snapshot_data)]
|
|
|
|
)
|
|
|
|
|
2024-02-28 03:10:27 -07:00
|
|
|
if isinstance(serialized_data[0], ChatComplete):
|
|
|
|
return len(snapshot_data) == len(serialized_data) and all(
|
|
|
|
[eq_chat_complete(r, o) for r, o in zip(serialized_data, snapshot_data)]
|
|
|
|
)
|
|
|
|
|
|
|
|
if isinstance(serialized_data[0], ChatCompletionChunk):
|
|
|
|
return len(snapshot_data) == len(serialized_data) and all(
|
|
|
|
[
|
|
|
|
eq_chat_complete_chunk(r, o)
|
|
|
|
for r, o in zip(serialized_data, snapshot_data)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2023-05-16 12:22:11 -06:00
|
|
|
return len(snapshot_data) == len(serialized_data) and all(
|
|
|
|
[eq_response(r, o) for r, o in zip(serialized_data, snapshot_data)]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-28 13:22:35 -07:00
|
|
|
class GenerousResponseComparator(ResponseComparator):
|
|
|
|
# Needed for GPTQ with exllama which has serious numerical fluctuations.
|
|
|
|
rtol = 0.75
|
|
|
|
|
2023-12-11 06:49:52 -07:00
|
|
|
|
2024-05-28 03:51:31 -06:00
|
|
|
class IgnoreLogProbResponseComparator(ResponseComparator):
|
|
|
|
ignore_logprob = True
|
|
|
|
|
|
|
|
|
2023-05-16 12:22:11 -06:00
|
|
|
class LauncherHandle:
|
|
|
|
def __init__(self, port: int):
|
2024-08-26 18:19:38 -06:00
|
|
|
self.client = AsyncClient(f"http://localhost:{port}", timeout=30)
|
2023-05-16 12:22:11 -06:00
|
|
|
|
|
|
|
def _inner_health(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
async def health(self, timeout: int = 60):
|
|
|
|
assert timeout > 0
|
|
|
|
for _ in range(timeout):
|
|
|
|
if not self._inner_health():
|
|
|
|
raise RuntimeError("Launcher crashed")
|
|
|
|
|
|
|
|
try:
|
|
|
|
await self.client.generate("test")
|
|
|
|
return
|
2024-07-26 08:29:09 -06:00
|
|
|
except (ClientConnectorError, ClientOSError, ServerDisconnectedError):
|
2023-05-16 12:22:11 -06:00
|
|
|
time.sleep(1)
|
|
|
|
raise RuntimeError("Health check failed")
|
|
|
|
|
|
|
|
|
|
|
|
class ContainerLauncherHandle(LauncherHandle):
|
|
|
|
def __init__(self, docker_client, container_name, port: int):
|
|
|
|
super(ContainerLauncherHandle, self).__init__(port)
|
|
|
|
self.docker_client = docker_client
|
|
|
|
self.container_name = container_name
|
|
|
|
|
|
|
|
def _inner_health(self) -> bool:
|
|
|
|
container = self.docker_client.containers.get(self.container_name)
|
|
|
|
return container.status in ["running", "created"]
|
|
|
|
|
|
|
|
|
|
|
|
class ProcessLauncherHandle(LauncherHandle):
|
|
|
|
def __init__(self, process, port: int):
|
|
|
|
super(ProcessLauncherHandle, self).__init__(port)
|
|
|
|
self.process = process
|
|
|
|
|
|
|
|
def _inner_health(self) -> bool:
|
|
|
|
return self.process.poll() is None
|
|
|
|
|
|
|
|
|
2023-05-15 15:36:30 -06:00
|
|
|
@pytest.fixture
|
2023-05-16 12:22:11 -06:00
|
|
|
def response_snapshot(snapshot):
|
|
|
|
return snapshot.use_extension(ResponseComparator)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
2023-12-11 06:49:52 -07:00
|
|
|
|
2023-11-28 13:22:35 -07:00
|
|
|
@pytest.fixture
|
|
|
|
def generous_response_snapshot(snapshot):
|
|
|
|
return snapshot.use_extension(GenerousResponseComparator)
|
|
|
|
|
2023-05-15 15:36:30 -06:00
|
|
|
|
2024-05-28 03:51:31 -06:00
|
|
|
@pytest.fixture
|
|
|
|
def ignore_logprob_response_snapshot(snapshot):
|
|
|
|
return snapshot.use_extension(IgnoreLogProbResponseComparator)
|
|
|
|
|
|
|
|
|
2023-05-15 15:36:30 -06:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def event_loop():
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
yield loop
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def launcher(event_loop):
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def local_launcher(
|
2023-05-30 10:25:19 -06:00
|
|
|
model_id: str,
|
|
|
|
num_shard: Optional[int] = None,
|
|
|
|
quantize: Optional[str] = None,
|
|
|
|
trust_remote_code: bool = False,
|
2023-06-08 06:51:52 -06:00
|
|
|
use_flash_attention: bool = True,
|
2024-02-15 02:28:10 -07:00
|
|
|
disable_grammar_support: bool = False,
|
2023-12-11 06:49:52 -07:00
|
|
|
dtype: Optional[str] = None,
|
2024-10-04 09:51:48 -06:00
|
|
|
kv_cache_dtype: Optional[str] = None,
|
2024-02-26 11:49:28 -07:00
|
|
|
revision: Optional[str] = None,
|
Adding Llava-Next (Llava 1.6) with full support. (#1709)
# What does this PR do?
- Changed all models to extract `embed_tokens` in order to enable llava
to separately call the embeddings and the core model layers.
- Added VlmCausalLM to inherit from FlashMistral in order to be
maximally supported. The only added logics sits on top and parses images
into pixel values, preallocates input_ids space for the image
embeddings, and passes them for the model.
- Added Clip for the vision tower.
- Didn't add flash for the vision tower since there's no padding anyway.
- Added heuristic (potentially incomplete) to calculate number of
features *before* calculating the clip patches (allows for easier logic
reuse of the LLM under the hood).
Still needs to be done:
- [x] Implement the image parsing in the controller side, to avoid
downloading n times per TP shard and also refusing requests too large
early and avoid issues where the truncation actually truncates the
image.
- [ ] Make sure it works with quantization properly.
- [x] Make sure it works with TP>1
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-04-09 13:32:00 -06:00
|
|
|
max_input_length: Optional[int] = None,
|
2024-04-23 15:04:44 -06:00
|
|
|
max_batch_prefill_tokens: Optional[int] = None,
|
Adding Llava-Next (Llava 1.6) with full support. (#1709)
# What does this PR do?
- Changed all models to extract `embed_tokens` in order to enable llava
to separately call the embeddings and the core model layers.
- Added VlmCausalLM to inherit from FlashMistral in order to be
maximally supported. The only added logics sits on top and parses images
into pixel values, preallocates input_ids space for the image
embeddings, and passes them for the model.
- Added Clip for the vision tower.
- Didn't add flash for the vision tower since there's no padding anyway.
- Added heuristic (potentially incomplete) to calculate number of
features *before* calculating the clip patches (allows for easier logic
reuse of the LLM under the hood).
Still needs to be done:
- [x] Implement the image parsing in the controller side, to avoid
downloading n times per TP shard and also refusing requests too large
early and avoid issues where the truncation actually truncates the
image.
- [ ] Make sure it works with quantization properly.
- [x] Make sure it works with TP>1
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-04-09 13:32:00 -06:00
|
|
|
max_total_tokens: Optional[int] = None,
|
2024-07-15 07:16:15 -06:00
|
|
|
lora_adapters: Optional[List[str]] = None,
|
|
|
|
cuda_graphs: Optional[List[int]] = None,
|
2024-09-16 09:00:54 -06:00
|
|
|
attention: Optional[str] = None,
|
2023-05-15 15:36:30 -06:00
|
|
|
):
|
2023-05-16 15:23:27 -06:00
|
|
|
port = random.randint(8000, 10_000)
|
|
|
|
master_port = random.randint(10_000, 20_000)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
2023-05-16 15:23:27 -06:00
|
|
|
shard_uds_path = (
|
|
|
|
f"/tmp/tgi-tests-{model_id.split('/')[-1]}-{num_shard}-{quantize}-server"
|
|
|
|
)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
|
|
|
args = [
|
|
|
|
"text-generation-launcher",
|
|
|
|
"--model-id",
|
|
|
|
model_id,
|
|
|
|
"--port",
|
|
|
|
str(port),
|
|
|
|
"--master-port",
|
|
|
|
str(master_port),
|
|
|
|
"--shard-uds-path",
|
|
|
|
shard_uds_path,
|
|
|
|
]
|
|
|
|
|
2023-07-21 02:59:00 -06:00
|
|
|
env = os.environ
|
|
|
|
|
2024-02-15 02:28:10 -07:00
|
|
|
if disable_grammar_support:
|
|
|
|
args.append("--disable-grammar-support")
|
2023-05-15 15:36:30 -06:00
|
|
|
if num_shard is not None:
|
|
|
|
args.extend(["--num-shard", str(num_shard)])
|
2023-07-21 02:59:00 -06:00
|
|
|
if quantize is not None:
|
2023-05-15 15:36:30 -06:00
|
|
|
args.append("--quantize")
|
2023-07-21 02:59:00 -06:00
|
|
|
args.append(quantize)
|
2023-11-28 09:54:26 -07:00
|
|
|
if dtype is not None:
|
|
|
|
args.append("--dtype")
|
|
|
|
args.append(dtype)
|
2024-10-04 09:51:48 -06:00
|
|
|
if kv_cache_dtype is not None:
|
|
|
|
args.append("--kv-cache-dtype")
|
|
|
|
args.append(kv_cache_dtype)
|
2024-02-26 11:49:28 -07:00
|
|
|
if revision is not None:
|
|
|
|
args.append("--revision")
|
|
|
|
args.append(revision)
|
2023-05-30 10:25:19 -06:00
|
|
|
if trust_remote_code:
|
|
|
|
args.append("--trust-remote-code")
|
Adding Llava-Next (Llava 1.6) with full support. (#1709)
# What does this PR do?
- Changed all models to extract `embed_tokens` in order to enable llava
to separately call the embeddings and the core model layers.
- Added VlmCausalLM to inherit from FlashMistral in order to be
maximally supported. The only added logics sits on top and parses images
into pixel values, preallocates input_ids space for the image
embeddings, and passes them for the model.
- Added Clip for the vision tower.
- Didn't add flash for the vision tower since there's no padding anyway.
- Added heuristic (potentially incomplete) to calculate number of
features *before* calculating the clip patches (allows for easier logic
reuse of the LLM under the hood).
Still needs to be done:
- [x] Implement the image parsing in the controller side, to avoid
downloading n times per TP shard and also refusing requests too large
early and avoid issues where the truncation actually truncates the
image.
- [ ] Make sure it works with quantization properly.
- [x] Make sure it works with TP>1
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-04-09 13:32:00 -06:00
|
|
|
if max_input_length:
|
|
|
|
args.append("--max-input-length")
|
|
|
|
args.append(str(max_input_length))
|
2024-04-23 15:04:44 -06:00
|
|
|
if max_batch_prefill_tokens:
|
|
|
|
args.append("--max-batch-prefill-tokens")
|
|
|
|
args.append(str(max_batch_prefill_tokens))
|
Adding Llava-Next (Llava 1.6) with full support. (#1709)
# What does this PR do?
- Changed all models to extract `embed_tokens` in order to enable llava
to separately call the embeddings and the core model layers.
- Added VlmCausalLM to inherit from FlashMistral in order to be
maximally supported. The only added logics sits on top and parses images
into pixel values, preallocates input_ids space for the image
embeddings, and passes them for the model.
- Added Clip for the vision tower.
- Didn't add flash for the vision tower since there's no padding anyway.
- Added heuristic (potentially incomplete) to calculate number of
features *before* calculating the clip patches (allows for easier logic
reuse of the LLM under the hood).
Still needs to be done:
- [x] Implement the image parsing in the controller side, to avoid
downloading n times per TP shard and also refusing requests too large
early and avoid issues where the truncation actually truncates the
image.
- [ ] Make sure it works with quantization properly.
- [x] Make sure it works with TP>1
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-04-09 13:32:00 -06:00
|
|
|
if max_total_tokens:
|
|
|
|
args.append("--max-total-tokens")
|
|
|
|
args.append(str(max_total_tokens))
|
2024-07-15 07:16:15 -06:00
|
|
|
if lora_adapters:
|
|
|
|
args.append("--lora-adapters")
|
|
|
|
args.append(",".join(lora_adapters))
|
|
|
|
if cuda_graphs:
|
|
|
|
args.append("--cuda-graphs")
|
|
|
|
args.append(",".join(map(str, cuda_graphs)))
|
|
|
|
|
|
|
|
print(" ".join(args), file=sys.stderr)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
2023-05-23 12:47:37 -06:00
|
|
|
env["LOG_LEVEL"] = "info,text_generation_router=debug"
|
2024-10-16 04:49:33 -06:00
|
|
|
env["PREFILL_CHUNKING"] = "1"
|
2023-05-23 12:47:37 -06:00
|
|
|
|
2023-06-08 06:51:52 -06:00
|
|
|
if not use_flash_attention:
|
|
|
|
env["USE_FLASH_ATTENTION"] = "false"
|
2024-09-16 09:00:54 -06:00
|
|
|
if attention is not None:
|
|
|
|
env["ATTENTION"] = attention
|
2023-06-08 06:51:52 -06:00
|
|
|
|
2024-05-28 01:25:14 -06:00
|
|
|
with tempfile.TemporaryFile("w+") as tmp:
|
|
|
|
# We'll output stdout/stderr to a temporary file. Using a pipe
|
|
|
|
# cause the process to block until stdout is read.
|
|
|
|
with subprocess.Popen(
|
|
|
|
args,
|
|
|
|
stdout=tmp,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
env=env,
|
|
|
|
) as process:
|
|
|
|
yield ProcessLauncherHandle(process, port)
|
|
|
|
|
|
|
|
process.terminate()
|
|
|
|
process.wait(60)
|
|
|
|
|
|
|
|
tmp.seek(0)
|
|
|
|
shutil.copyfileobj(tmp, sys.stderr)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
2023-06-08 06:51:52 -06:00
|
|
|
if not use_flash_attention:
|
|
|
|
del env["USE_FLASH_ATTENTION"]
|
|
|
|
|
2023-05-15 15:36:30 -06:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def docker_launcher(
|
2023-05-30 10:25:19 -06:00
|
|
|
model_id: str,
|
|
|
|
num_shard: Optional[int] = None,
|
|
|
|
quantize: Optional[str] = None,
|
|
|
|
trust_remote_code: bool = False,
|
2023-06-08 06:51:52 -06:00
|
|
|
use_flash_attention: bool = True,
|
2024-02-15 02:28:10 -07:00
|
|
|
disable_grammar_support: bool = False,
|
2023-12-11 06:49:52 -07:00
|
|
|
dtype: Optional[str] = None,
|
2024-10-04 09:51:48 -06:00
|
|
|
kv_cache_dtype: Optional[str] = None,
|
2024-02-26 11:49:28 -07:00
|
|
|
revision: Optional[str] = None,
|
Adding Llava-Next (Llava 1.6) with full support. (#1709)
# What does this PR do?
- Changed all models to extract `embed_tokens` in order to enable llava
to separately call the embeddings and the core model layers.
- Added VlmCausalLM to inherit from FlashMistral in order to be
maximally supported. The only added logics sits on top and parses images
into pixel values, preallocates input_ids space for the image
embeddings, and passes them for the model.
- Added Clip for the vision tower.
- Didn't add flash for the vision tower since there's no padding anyway.
- Added heuristic (potentially incomplete) to calculate number of
features *before* calculating the clip patches (allows for easier logic
reuse of the LLM under the hood).
Still needs to be done:
- [x] Implement the image parsing in the controller side, to avoid
downloading n times per TP shard and also refusing requests too large
early and avoid issues where the truncation actually truncates the
image.
- [ ] Make sure it works with quantization properly.
- [x] Make sure it works with TP>1
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-04-09 13:32:00 -06:00
|
|
|
max_input_length: Optional[int] = None,
|
2024-04-23 15:04:44 -06:00
|
|
|
max_batch_prefill_tokens: Optional[int] = None,
|
Adding Llava-Next (Llava 1.6) with full support. (#1709)
# What does this PR do?
- Changed all models to extract `embed_tokens` in order to enable llava
to separately call the embeddings and the core model layers.
- Added VlmCausalLM to inherit from FlashMistral in order to be
maximally supported. The only added logics sits on top and parses images
into pixel values, preallocates input_ids space for the image
embeddings, and passes them for the model.
- Added Clip for the vision tower.
- Didn't add flash for the vision tower since there's no padding anyway.
- Added heuristic (potentially incomplete) to calculate number of
features *before* calculating the clip patches (allows for easier logic
reuse of the LLM under the hood).
Still needs to be done:
- [x] Implement the image parsing in the controller side, to avoid
downloading n times per TP shard and also refusing requests too large
early and avoid issues where the truncation actually truncates the
image.
- [ ] Make sure it works with quantization properly.
- [x] Make sure it works with TP>1
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-04-09 13:32:00 -06:00
|
|
|
max_total_tokens: Optional[int] = None,
|
2024-07-15 07:16:15 -06:00
|
|
|
lora_adapters: Optional[List[str]] = None,
|
|
|
|
cuda_graphs: Optional[List[int]] = None,
|
2024-09-16 09:00:54 -06:00
|
|
|
attention: Optional[str] = None,
|
2023-05-15 15:36:30 -06:00
|
|
|
):
|
2023-05-16 15:23:27 -06:00
|
|
|
port = random.randint(8000, 10_000)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
|
|
|
args = ["--model-id", model_id, "--env"]
|
|
|
|
|
2024-02-15 02:28:10 -07:00
|
|
|
if disable_grammar_support:
|
|
|
|
args.append("--disable-grammar-support")
|
2023-05-15 15:36:30 -06:00
|
|
|
if num_shard is not None:
|
|
|
|
args.extend(["--num-shard", str(num_shard)])
|
2023-07-21 02:59:00 -06:00
|
|
|
if quantize is not None:
|
2023-05-15 15:36:30 -06:00
|
|
|
args.append("--quantize")
|
2023-07-21 02:59:00 -06:00
|
|
|
args.append(quantize)
|
2023-11-28 09:54:26 -07:00
|
|
|
if dtype is not None:
|
|
|
|
args.append("--dtype")
|
|
|
|
args.append(dtype)
|
2024-10-04 09:51:48 -06:00
|
|
|
if kv_cache_dtype is not None:
|
|
|
|
args.append("--kv-cache-dtype")
|
|
|
|
args.append(kv_cache_dtype)
|
2024-02-26 11:49:28 -07:00
|
|
|
if revision is not None:
|
|
|
|
args.append("--revision")
|
|
|
|
args.append(revision)
|
2023-05-30 10:25:19 -06:00
|
|
|
if trust_remote_code:
|
|
|
|
args.append("--trust-remote-code")
|
Adding Llava-Next (Llava 1.6) with full support. (#1709)
# What does this PR do?
- Changed all models to extract `embed_tokens` in order to enable llava
to separately call the embeddings and the core model layers.
- Added VlmCausalLM to inherit from FlashMistral in order to be
maximally supported. The only added logics sits on top and parses images
into pixel values, preallocates input_ids space for the image
embeddings, and passes them for the model.
- Added Clip for the vision tower.
- Didn't add flash for the vision tower since there's no padding anyway.
- Added heuristic (potentially incomplete) to calculate number of
features *before* calculating the clip patches (allows for easier logic
reuse of the LLM under the hood).
Still needs to be done:
- [x] Implement the image parsing in the controller side, to avoid
downloading n times per TP shard and also refusing requests too large
early and avoid issues where the truncation actually truncates the
image.
- [ ] Make sure it works with quantization properly.
- [x] Make sure it works with TP>1
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-04-09 13:32:00 -06:00
|
|
|
if max_input_length:
|
|
|
|
args.append("--max-input-length")
|
|
|
|
args.append(str(max_input_length))
|
2024-04-23 15:04:44 -06:00
|
|
|
if max_batch_prefill_tokens:
|
|
|
|
args.append("--max-batch-prefill-tokens")
|
|
|
|
args.append(str(max_batch_prefill_tokens))
|
Adding Llava-Next (Llava 1.6) with full support. (#1709)
# What does this PR do?
- Changed all models to extract `embed_tokens` in order to enable llava
to separately call the embeddings and the core model layers.
- Added VlmCausalLM to inherit from FlashMistral in order to be
maximally supported. The only added logics sits on top and parses images
into pixel values, preallocates input_ids space for the image
embeddings, and passes them for the model.
- Added Clip for the vision tower.
- Didn't add flash for the vision tower since there's no padding anyway.
- Added heuristic (potentially incomplete) to calculate number of
features *before* calculating the clip patches (allows for easier logic
reuse of the LLM under the hood).
Still needs to be done:
- [x] Implement the image parsing in the controller side, to avoid
downloading n times per TP shard and also refusing requests too large
early and avoid issues where the truncation actually truncates the
image.
- [ ] Make sure it works with quantization properly.
- [x] Make sure it works with TP>1
<!--
Congratulations! You've made it this far! You're not quite done yet
though.
Once merged, your PR is going to appear in the release notes with the
title you set, so make sure it's a great title that fully reflects the
extent of your awesome contribution.
Then, please replace this with a description of the change and which
issue is fixed (if applicable). Please also include relevant motivation
and context. List any dependencies (if any) that are required for this
change.
Once you're done, someone will review your PR shortly (see the section
"Who can review?" below to tag some potential reviewers). They may
suggest changes to make the code even better. If no one reviewed your PR
after a week has passed, don't hesitate to post a new comment
@-mentioning the same persons---sometimes notifications get lost.
-->
<!-- Remove if not applicable -->
Fixes # (issue)
## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Did you read the [contributor
guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the
[forum](https://discuss.huggingface.co/)? Please add a link
to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes?
Here are the
[documentation
guidelines](https://github.com/huggingface/transformers/tree/main/docs),
and
[here are tips on formatting
docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?
## Who can review?
Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.
<!-- Your PR will be replied to more quickly if you can figure out the
right person to tag with @
@OlivierDehaene OR @Narsil
-->
2024-04-09 13:32:00 -06:00
|
|
|
if max_total_tokens:
|
|
|
|
args.append("--max-total-tokens")
|
|
|
|
args.append(str(max_total_tokens))
|
2024-07-15 07:16:15 -06:00
|
|
|
if lora_adapters:
|
|
|
|
args.append("--lora-adapters")
|
|
|
|
args.append(",".join(lora_adapters))
|
|
|
|
if cuda_graphs:
|
|
|
|
args.append("--cuda-graphs")
|
|
|
|
args.append(",".join(map(str, cuda_graphs)))
|
2023-05-15 15:36:30 -06:00
|
|
|
|
|
|
|
client = docker.from_env()
|
|
|
|
|
|
|
|
container_name = f"tgi-tests-{model_id.split('/')[-1]}-{num_shard}-{quantize}"
|
|
|
|
|
|
|
|
try:
|
|
|
|
container = client.containers.get(container_name)
|
|
|
|
container.stop()
|
2024-10-09 09:50:49 -06:00
|
|
|
container.remove()
|
2023-05-15 15:36:30 -06:00
|
|
|
container.wait()
|
|
|
|
except NotFound:
|
|
|
|
pass
|
|
|
|
|
|
|
|
gpu_count = num_shard if num_shard is not None else 1
|
|
|
|
|
2024-02-12 02:09:29 -07:00
|
|
|
env = {
|
|
|
|
"LOG_LEVEL": "info,text_generation_router=debug",
|
2024-10-16 04:49:33 -06:00
|
|
|
"PREFILL_CHUNKING": "1",
|
2024-02-12 02:09:29 -07:00
|
|
|
}
|
2023-06-08 06:51:52 -06:00
|
|
|
if not use_flash_attention:
|
|
|
|
env["USE_FLASH_ATTENTION"] = "false"
|
2024-09-16 09:00:54 -06:00
|
|
|
if attention is not None:
|
|
|
|
env["ATTENTION"] = attention
|
2023-06-08 06:51:52 -06:00
|
|
|
|
2024-06-25 01:23:12 -06:00
|
|
|
if HF_TOKEN is not None:
|
|
|
|
env["HF_TOKEN"] = HF_TOKEN
|
2023-05-15 15:36:30 -06:00
|
|
|
|
|
|
|
volumes = []
|
|
|
|
if DOCKER_VOLUME:
|
|
|
|
volumes = [f"{DOCKER_VOLUME}:/data"]
|
|
|
|
|
2024-06-24 10:08:34 -06:00
|
|
|
if DOCKER_DEVICES:
|
2024-10-09 09:50:49 -06:00
|
|
|
if DOCKER_DEVICES.lower() == "none":
|
|
|
|
devices = []
|
|
|
|
else:
|
|
|
|
devices = DOCKER_DEVICES.strip().split(",")
|
2024-06-24 10:08:34 -06:00
|
|
|
visible = os.getenv("ROCR_VISIBLE_DEVICES")
|
|
|
|
if visible:
|
|
|
|
env["ROCR_VISIBLE_DEVICES"] = visible
|
|
|
|
device_requests = []
|
2024-10-09 09:50:49 -06:00
|
|
|
if not devices:
|
|
|
|
devices = None
|
|
|
|
elif devices == ["nvidia.com/gpu=all"]:
|
|
|
|
devices = None
|
|
|
|
device_requests = [
|
|
|
|
docker.types.DeviceRequest(
|
|
|
|
driver="cdi",
|
|
|
|
# count=gpu_count,
|
|
|
|
device_ids=[f"nvidia.com/gpu={i}"],
|
|
|
|
)
|
|
|
|
for i in range(gpu_count)
|
|
|
|
]
|
2024-06-24 10:08:34 -06:00
|
|
|
else:
|
2024-10-09 09:50:49 -06:00
|
|
|
devices = None
|
2024-06-24 10:08:34 -06:00
|
|
|
device_requests = [
|
|
|
|
docker.types.DeviceRequest(count=gpu_count, capabilities=[["gpu"]])
|
|
|
|
]
|
|
|
|
|
2023-05-15 15:36:30 -06:00
|
|
|
container = client.containers.run(
|
|
|
|
DOCKER_IMAGE,
|
|
|
|
command=args,
|
|
|
|
name=container_name,
|
|
|
|
environment=env,
|
2023-05-16 12:22:11 -06:00
|
|
|
auto_remove=False,
|
2023-05-15 15:36:30 -06:00
|
|
|
detach=True,
|
2024-06-24 10:08:34 -06:00
|
|
|
device_requests=device_requests,
|
|
|
|
devices=devices,
|
2023-05-15 15:36:30 -06:00
|
|
|
volumes=volumes,
|
|
|
|
ports={"80/tcp": port},
|
2024-09-16 09:00:54 -06:00
|
|
|
healthcheck={"timeout": int(10 * 1e9)},
|
2023-12-11 06:49:52 -07:00
|
|
|
shm_size="1G",
|
2023-05-15 15:36:30 -06:00
|
|
|
)
|
|
|
|
|
2024-10-09 09:50:49 -06:00
|
|
|
try:
|
|
|
|
yield ContainerLauncherHandle(client, container.name, port)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
2024-10-09 09:50:49 -06:00
|
|
|
if not use_flash_attention:
|
|
|
|
del env["USE_FLASH_ATTENTION"]
|
2023-06-08 06:51:52 -06:00
|
|
|
|
2024-10-09 09:50:49 -06:00
|
|
|
try:
|
|
|
|
container.stop()
|
|
|
|
container.wait()
|
|
|
|
except NotFound:
|
|
|
|
pass
|
2023-05-15 15:36:30 -06:00
|
|
|
|
2024-10-09 09:50:49 -06:00
|
|
|
container_output = container.logs().decode("utf-8")
|
|
|
|
print(container_output, file=sys.stderr)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
2024-10-09 09:50:49 -06:00
|
|
|
finally:
|
2024-10-10 08:51:57 -06:00
|
|
|
try:
|
|
|
|
container.remove()
|
|
|
|
except Exception:
|
|
|
|
pass
|
2023-05-16 12:22:11 -06:00
|
|
|
|
2023-05-15 15:36:30 -06:00
|
|
|
if DOCKER_IMAGE is not None:
|
|
|
|
return docker_launcher
|
|
|
|
return local_launcher
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def generate_load():
|
|
|
|
async def generate_load_inner(
|
2024-02-15 02:28:10 -07:00
|
|
|
client: AsyncClient,
|
|
|
|
prompt: str,
|
|
|
|
max_new_tokens: int,
|
|
|
|
n: int,
|
|
|
|
seed: Optional[int] = None,
|
|
|
|
grammar: Optional[Grammar] = None,
|
|
|
|
stop_sequences: Optional[List[str]] = None,
|
2023-05-15 15:36:30 -06:00
|
|
|
) -> List[Response]:
|
|
|
|
futures = [
|
2023-06-02 09:12:30 -06:00
|
|
|
client.generate(
|
2024-02-15 02:28:10 -07:00
|
|
|
prompt,
|
|
|
|
max_new_tokens=max_new_tokens,
|
|
|
|
decoder_input_details=True,
|
|
|
|
seed=seed,
|
|
|
|
grammar=grammar,
|
|
|
|
stop_sequences=stop_sequences,
|
2023-06-02 09:12:30 -06:00
|
|
|
)
|
|
|
|
for _ in range(n)
|
2023-05-15 15:36:30 -06:00
|
|
|
]
|
|
|
|
|
2023-05-16 12:22:11 -06:00
|
|
|
return await asyncio.gather(*futures)
|
2023-05-15 15:36:30 -06:00
|
|
|
|
|
|
|
return generate_load_inner
|
2024-09-11 10:10:40 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def generate_multi():
|
|
|
|
async def generate_load_inner(
|
|
|
|
client: AsyncClient,
|
|
|
|
prompts: List[str],
|
|
|
|
max_new_tokens: int,
|
|
|
|
seed: Optional[int] = None,
|
|
|
|
) -> List[Response]:
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
arange = np.arange(len(prompts))
|
|
|
|
perm = np.random.permutation(arange)
|
|
|
|
rperm = [-1] * len(perm)
|
|
|
|
for i, p in enumerate(perm):
|
|
|
|
rperm[p] = i
|
|
|
|
|
|
|
|
shuffled_prompts = [prompts[p] for p in perm]
|
|
|
|
futures = [
|
|
|
|
client.chat(
|
|
|
|
messages=[Message(role="user", content=prompt)],
|
|
|
|
max_tokens=max_new_tokens,
|
|
|
|
temperature=0,
|
|
|
|
seed=seed,
|
|
|
|
)
|
|
|
|
for prompt in shuffled_prompts
|
|
|
|
]
|
|
|
|
|
|
|
|
shuffled_responses = await asyncio.gather(*futures)
|
|
|
|
responses = [shuffled_responses[p] for p in rperm]
|
|
|
|
return responses
|
|
|
|
|
|
|
|
return generate_load_inner
|
2024-10-16 04:49:33 -06:00
|
|
|
|
|
|
|
|
|
|
|
# TODO fix the server parsser to count inline image tokens correctly
|
|
|
|
@pytest.fixture
|
|
|
|
def chicken():
|
|
|
|
path = Path(__file__).parent / "images" / "chicken_on_money.png"
|
|
|
|
|
|
|
|
with open(path, "rb") as image_file:
|
|
|
|
encoded_string = base64.b64encode(image_file.read())
|
|
|
|
return f"data:image/png;base64,{encoded_string.decode('utf-8')}"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def cow_beach():
|
|
|
|
path = Path(__file__).parent / "images" / "cow_beach.png"
|
|
|
|
|
|
|
|
with open(path, "rb") as image_file:
|
|
|
|
encoded_string = base64.b64encode(image_file.read())
|
|
|
|
return f"data:image/png;base64,{encoded_string.decode('utf-8')}"
|