2022-10-08 04:30:12 -06:00
|
|
|
import asyncio
|
2022-10-17 06:59:00 -06:00
|
|
|
import os
|
2023-02-07 07:38:22 -07:00
|
|
|
import torch
|
2023-12-14 07:59:38 -07:00
|
|
|
import time
|
2024-04-29 09:23:40 -06:00
|
|
|
import signal
|
2022-10-17 06:59:00 -06:00
|
|
|
|
2022-10-08 04:30:12 -06:00
|
|
|
from grpc import aio
|
2023-01-05 04:01:23 -07:00
|
|
|
from loguru import logger
|
2022-10-08 04:30:12 -06:00
|
|
|
|
|
|
|
from grpc_reflection.v1alpha import reflection
|
|
|
|
from pathlib import Path
|
2023-01-31 10:53:56 -07:00
|
|
|
from typing import List, Optional
|
2022-10-08 04:30:12 -06:00
|
|
|
|
2023-03-07 10:52:22 -07:00
|
|
|
from text_generation_server.cache import Cache
|
|
|
|
from text_generation_server.interceptor import ExceptionInterceptor
|
|
|
|
from text_generation_server.models import Model, get_model
|
2024-05-23 06:39:38 -06:00
|
|
|
|
|
|
|
try:
|
|
|
|
from text_generation_server.models.pali_gemma import PaliGemmaBatch
|
|
|
|
from text_generation_server.models.vlm_causal_lm import (
|
|
|
|
VlmCausalLMBatch,
|
|
|
|
)
|
|
|
|
from text_generation_server.models.idefics_causal_lm import IdeficsCausalLMBatch
|
|
|
|
|
|
|
|
VLM_BATCH_TYPES = {PaliGemmaBatch, VlmCausalLMBatch, IdeficsCausalLMBatch}
|
|
|
|
except (ImportError, NotImplementedError):
|
|
|
|
# These imports can fail on CPU/Non flash.
|
|
|
|
VLM_BATCH_TYPES = set()
|
|
|
|
|
2023-03-07 10:52:22 -07:00
|
|
|
from text_generation_server.pb import generate_pb2_grpc, generate_pb2
|
|
|
|
from text_generation_server.tracing import UDSOpenTelemetryAioServerInterceptor
|
2024-06-25 12:46:27 -06:00
|
|
|
from text_generation_server.models.globals import set_model_id, set_adapter_to_index
|
|
|
|
from text_generation_server.utils.adapter import (
|
|
|
|
AdapterParameters,
|
|
|
|
)
|
2022-10-08 04:30:12 -06:00
|
|
|
|
2023-09-27 04:22:09 -06:00
|
|
|
|
2024-04-29 09:23:40 -06:00
|
|
|
class SignalHandler:
|
|
|
|
KEEP_PROCESSING = True
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
signal.signal(signal.SIGINT, self.exit_gracefully)
|
|
|
|
signal.signal(signal.SIGTERM, self.exit_gracefully)
|
|
|
|
|
|
|
|
def exit_gracefully(self, signum, frame):
|
|
|
|
print(f"Exiting gracefully: Signal {signum}")
|
|
|
|
self.KEEP_PROCESSING = False
|
|
|
|
|
|
|
|
|
2022-10-11 08:50:54 -06:00
|
|
|
class TextGenerationService(generate_pb2_grpc.TextGenerationServiceServicer):
|
2023-12-18 08:07:05 -07:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
model: Model,
|
|
|
|
cache: Cache,
|
|
|
|
quantize: Optional[str],
|
|
|
|
server_urls: List[str],
|
|
|
|
):
|
2022-10-08 04:30:12 -06:00
|
|
|
self.cache = cache
|
|
|
|
self.model = model
|
2023-12-18 08:07:05 -07:00
|
|
|
self.quantize = quantize
|
2022-10-08 04:30:12 -06:00
|
|
|
self.server_urls = server_urls
|
2023-02-07 07:38:22 -07:00
|
|
|
# For some reason, inference_mode does not work well with GLOO which we use on CPU
|
|
|
|
if model.device.type == "cuda":
|
|
|
|
# Force inference mode for the lifetime of TextGenerationService
|
|
|
|
self._inference_mode_raii_guard = torch._C._InferenceMode(True)
|
2022-10-08 04:30:12 -06:00
|
|
|
|
2023-04-21 07:36:29 -06:00
|
|
|
async def Info(self, request, context):
|
|
|
|
return self.model.info
|
|
|
|
|
2023-04-26 12:23:54 -06:00
|
|
|
async def Health(self, request, context):
|
|
|
|
if self.model.device.type == "cuda":
|
|
|
|
torch.zeros((2, 2)).cuda()
|
|
|
|
return generate_pb2.HealthResponse()
|
|
|
|
|
2022-10-08 04:30:12 -06:00
|
|
|
async def ServiceDiscovery(self, request, context):
|
|
|
|
return generate_pb2.ServiceDiscoveryResponse(urls=self.server_urls)
|
|
|
|
|
|
|
|
async def ClearCache(self, request, context):
|
2023-03-28 03:29:35 -06:00
|
|
|
if request.HasField("id"):
|
|
|
|
self.cache.delete(request.id)
|
|
|
|
else:
|
|
|
|
self.cache.clear()
|
2022-10-11 08:50:54 -06:00
|
|
|
return generate_pb2.ClearCacheResponse()
|
2022-10-08 04:30:12 -06:00
|
|
|
|
2023-04-24 09:59:00 -06:00
|
|
|
async def FilterBatch(self, request, context):
|
|
|
|
batch = self.cache.pop(request.batch_id)
|
|
|
|
if batch is None:
|
|
|
|
raise ValueError(f"Batch ID {request.batch_id} not found in cache.")
|
2023-05-24 11:19:57 -06:00
|
|
|
filtered_batch = batch.filter(request.request_ids)
|
2023-04-24 09:59:00 -06:00
|
|
|
self.cache.set(filtered_batch)
|
|
|
|
|
|
|
|
return generate_pb2.FilterBatchResponse(batch=filtered_batch.to_pb())
|
|
|
|
|
2023-06-30 11:09:59 -06:00
|
|
|
async def Warmup(self, request, context):
|
2024-05-28 03:51:31 -06:00
|
|
|
if self.quantize in {"exl2", "gptq"}:
|
2023-12-18 08:07:05 -07:00
|
|
|
try:
|
|
|
|
# When using GPTQ, Exllama kernels need some global kernels
|
|
|
|
# For which we have the finale shapes only after the model has loaded
|
|
|
|
# This will allocate those buffers.
|
2024-05-13 04:44:30 -06:00
|
|
|
from text_generation_server.layers.gptq import (
|
2023-12-18 08:07:05 -07:00
|
|
|
create_exllama_buffers,
|
|
|
|
set_device,
|
|
|
|
)
|
|
|
|
|
|
|
|
set_device(self.model.device)
|
|
|
|
create_exllama_buffers(request.max_prefill_tokens)
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2024-05-23 06:39:38 -06:00
|
|
|
if (
|
|
|
|
self.model.batch_type in VLM_BATCH_TYPES
|
|
|
|
): # Hack, i would rather use kwargs in the `from_pb` call
|
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
|
|
|
batch = self.model.batch_type.from_pb_processor(
|
2023-09-27 04:22:09 -06:00
|
|
|
request.batch,
|
|
|
|
self.model.tokenizer,
|
|
|
|
self.model.processor,
|
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
|
|
|
self.model.model.config,
|
2023-09-27 04:22:09 -06:00
|
|
|
self.model.dtype,
|
|
|
|
self.model.device,
|
2023-08-17 06:38:49 -06:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
batch = self.model.batch_type.from_pb(
|
|
|
|
request.batch, self.model.tokenizer, self.model.dtype, self.model.device
|
|
|
|
)
|
2023-07-19 01:31:25 -06:00
|
|
|
max_supported_total_tokens = self.model.warmup(batch)
|
2023-07-12 09:05:50 -06:00
|
|
|
|
2023-07-19 01:31:25 -06:00
|
|
|
return generate_pb2.WarmupResponse(
|
|
|
|
max_supported_total_tokens=max_supported_total_tokens
|
|
|
|
)
|
2023-06-30 11:09:59 -06:00
|
|
|
|
2023-01-31 09:04:00 -07:00
|
|
|
async def Prefill(self, request, context):
|
2023-12-14 07:59:38 -07:00
|
|
|
start = time.time_ns()
|
2024-05-23 06:39:38 -06:00
|
|
|
if (
|
|
|
|
self.model.batch_type in VLM_BATCH_TYPES
|
|
|
|
): # Hack, i would rather use kwargs in the `from_pb` call
|
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
|
|
|
batch = self.model.batch_type.from_pb_processor(
|
2023-09-27 04:22:09 -06:00
|
|
|
request.batch,
|
|
|
|
self.model.tokenizer,
|
|
|
|
self.model.processor,
|
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
|
|
|
self.model.model.config,
|
2023-09-27 04:22:09 -06:00
|
|
|
self.model.dtype,
|
|
|
|
self.model.device,
|
2023-08-17 06:38:49 -06:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
batch = self.model.batch_type.from_pb(
|
|
|
|
request.batch, self.model.tokenizer, self.model.dtype, self.model.device
|
|
|
|
)
|
2022-10-11 08:50:54 -06:00
|
|
|
|
2023-12-14 07:59:38 -07:00
|
|
|
generations, next_batch, timings = self.model.generate_token(batch)
|
2022-10-11 08:50:54 -06:00
|
|
|
self.cache.set(next_batch)
|
|
|
|
|
2023-01-31 09:04:00 -07:00
|
|
|
return generate_pb2.PrefillResponse(
|
|
|
|
generations=[generation.to_pb() for generation in generations],
|
2022-10-11 08:50:54 -06:00
|
|
|
batch=next_batch.to_pb() if next_batch else None,
|
2023-12-14 07:59:38 -07:00
|
|
|
forward_ns=timings[0],
|
|
|
|
decode_ns=timings[1],
|
|
|
|
total_ns=time.time_ns() - start,
|
2022-10-08 04:30:12 -06:00
|
|
|
)
|
|
|
|
|
2023-01-31 09:04:00 -07:00
|
|
|
async def Decode(self, request, context):
|
2023-12-14 07:59:38 -07:00
|
|
|
start = time.time_ns()
|
2022-10-11 08:50:54 -06:00
|
|
|
if len(request.batches) == 0:
|
|
|
|
raise ValueError("Must provide at least one batch")
|
|
|
|
|
|
|
|
batches = []
|
|
|
|
for batch_pb in request.batches:
|
|
|
|
batch = self.cache.pop(batch_pb.id)
|
|
|
|
if batch is None:
|
|
|
|
raise ValueError(f"Batch ID {batch_pb.id} not found in cache.")
|
2023-04-24 09:59:00 -06:00
|
|
|
batches.append(batch)
|
2023-04-20 03:07:40 -06:00
|
|
|
|
|
|
|
if len(batches) == 0:
|
|
|
|
raise ValueError("All batches are empty")
|
2022-10-11 08:50:54 -06:00
|
|
|
|
|
|
|
if len(batches) > 1:
|
2023-12-14 07:59:38 -07:00
|
|
|
start_concat = time.time_ns()
|
2022-11-04 11:03:04 -06:00
|
|
|
batch = self.model.batch_type.concatenate(batches)
|
2023-12-14 07:59:38 -07:00
|
|
|
concat_ns = time.time_ns() - start_concat
|
2022-10-11 08:50:54 -06:00
|
|
|
else:
|
|
|
|
batch = batches[0]
|
2023-12-14 07:59:38 -07:00
|
|
|
concat_ns = None
|
2022-10-11 08:50:54 -06:00
|
|
|
|
2023-12-14 07:59:38 -07:00
|
|
|
generations, next_batch, timings = self.model.generate_token(batch)
|
2022-10-11 08:50:54 -06:00
|
|
|
self.cache.set(next_batch)
|
|
|
|
|
2023-01-31 09:04:00 -07:00
|
|
|
return generate_pb2.DecodeResponse(
|
|
|
|
generations=[generation.to_pb() for generation in generations],
|
2022-10-11 08:50:54 -06:00
|
|
|
batch=next_batch.to_pb() if next_batch else None,
|
2023-12-14 07:59:38 -07:00
|
|
|
concat_ns=concat_ns,
|
|
|
|
forward_ns=timings[0],
|
|
|
|
decode_ns=timings[1],
|
|
|
|
total_ns=time.time_ns() - start,
|
2022-10-11 08:50:54 -06:00
|
|
|
)
|
|
|
|
|
2022-10-08 04:30:12 -06:00
|
|
|
|
2022-10-18 07:19:03 -06:00
|
|
|
def serve(
|
2023-07-27 04:28:10 -06:00
|
|
|
model_id: str,
|
2024-06-25 12:46:27 -06:00
|
|
|
lora_adapter_ids: Optional[List[str]],
|
2023-07-27 04:28:10 -06:00
|
|
|
revision: Optional[str],
|
|
|
|
sharded: bool,
|
|
|
|
quantize: Optional[str],
|
2023-12-11 04:46:30 -07:00
|
|
|
speculate: Optional[int],
|
2023-07-27 04:28:10 -06:00
|
|
|
dtype: Optional[str],
|
|
|
|
trust_remote_code: bool,
|
|
|
|
uds_path: Path,
|
2024-06-10 01:09:50 -06:00
|
|
|
max_input_tokens: int,
|
2023-07-24 06:25:43 -06:00
|
|
|
):
|
|
|
|
async def serve_inner(
|
2023-07-27 04:28:10 -06:00
|
|
|
model_id: str,
|
2024-06-25 12:46:27 -06:00
|
|
|
lora_adapter_ids: Optional[List[str]],
|
2023-07-27 04:28:10 -06:00
|
|
|
revision: Optional[str],
|
|
|
|
sharded: bool = False,
|
|
|
|
quantize: Optional[str] = None,
|
2023-12-11 04:46:30 -07:00
|
|
|
speculate: Optional[int] = None,
|
2023-07-27 04:28:10 -06:00
|
|
|
dtype: Optional[str] = None,
|
|
|
|
trust_remote_code: bool = False,
|
2022-10-08 04:30:12 -06:00
|
|
|
):
|
2022-10-18 07:19:03 -06:00
|
|
|
unix_socket_template = "unix://{}-{}"
|
2024-06-25 12:46:27 -06:00
|
|
|
adapter_to_index = {}
|
2022-10-08 04:30:12 -06:00
|
|
|
if sharded:
|
|
|
|
server_urls = [
|
2022-10-18 07:19:03 -06:00
|
|
|
unix_socket_template.format(uds_path, rank)
|
2022-10-28 11:24:00 -06:00
|
|
|
for rank in range(int(os.environ["WORLD_SIZE"]))
|
2022-10-08 04:30:12 -06:00
|
|
|
]
|
2022-10-28 11:24:00 -06:00
|
|
|
local_url = server_urls[int(os.environ["RANK"])]
|
2022-10-08 04:30:12 -06:00
|
|
|
else:
|
2022-10-18 07:19:03 -06:00
|
|
|
local_url = unix_socket_template.format(uds_path, 0)
|
2022-10-08 04:30:12 -06:00
|
|
|
server_urls = [local_url]
|
|
|
|
|
2023-02-07 07:38:22 -07:00
|
|
|
try:
|
2023-06-30 12:30:09 -06:00
|
|
|
model = get_model(
|
2023-12-11 06:49:52 -07:00
|
|
|
model_id,
|
2024-06-25 12:46:27 -06:00
|
|
|
lora_adapter_ids,
|
2023-12-11 06:49:52 -07:00
|
|
|
revision,
|
|
|
|
sharded,
|
|
|
|
quantize,
|
|
|
|
speculate,
|
|
|
|
dtype,
|
|
|
|
trust_remote_code,
|
2024-06-10 01:09:50 -06:00
|
|
|
max_input_tokens,
|
2023-06-30 12:30:09 -06:00
|
|
|
)
|
2024-06-25 12:46:27 -06:00
|
|
|
|
|
|
|
if len(lora_adapter_ids) > 0:
|
|
|
|
for index, adapter_id in enumerate(lora_adapter_ids):
|
|
|
|
# TODO: improve non merged adapter loading and long term
|
|
|
|
# improve adapter loading as a whole
|
|
|
|
adapter_parameters = AdapterParameters(
|
|
|
|
adapter_ids=[adapter_id],
|
|
|
|
weights=None, # will be set to 1
|
|
|
|
merge_strategy=0,
|
|
|
|
density=1.0,
|
|
|
|
majority_sign_method=0,
|
|
|
|
)
|
|
|
|
adapter_index = index + 1
|
|
|
|
adapter_to_index[adapter_id] = adapter_index
|
|
|
|
model.load_adapter(
|
|
|
|
adapter_parameters,
|
|
|
|
None, # adapter_source
|
|
|
|
adapter_index,
|
|
|
|
None, # api_token
|
|
|
|
False, # dynamic
|
|
|
|
)
|
|
|
|
|
2023-02-07 07:38:22 -07:00
|
|
|
except Exception:
|
|
|
|
logger.exception("Error when initializing model")
|
|
|
|
raise
|
2022-10-28 11:24:00 -06:00
|
|
|
|
2024-06-25 12:46:27 -06:00
|
|
|
set_adapter_to_index(adapter_to_index)
|
2023-02-13 05:02:45 -07:00
|
|
|
server = aio.server(
|
|
|
|
interceptors=[
|
|
|
|
ExceptionInterceptor(),
|
|
|
|
UDSOpenTelemetryAioServerInterceptor(),
|
2024-06-17 08:40:44 -06:00
|
|
|
],
|
|
|
|
options=[
|
|
|
|
# Set the maximum possible message length: i32::MAX
|
|
|
|
("grpc.max_receive_message_length", (1 << 31) - 1)
|
|
|
|
],
|
2023-02-13 05:02:45 -07:00
|
|
|
)
|
2022-10-11 08:50:54 -06:00
|
|
|
generate_pb2_grpc.add_TextGenerationServiceServicer_to_server(
|
2023-12-18 08:07:05 -07:00
|
|
|
TextGenerationService(model, Cache(), quantize, server_urls), server
|
2022-10-08 04:30:12 -06:00
|
|
|
)
|
|
|
|
SERVICE_NAMES = (
|
2022-10-11 08:50:54 -06:00
|
|
|
generate_pb2.DESCRIPTOR.services_by_name["TextGenerationService"].full_name,
|
2022-10-08 04:30:12 -06:00
|
|
|
reflection.SERVICE_NAME,
|
|
|
|
)
|
|
|
|
reflection.enable_server_reflection(SERVICE_NAMES, server)
|
|
|
|
server.add_insecure_port(local_url)
|
2023-02-07 07:38:22 -07:00
|
|
|
|
2022-10-08 04:30:12 -06:00
|
|
|
await server.start()
|
2023-02-07 07:38:22 -07:00
|
|
|
|
2023-01-05 04:01:23 -07:00
|
|
|
logger.info("Server started at {}".format(local_url))
|
Fixing signals. (#1910)
Taking the signal handles later, so during loads,
regular signal handling is done, we only need to handle SIGINT and
SIGTERM during real loads to get more graceful shutdowns when queries
are in flight.
Fixes #1842
# What does this PR do?
<!--
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-05-16 13:40:10 -06:00
|
|
|
signal_handler = SignalHandler()
|
2024-04-29 09:23:40 -06:00
|
|
|
while signal_handler.KEEP_PROCESSING:
|
|
|
|
await asyncio.sleep(0.5)
|
2022-10-08 04:30:12 -06:00
|
|
|
|
MI300 compatibility (#1764)
Adds support for AMD Instinct MI300 in TGI.
Most changes are:
* Support PyTorch TunableOp to pick the GEMM/GEMV kernels for decoding
https://github.com/pytorch/pytorch/tree/main/aten/src/ATen/cuda/tunable.
TunableOp is disabled by default, and can be enabled with
`PYTORCH_TUNABLEOP_ENABLED=1`.
* Update ROCm dockerfile to PyTorch 2.3 (actually patched with changes
from https://github.com/pytorch/pytorch/pull/124362)
* Support SILU & Linear custom kernels contributed by AMD
* Update vLLM paged attention to https://github.com/fxmarty/rocm-vllm/,
branching out of a much more recent commit
https://github.com/ROCm/vllm/commit/3489ce7936c5de588916ae3047c44c23c0b0c308
* Support FA2 Triton kernel as recommended by AMD. Can be used by
specifying `ROCM_USE_FLASH_ATTN_V2_TRITON=1`.
* Update dockerfile to ROCm 6.1
By default, TunableOp tuning results are saved in `/data` (e.g.
`/data/tunableop_meta-llama-Llama-2-70b-chat-hf_tp1_rank0.csv`) in order
to avoid to have to rerun the tuning at each `docker run`.
Example:
```
Validator,PT_VERSION,2.3.0
Validator,ROCM_VERSION,6.1.0.0-82-5fabb4c
Validator,HIPBLASLT_VERSION,0.7.0-1549b021
Validator,GCN_ARCH_NAME,gfx942:sramecc+:xnack-
Validator,ROCBLAS_VERSION,4.1.0-cefa4a9b-dirty
GemmTunableOp_Half_TN,tn_8192_7_28672,Gemm_Rocblas_45475,0.132098
GemmTunableOp_Half_TN,tn_10240_4_8192,Gemm_Rocblas_45546,0.0484431
GemmTunableOp_Half_TN,tn_32000_6_8192,Default,0.149546
GemmTunableOp_Half_TN,tn_32000_3_8192,Gemm_Rocblas_45520,0.147119
GemmTunableOp_Half_TN,tn_8192_3_28672,Gemm_Rocblas_45475,0.132645
GemmTunableOp_Half_TN,tn_10240_3_8192,Gemm_Rocblas_45546,0.0482971
GemmTunableOp_Half_TN,tn_57344_5_8192,Gemm_Rocblas_45520,0.255694
GemmTunableOp_Half_TN,tn_10240_7_8192,Gemm_Rocblas_45517,0.0482522
GemmTunableOp_Half_TN,tn_8192_3_8192,Gemm_Rocblas_45546,0.0444671
GemmTunableOp_Half_TN,tn_8192_5_8192,Gemm_Rocblas_45546,0.0445834
GemmTunableOp_Half_TN,tn_57344_7_8192,Gemm_Rocblas_45520,0.25622
GemmTunableOp_Half_TN,tn_8192_2_28672,Gemm_Rocblas_45475,0.132122
GemmTunableOp_Half_TN,tn_8192_4_8192,Gemm_Rocblas_45517,0.0453191
GemmTunableOp_Half_TN,tn_10240_5_8192,Gemm_Rocblas_45517,0.0482514
GemmTunableOp_Half_TN,tn_8192_5_28672,Gemm_Rocblas_45542,0.133914
GemmTunableOp_Half_TN,tn_8192_2_8192,Gemm_Rocblas_45517,0.0446516
GemmTunableOp_Half_TN,tn_8192_1_28672,Gemm_Hipblaslt_TN_10814,0.131953
GemmTunableOp_Half_TN,tn_10240_2_8192,Gemm_Rocblas_45546,0.0481043
GemmTunableOp_Half_TN,tn_32000_4_8192,Gemm_Rocblas_45520,0.147497
GemmTunableOp_Half_TN,tn_8192_6_28672,Gemm_Rocblas_45529,0.134895
GemmTunableOp_Half_TN,tn_57344_2_8192,Gemm_Rocblas_45520,0.254716
GemmTunableOp_Half_TN,tn_57344_4_8192,Gemm_Rocblas_45520,0.255731
GemmTunableOp_Half_TN,tn_10240_6_8192,Gemm_Rocblas_45517,0.0484816
GemmTunableOp_Half_TN,tn_57344_3_8192,Gemm_Rocblas_45520,0.254701
GemmTunableOp_Half_TN,tn_8192_4_28672,Gemm_Rocblas_45475,0.132159
GemmTunableOp_Half_TN,tn_32000_2_8192,Default,0.147524
GemmTunableOp_Half_TN,tn_32000_5_8192,Default,0.147074
GemmTunableOp_Half_TN,tn_8192_6_8192,Gemm_Rocblas_45546,0.0454045
GemmTunableOp_Half_TN,tn_57344_6_8192,Gemm_Rocblas_45520,0.255582
GemmTunableOp_Half_TN,tn_32000_7_8192,Default,0.146705
GemmTunableOp_Half_TN,tn_8192_7_8192,Gemm_Rocblas_45546,0.0445489
```
---------
Co-authored-by: Mohit Sharma <mohit21sharma.ms@gmail.com>
2024-05-17 07:30:47 -06:00
|
|
|
set_model_id(model_id)
|
2023-06-30 12:30:09 -06:00
|
|
|
asyncio.run(
|
2023-12-11 06:49:52 -07:00
|
|
|
serve_inner(
|
2024-06-25 12:46:27 -06:00
|
|
|
model_id,
|
|
|
|
lora_adapter_ids,
|
|
|
|
revision,
|
|
|
|
sharded,
|
|
|
|
quantize,
|
|
|
|
speculate,
|
|
|
|
dtype,
|
|
|
|
trust_remote_code,
|
2023-12-11 06:49:52 -07:00
|
|
|
)
|
2023-06-30 12:30:09 -06:00
|
|
|
)
|