vllm.model_executor.models.longcat_flash_ngram
¶
Inference-only LongCat-Flash-Lite (n-gram embedding) model.
LongcatFlashNgramForCausalLM is LongCat-Flash (MLA dual-attention +
zero-expert MoE + YaRN) plus an n-gram embedding input layer: each position's
embedding fuses the token embedding with hashed embeddings of the preceding
n tokens. That per-request token history is isolated in a Model-Runner-V2
LongcatNgramModelState (mirroring DiffusionGemmaModelState), so
get_model_state_cls makes the model MRV2-only.
Classes:
-
FlashNgramModel–FlashModel whose input embedding is an
NgramEmbedding. -
LongcatFlashNgramForCausalLM–LongCat-Flash-Lite for causal LM (n-gram embedding).
-
LongcatNgramModelState– -
NgramEmbedding–Token embedding fused with hashed n-gram embeddings.
FlashNgramModel
¶
LongcatFlashNgramForCausalLM
¶
LongcatNgramModelState
¶
Bases: DefaultModelState
Attributes:
-
supports_prompt_embeds–Per-request n-gram token history for LongCat-Flash-Lite.
supports_prompt_embeds = False
class-attribute
instance-attribute
¶
Per-request n-gram token history for LongCat-Flash-Lite.
Maintains a small CPU-side per-slot context (last n-1 processed tokens)
and a persistent inputs_embeds buffer. prepare_inputs computes the
fused n-gram embedding per request into the buffer, handed to the model
forward as inputs_embeds.
_compute_oe_ids(input_batch)
¶
Batched global n-gram ids [num_tokens, num_embedders].
Assembles an ephemeral per-request token table ([n-1] context ++
current tokens, EOS-negated) and runs the ngram_compute_n_gram_ids
CUDA kernel for the whole batch, then rolls each slot's context forward.
NgramEmbedding
¶
Bases: Module
Token embedding fused with hashed n-gram embeddings.
TP-sharded: the k*(n-1) per-embedder tables are concatenated into one
VocabParallelEmbedding (oe_embedder) with per-embedder offsets,
and the projections are stacked into one oe_projection applied with a
single bmm. Hashing math is ported from the HF reference.
Methods:
-
embed_batched–Fused n-gram embedding for a flat batch given precomputed ids.
-
load_weight–Split a per-embedder checkpoint weight into the sharded layout.