-
Notifications
You must be signed in to change notification settings - Fork 122
Add base_model=encoder_torch for BEI-torch backend #2592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
8687e63
22d758d
cd62ab1
6c084bc
9410a3b
5404fbc
6c4ee86
f000092
fcfa5e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,10 @@ | |
| BEI_TRTLLM_CLIENT_BATCH_SIZE = 128 | ||
| BEI_MAX_CONCURRENCY_TARGET_REQUESTS = 2048 | ||
| BEI_REQUIRED_MAX_NUM_TOKENS = 16384 | ||
| # BEI-torch (vLLM) rejects --max-batch-tokens below this; long-context embedders | ||
| # (Nemotron-3-Embed at 32k) need the headroom. User max_num_tokens is clamped | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if max_num_tokens is clamped? WDYM? We are not clamping down, right? |
||
| # upward to this floor, matching the ENCODER/ENCODER_BERT behavior. | ||
| BEI_TORCH_REQUIRED_MAX_NUM_TOKENS = 32768 | ||
|
|
||
| TRTLLM_MIN_MEMORY_REQUEST_GI = 10 | ||
| HF_MODELS_API_URL = "https://huggingface.co/api/models" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,11 @@ class TrussTRTLLMModel(str, Enum): | |
| # the encoder_bert setting will specfically optimize for thoughput and cold-start latency of small models (<4B parameters) | ||
| # supports also splade and colbert style models or ModernBert. | ||
| ENCODER_BERT = "encoder_bert" | ||
| # BEI torch backend (text-embeddings-router + vLLM). Serves embedding, reranker, and | ||
| # classification models whose architecture the TRT-LLM `encoder` path cannot compile | ||
| # (e.g. LlamaBidirectional / Ministral3-Embed, Gemma2Embedding, jina-v3). No engine | ||
| # build step; the checkpoint is served directly by the torch backend. | ||
| ENCODER_TORCH = "encoder_torch" | ||
| # Decoder will launch the backend that is optimized for decoder only models such as LLama3ForCausalLM, Qwen3MoeForCausalLM etc. | ||
| DECODER = "decoder" | ||
| # a ERROR will be raised if you push one of the below models. Don't use | ||
|
|
@@ -365,7 +370,31 @@ def uses_lora(self) -> bool: | |
|
|
||
| def _bei_specfic_migration(self): | ||
| """performs embedding specfic optimizations (no kv-cache, high batch size)""" | ||
| if self.base_model == TrussTRTLLMModel.ENCODER: | ||
| if self.base_model == TrussTRTLLMModel.ENCODER_TORCH: | ||
| # BEI-torch has no engine build, so build-time quantization is not applicable. | ||
| # Users wanting quantized weights must point checkpoint_repository at a | ||
| # pre-quantized HF checkpoint. | ||
| if self.quantization_type != TrussTRTLLMQuantizationType.NO_QUANT: | ||
| raise ValueError( | ||
| f"base_model=encoder_torch does not support build-time quantization; " | ||
| f"you set build.quantization_type={self.quantization_type.value}. " | ||
| "Point checkpoint_repository at a pre-quantized HF checkpoint instead." | ||
| ) | ||
| # Speculative decoding is a decoder concept; embedding/reranker serving via | ||
| # BEI-torch has no draft/target loop. | ||
| if self.speculator is not None: | ||
| raise ValueError( | ||
| "base_model=encoder_torch does not support speculative decoding; " | ||
| "remove trt_llm.build.speculator." | ||
| ) | ||
| # LoRA adapters are a TRT-LLM build-time concept; vLLM serves the | ||
| # checkpoint as-is, so adapters would be silently ignored. | ||
| if self.lora_adapters is not None: | ||
| raise ValueError( | ||
| "base_model=encoder_torch does not support lora_adapters; " | ||
| "remove trt_llm.build.lora_adapters." | ||
| ) | ||
| elif self.base_model == TrussTRTLLMModel.ENCODER: | ||
| # Encoder specific settings | ||
| if self.max_seq_len: | ||
| logger.info( | ||
|
|
@@ -572,6 +601,7 @@ class VersionsOverrides(PydanticTrTBaseModel): | |
| briton_version: Optional[str] = None | ||
| bei_version: Optional[str] = None | ||
| bei_bert_version: Optional[str] = None | ||
| bei_torch_version: Optional[str] = None | ||
| v2_llm_version: Optional[str] = None | ||
|
|
||
| @model_validator(mode="before") | ||
|
|
@@ -581,6 +611,7 @@ def version_must_start_with_number(cls, data): | |
| "briton_version", | ||
| "bei_version", | ||
| "bei_bert_version", | ||
| "bei_torch_version", | ||
| ]: | ||
| v = data.get(field) | ||
| if v is not None and (not v or not v[0].isdigit()): | ||
|
|
@@ -596,6 +627,10 @@ class ImageVersions(PydanticTrTBaseModel): | |
| # INTERNAL | ||
| bei_image: str | ||
| beibert_image: str | ||
| # Base image for the BEI torch backend (text-embeddings-router + vLLM). Backend | ||
| # inserts a resolved image reference; the default here is a placeholder so | ||
| # local unit tests can construct ImageVersions without wiring core-product. | ||
| bei_torch_image: str = "baseten/bei:torch-dev-placeholder" | ||
| briton_image: str | ||
| v2_llm_image: str | ||
|
|
||
|
|
@@ -618,7 +653,11 @@ def model_post_init(self, __context): | |
| self.runtime.enable_chunked_context | ||
| and ( | ||
| self.build.base_model | ||
| not in (TrussTRTLLMModel.ENCODER, TrussTRTLLMModel.ENCODER_BERT) | ||
| not in ( | ||
| TrussTRTLLMModel.ENCODER, | ||
| TrussTRTLLMModel.ENCODER_BERT, | ||
| TrussTRTLLMModel.ENCODER_TORCH, | ||
| ) | ||
| ) | ||
| and not ( | ||
| self.build.plugin_configuration.use_paged_context_fmha | ||
|
|
@@ -636,7 +675,11 @@ def model_post_init(self, __context): | |
| if ( | ||
| self.runtime.webserver_default_route is None | ||
| and self.build.base_model | ||
| in (TrussTRTLLMModel.ENCODER, TrussTRTLLMModel.ENCODER_BERT) | ||
| in ( | ||
| TrussTRTLLMModel.ENCODER, | ||
| TrussTRTLLMModel.ENCODER_BERT, | ||
| TrussTRTLLMModel.ENCODER_TORCH, | ||
| ) | ||
| and not ENGINE_BUILDER_TRUSS_RUNTIME_MIGRATION | ||
| ): | ||
| if hf_cfg is not None: | ||
|
|
@@ -672,9 +715,11 @@ def model_post_init(self, __context): | |
| f"but you set `trt_llm.build.base_model` to `decoder`. " | ||
| f"Please set it to `encoder_bert`." | ||
| ) | ||
| if ( | ||
| "ForCausalLM" in arch | ||
| and self.build.base_model != TrussTRTLLMModel.DECODER | ||
| if "ForCausalLM" in arch and self.build.base_model not in ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. puh, this is a hard one? Is that actually true? I forgot, but don't users need to convert models or do you wanna do it on startup? |
||
| TrussTRTLLMModel.DECODER, | ||
| # encoder_torch is the sanctioned way to serve a causal-arch checkpoint | ||
| # as an embedding/reranker via bidirectional-attention override in BEI-torch. | ||
| TrussTRTLLMModel.ENCODER_TORCH, | ||
| ): | ||
| logger.warning( | ||
| f"Your model architecture {arch} indicates a CausalLM based model. " | ||
|
|
@@ -889,7 +934,7 @@ def trt_llm_common_validation(config: "TrussConfig"): | |
| pass | ||
| else: | ||
| raise ValueError( | ||
| "TRT-LLM is not supported on CUDA_COMPUTE_75 (T4) and CUDA_COMPUTE_70 (V100) GPUs. \n" | ||
| "TRT-LLM and BEI-torch are not supported on CUDA_COMPUTE_75 (T4) and CUDA_COMPUTE_70 (V100) GPUs. \n" | ||
| "the lowest supported CUDA compute capability is CUDA_COMPUTE_80 (A100) or A10G (CUDA_COMPUTE_86)" | ||
| ) | ||
| elif trt_llm_config.build.quantization_type in [ | ||
|
|
@@ -947,6 +992,7 @@ def trt_llm_validation_v1(config: "TrussConfig") -> "TrussConfig": | |
| if trt_llm_config_v1.build.base_model not in [ | ||
| TrussTRTLLMModel.ENCODER, | ||
| TrussTRTLLMModel.ENCODER_BERT, | ||
| TrussTRTLLMModel.ENCODER_TORCH, | ||
| ]: | ||
| current_tags = config.model_metadata.get("tags", []) | ||
| if ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mhh, please remove this comment vLLM... internals