Repository navigation
Add LFM2.5 embedding model support - #28691
Merged
JustinTong0323 merged 7 commits intoJul 29, 2026
Merged
Conversation
Add native support for LiquidAI/LFM2.5-Embedding-350M by routing Lfm2BidirectionalModel through the prefill-only embedding path. The bidirectional variant uses encoder-only attention, non-causal same-padding short conv, CLS pooling, and L2 normalization. Keep Lfm2ForCausalLM.load_weights inline with the original conv renaming, QKV stacking, and tied lm_head handling. Lfm2BidirectionalModel uses the same conv/QKV loading shape without the tied lm_head path because the embedding checkpoint has no lm_head. Register Lfm2BidirectionalModel as non-generation so /v1/embeddings works without --is-embedding on FlashInfer. Validation: - PYTHONPATH=python python -m py_compile python/sglang/srt/models/lfm2.py python/sglang/srt/configs/model_config.py - PYTHONPATH=python python - <<'PY' from sglang.srt.configs.model_config import is_generation_model from sglang.srt.models.registry import ModelRegistry print(is_generation_model(['Lfm2BidirectionalModel'])) model_cls, arch = ModelRegistry.resolve_model_cls(['Lfm2BidirectionalModel']) print(arch, model_cls.__name__) PY False Lfm2BidirectionalModel Lfm2BidirectionalModel - PYTHONPATH=python python scratch/lfm25_embed_validation/sglang_backend_cosine.py --backends flashinfer --launch-preset default --base-port 32171 --results-file scratch/lfm25_embed_validation/sglang_flashinfer_default_after_simplify_results.json top_docs=[0, 1], query_pair_cosine=[0.9999523, 0.9999496], document_pair_cosine=[0.9999526, 0.9999406, 0.9999533], score_max_abs_diff_vs_reference=0.0013513 server_args included is_embedding=False, disable_radix_cache=False, chunked_prefill_size=16384, attention_backend='flashinfer'.
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Contributor
Author
|
/tag-and-rerun-ci |
Contributor
Author
|
/tag-and-rerun-ci |
JustinTong0323
approved these changes
Jul 2, 2026
JustinTong0323
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, very clean
JustinTong0323
enabled auto-merge (squash)
July 2, 2026 09:15
Contributor
Author
|
/tag-and-rerun-ci |
Contributor
|
@JustinTong0323 could we merge it now? |
Contributor
Author
|
/tag-and-rerun-ci |
saturn-acc
pushed a commit
to saturn-acc/sglang
that referenced
this pull request
Aug 16, 2026
Atituiset
pushed a commit
to Atituiset/sglang
that referenced
this pull request
Sep 10, 2026
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LiquidAI/LFM2.5-Embedding-350Mby routingLfm2BidirectionalModelthrough SGLang's prefill-only embedding path.Lfm2BidirectionalModelas non-generation so/v1/embeddingsworks without--is-embeddingon FlashInfer.How To Run
The model is auto-detected as an embedding model from its architecture, so
--is-embeddingis not required.Motivation
LiquidAI/LFM2.5-Embedding-350Mis a dense bi-encoder built from the LFM2.5 bidirectional architecture. The Hugging Face checkpoint exposesLfm2BidirectionalModel, but SGLang previously only had the causal LFM2 path. This PR adds the minimum model-side support needed for/v1/embeddingsto return the model's CLS-pooled, normalized vectors through the existing prefill-only embedding flow.Modifications
Lfm2BidirectionalModelinpython/sglang/srt/models/lfm2.py.AttentionType.ENCODER_ONLYfor the bidirectional embedding architecture.Lfm2ForCausalLM.load_weightsremains inline with the original conv renaming, QKV stacking, and tiedlm_headhandling."Lfm2BidirectionalModel"to the non-generation architecture set inis_generation_model.Accuracy Tests
Compile and registry checks:
Output:
FlashInfer default serving check against the PyLate/SentenceTransformers reference:
Results:
The default server path was confirmed in the log:
Note: SGLang's prefill path is packed/unpadded. The HF remote model comments describe FlashAttention-2 behavior as equivalent to the unpadded forward, while eager/sdpa preserves padded training-time behavior. For that reason the vector-level serving check asserts against the unpadded PyLate/SentenceTransformers reference.
Speed Tests and Profiling
No dedicated speed benchmark in this PR. The validation above exercises the default FlashInfer serving path with one 96-item embeddings request.
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ⏳ Run #30426507975
Latest PR Test (Extra): ❌ Run #30426507842