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 :class:LongcatNgramModelState (mirroring DiffusionGemmaModelState), so get_model_state_cls makes the model MRV2-only.
Classes:
-
FlashNgramModel–FlashModel whose input embedding is an :class:
NgramEmbedding. -
LongcatFlashNgramForCausalLM–LongCat-Flash-Lite for causal LM (MRV2-only, n-gram embedding).
-
LongcatNgramModelState–Per-request n-gram token history for LongCat-Flash-Lite.
-
NgramEmbedding–Token embedding fused with hashed n-gram embeddings.
FlashNgramModel ¶
Bases: FlashModel
FlashModel whose input embedding is an :class:NgramEmbedding.
Source code in vllm/model_executor/models/longcat_flash_ngram.py
LongcatFlashNgramForCausalLM ¶
Bases: Module, SupportsLoRA, SupportsPP
LongCat-Flash-Lite for causal LM (MRV2-only, n-gram embedding).
Source code in vllm/model_executor/models/longcat_flash_ngram.py
LongcatNgramModelState ¶
Bases: DefaultModelState
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.
Source code in vllm/model_executor/models/longcat_flash_ngram.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
_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.
Source code in vllm/model_executor/models/longcat_flash_ngram.py
NgramEmbedding ¶
Bases: Module
Token embedding fused with hashed n-gram embeddings.
TP-sharded: the k*(n-1) per-embedder tables are concatenated into one :class: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.
Source code in vllm/model_executor/models/longcat_flash_ngram.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
embed_batched(input_ids, oe_ids) ¶
Fused n-gram embedding for a flat batch given precomputed ids.
Parameters:
-
(input_ids¶Tensor) –[num_tokens]current token per position. -
(oe_ids¶Tensor) –[num_tokens, num_embedders]global (offset) n-gram ids, as produced by thengram_compute_n_gram_idskernel.
Returns: [num_tokens, hidden].
Source code in vllm/model_executor/models/longcat_flash_ngram.py
load_weight(weight_name, loaded_weight) ¶
Split a per-embedder checkpoint weight into the sharded layout.
Returns the destination parameter's qualified name (relative to the enclosing model) so the caller can mark it loaded for completeness checks.