[Auto Sync] Update detokenizer_manager.py, io_struct.py, mu... (20260120) (#17442)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Wangfan Fu <wangfan@x.ai>
This commit is contained in:
@@ -69,7 +69,6 @@ dependencies = [
|
||||
"torchaudio==2.9.1",
|
||||
"torchcodec==0.8.0 ; sys_platform != 'linux' or (sys_platform == 'linux' and platform_machine != 'aarch64' and platform_machine != 'arm64' and platform_machine != 'armv7l')", # torchcodec does not exist in those systems. If not provided, transformer will use torchvision instead by default.
|
||||
"torchvision",
|
||||
"torchao==0.9.0",
|
||||
"tqdm",
|
||||
"transformers==4.57.1",
|
||||
"uvicorn",
|
||||
|
||||
@@ -57,7 +57,6 @@ dependencies = [
|
||||
"soundfile==0.13.1",
|
||||
"tiktoken",
|
||||
"timm==1.0.16",
|
||||
"torchao==0.9.0",
|
||||
"tqdm",
|
||||
"transformers==4.57.1",
|
||||
"uvicorn",
|
||||
|
||||
@@ -57,7 +57,6 @@ runtime_common = [
|
||||
"soundfile==0.13.1",
|
||||
"tiktoken",
|
||||
"timm==1.0.16",
|
||||
"torchao==0.9.0",
|
||||
"tqdm",
|
||||
"transformers==4.57.1",
|
||||
"uvicorn",
|
||||
|
||||
@@ -61,7 +61,6 @@ dependencies = [
|
||||
"soundfile==0.13.1",
|
||||
"tiktoken",
|
||||
"timm==1.0.16",
|
||||
"torchao==0.9.0",
|
||||
"tqdm",
|
||||
"transformers==4.57.1",
|
||||
"uvicorn",
|
||||
|
||||
@@ -46,7 +46,7 @@ import orjson
|
||||
import requests
|
||||
import uvicorn
|
||||
import uvloop
|
||||
from fastapi import Depends, FastAPI, HTTPException, Request, UploadFile
|
||||
from fastapi import Depends, FastAPI, HTTPException, Request
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import ORJSONResponse, Response, StreamingResponse
|
||||
@@ -552,26 +552,20 @@ async def model_info():
|
||||
"has_audio_understanding": model_config.is_audio_understandable_model,
|
||||
"model_type": getattr(model_config.hf_config, "model_type", None),
|
||||
"architectures": getattr(model_config.hf_config, "architectures", None),
|
||||
"weight_version": _global_state.tokenizer_manager.server_args.weight_version,
|
||||
# "hf_config": model_config.hf_config.to_dict(),
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
@app.get("/get_weight_version")
|
||||
async def get_weight_version():
|
||||
"""Get the current weight version (deprecated - use /weight_version instead)."""
|
||||
logger.warning(
|
||||
"Endpoint '/get_weight_version' is deprecated and will be removed in a future version. "
|
||||
"Please use '/weight_version' instead."
|
||||
)
|
||||
return await weight_version()
|
||||
|
||||
|
||||
@app.get("/weight_version")
|
||||
async def weight_version():
|
||||
"""Get the current weight version."""
|
||||
return {
|
||||
"weight_version": _global_state.tokenizer_manager.server_args.weight_version
|
||||
}
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Endpoint '/get_weight_version' or '/weight_version' is deprecated. Please use '/model_info' instead.",
|
||||
)
|
||||
|
||||
|
||||
@app.get("/get_server_info")
|
||||
@@ -661,30 +655,6 @@ async def generate_request(obj: GenerateReqInput, request: Request):
|
||||
return _create_error_response(e)
|
||||
|
||||
|
||||
@app.api_route("/generate_from_file", methods=["POST"])
|
||||
async def generate_from_file_request(file: UploadFile, request: Request):
|
||||
"""Handle a generate request, this is purely to work with input_embeds."""
|
||||
content = await file.read()
|
||||
input_embeds = orjson.loads(content.decode("utf-8"))
|
||||
|
||||
obj = GenerateReqInput(
|
||||
input_embeds=input_embeds,
|
||||
sampling_params={
|
||||
"temperature": 0.0,
|
||||
"max_new_tokens": 512,
|
||||
},
|
||||
)
|
||||
|
||||
try:
|
||||
ret = await _global_state.tokenizer_manager.generate_request(
|
||||
obj, request
|
||||
).__anext__()
|
||||
return ret
|
||||
except ValueError as e:
|
||||
logger.error(f"Error: {e}")
|
||||
return _create_error_response(e)
|
||||
|
||||
|
||||
@app.api_route("/encode", methods=["POST", "PUT"])
|
||||
async def encode_request(obj: EmbeddingReqInput, request: Request):
|
||||
"""Handle an embedding request."""
|
||||
|
||||
@@ -326,20 +326,20 @@ class DetokenizerManager(MultiHttpWorkerDetokenizerMixin):
|
||||
|
||||
return output_strs
|
||||
|
||||
def _extract_routed_experts(self, recv_obj: BatchTokenIDOutput) -> List[List[int]]:
|
||||
output_routed_experts = None
|
||||
if recv_obj.output_routed_experts is not None:
|
||||
output_routed_experts = [
|
||||
def _extract_routed_experts(
|
||||
self, recv_obj: BatchTokenIDOutput
|
||||
) -> List[List[int]] | None:
|
||||
routed_experts = None
|
||||
if recv_obj.routed_experts is not None:
|
||||
routed_experts = [
|
||||
(
|
||||
pybase64.b64encode(output_routed_experts.numpy().tobytes()).decode(
|
||||
"utf-8"
|
||||
)
|
||||
if output_routed_experts is not None
|
||||
pybase64.b64encode(routed_experts.numpy().tobytes()).decode("utf-8")
|
||||
if routed_experts is not None
|
||||
else []
|
||||
)
|
||||
for output_routed_experts in recv_obj.output_routed_experts
|
||||
for routed_experts in recv_obj.routed_experts
|
||||
]
|
||||
return output_routed_experts
|
||||
return routed_experts
|
||||
|
||||
def handle_batch_token_id_out(self, recv_obj: BatchTokenIDOutput):
|
||||
# If handling idle batch, set output_strs to [].
|
||||
@@ -348,7 +348,7 @@ class DetokenizerManager(MultiHttpWorkerDetokenizerMixin):
|
||||
if len(recv_obj.rids) > 0
|
||||
else []
|
||||
)
|
||||
output_routed_experts = self._extract_routed_experts(recv_obj)
|
||||
routed_experts = self._extract_routed_experts(recv_obj)
|
||||
|
||||
return BatchStrOutput(
|
||||
rids=recv_obj.rids,
|
||||
@@ -375,7 +375,7 @@ class DetokenizerManager(MultiHttpWorkerDetokenizerMixin):
|
||||
output_token_ids_logprobs_idx=recv_obj.output_token_ids_logprobs_idx,
|
||||
output_token_entropy_val=recv_obj.output_token_entropy_val,
|
||||
output_hidden_states=recv_obj.output_hidden_states,
|
||||
output_routed_experts=output_routed_experts,
|
||||
routed_experts=routed_experts,
|
||||
customized_info=recv_obj.customized_info,
|
||||
placeholder_tokens_idx=None,
|
||||
placeholder_tokens_val=None,
|
||||
|
||||
@@ -202,6 +202,8 @@ class GenerateReqInput(BaseReq, APIServingTimingMixin):
|
||||
return_hidden_states: Union[List[bool], bool] = False
|
||||
# Whether to return captured routed experts
|
||||
return_routed_experts: bool = False
|
||||
# The start location in the prompt for returning routed experts.
|
||||
routed_experts_start_len: int = 0
|
||||
|
||||
# The modalities of the image data [image, multi-images, video]
|
||||
modalities: Optional[List[str]] = None
|
||||
@@ -709,6 +711,8 @@ class TokenizedGenerateReqInput(BaseReq):
|
||||
|
||||
# Whether to return captured routed experts
|
||||
return_routed_experts: bool = False
|
||||
# The start location in the prompt for returning routed experts.
|
||||
routed_experts_start_len: int = 0
|
||||
|
||||
# The input embeds
|
||||
input_embeds: Optional[Union[List[List[List[float]]], List[List[float]]]] = None
|
||||
@@ -981,8 +985,9 @@ class BatchTokenIDOutput(
|
||||
# Hidden states
|
||||
output_hidden_states: List[List[float]]
|
||||
|
||||
# The routed experts for each output token
|
||||
output_routed_experts: List[torch.Tensor]
|
||||
# The routed experts for each token, including both input and output tokens
|
||||
# routed_experts[i] is a tensor of shape (token, layer, top_k) for request i
|
||||
routed_experts: List[Optional[torch.Tensor]]
|
||||
|
||||
# The information of placeholder tokens (e.g., image token)
|
||||
# idx is the index of the token in the prompt after expansion.
|
||||
@@ -1068,8 +1073,9 @@ class BatchStrOutput(
|
||||
# Hidden states
|
||||
output_hidden_states: List[List[float]]
|
||||
|
||||
# The routed experts for each output token
|
||||
output_routed_experts: List[List[int]]
|
||||
# The routed experts for each token, including both input and output tokens
|
||||
# routed_experts[i] is a tensor of shape (token, layer, top_k) for request i
|
||||
routed_experts: List[Optional[torch.Tensor]]
|
||||
|
||||
# The information of placeholder tokens (e.g., image token)
|
||||
# idx is the index of the token in the prompt after expansion.
|
||||
|
||||
@@ -278,8 +278,8 @@ def _handle_output_by_index(output, i):
|
||||
output_hidden_states=_extract_field_by_index(
|
||||
output, "output_hidden_states", i, check_length=False
|
||||
),
|
||||
output_routed_experts=_extract_field_by_index(
|
||||
output, "output_routed_experts", i, check_length=False
|
||||
routed_experts=_extract_field_by_index(
|
||||
output, "routed_experts", i, check_length=False
|
||||
),
|
||||
customized_info=_extract_field_by_index(
|
||||
output, "customized_info", i, check_length=False
|
||||
|
||||
@@ -854,7 +854,7 @@ class SchedulerOutputProcessorMixin:
|
||||
retraction_counts = []
|
||||
output_hidden_states = None
|
||||
load = self.get_load()
|
||||
output_routed_experts = None
|
||||
routed_experts = None
|
||||
customized_info = {}
|
||||
|
||||
queue_times = []
|
||||
@@ -1051,9 +1051,9 @@ class SchedulerOutputProcessorMixin:
|
||||
output_hidden_states = []
|
||||
output_hidden_states.append(req.hidden_states)
|
||||
if req.return_routed_experts:
|
||||
if output_routed_experts is None:
|
||||
output_routed_experts = []
|
||||
output_routed_experts.append(req.routed_experts)
|
||||
if routed_experts is None:
|
||||
routed_experts = []
|
||||
routed_experts.append(req.routed_experts)
|
||||
|
||||
if req.customized_info is not None:
|
||||
for k, v in req.customized_info.items():
|
||||
@@ -1108,7 +1108,7 @@ class SchedulerOutputProcessorMixin:
|
||||
output_token_ids_logprobs_idx=output_token_ids_logprobs_idx,
|
||||
output_token_entropy_val=None,
|
||||
output_hidden_states=output_hidden_states,
|
||||
output_routed_experts=output_routed_experts,
|
||||
routed_experts=routed_experts,
|
||||
customized_info=customized_info,
|
||||
placeholder_tokens_idx=None,
|
||||
placeholder_tokens_val=None,
|
||||
|
||||
@@ -1534,8 +1534,8 @@ class TokenizerManager(TokenizerCommunicatorMixin, TokenizerManagerMultiItemMixi
|
||||
|
||||
if getattr(recv_obj, "output_hidden_states", None):
|
||||
meta_info["hidden_states"] = recv_obj.output_hidden_states[i]
|
||||
if getattr(recv_obj, "output_routed_experts", None):
|
||||
meta_info["routed_experts"] = recv_obj.output_routed_experts[i]
|
||||
if getattr(recv_obj, "routed_experts", None):
|
||||
meta_info["routed_experts"] = recv_obj.routed_experts[i]
|
||||
if getattr(recv_obj, "customized_info", None):
|
||||
for k, v in recv_obj.customized_info.items():
|
||||
meta_info[k] = v[i]
|
||||
|
||||
Reference in New Issue
Block a user