[Model] Support Qwen3.8-Flash-Next (#53896)
Signed-off-by: huanghaoyan.hhy <huanghaoyan.hhy@alibaba-inc.com> Signed-off-by: andyluo7 <andy.luo@amd.com> Signed-off-by: lishunyang12 <lishunyang03@gmail.com> Signed-off-by: Harry Huang <huanghaoyan.hhy@alibaba-inc.com> Signed-off-by: Thien Tran <gau.nernst@yahoo.com.sg> Signed-off-by: Isotr0py <Isotr0py@outlook.com> Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com> Signed-off-by: Yifan Qiao <yifanqiao@inferact.ai> Signed-off-by: zjy0516 <riverclouds.zhu@qq.com> Co-authored-by: zjy0516 <riverclouds.zhu@qq.com> Co-authored-by: KungYork <firelikest@163.com> Co-authored-by: Thien Tran <gau.nernst@yahoo.com.sg> Co-authored-by: Yifan Qiao <yifanqiao@inferact.ai> Co-authored-by: andyluo7 <43718156+andyluo7@users.noreply.github.com> Co-authored-by: Isotr0py <mozf@inferact.ai> Co-authored-by: andyluo7 <andy.luo@amd.com> Co-authored-by: OpenAI Codex <noreply@openai.com> Co-authored-by: lishunyang12 <lishunyang03@gmail.com> Co-authored-by: Vadim Gimpelson <156319763+vadiklyutiy@users.noreply.github.com> Co-authored-by: Isotr0py <Isotr0py@outlook.com> Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
co-authored by
zjy0516
KungYork
Thien Tran
Yifan Qiao
andyluo7
Isotr0py
andyluo7
OpenAI Codex
lishunyang12
Vadim Gimpelson
Isotr0py
Lucas Wilkinson
Claude Opus 5
OpenAI Codex
parent
687db59744
commit
e126687a9a
@@ -104,6 +104,47 @@ def _make_speculator(
|
||||
return speculator
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("hc_mult", "expected"), [(None, 64), (4, 256)])
|
||||
def test_speculator_uses_draft_model_hidden_size(monkeypatch, hc_mult, expected):
|
||||
# Qwen4Exp targets expose multi-stream HC residuals to the drafter.
|
||||
monkeypatch.setattr(base_spec_module, "_target_feeds_hc_residual", lambda _: True)
|
||||
hf_config = SimpleNamespace()
|
||||
if hc_mult is not None:
|
||||
hf_config.hc_mult = hc_mult
|
||||
draft_model_config = SimpleNamespace(
|
||||
hf_config=hf_config,
|
||||
get_hidden_size=lambda: 64,
|
||||
get_vocab_size=lambda: 32,
|
||||
)
|
||||
speculative_config = SimpleNamespace(
|
||||
method="mtp",
|
||||
num_speculative_tokens=3,
|
||||
draft_model_config=draft_model_config,
|
||||
use_local_argmax_reduction=False,
|
||||
draft_sample_method="greedy",
|
||||
)
|
||||
vllm_config = SimpleNamespace(
|
||||
speculative_config=speculative_config,
|
||||
scheduler_config=SimpleNamespace(
|
||||
max_num_seqs=2,
|
||||
max_num_batched_tokens=8,
|
||||
),
|
||||
model_config=SimpleNamespace(
|
||||
max_model_len=32,
|
||||
dtype=torch.float32,
|
||||
use_fp64_gumbel=False,
|
||||
),
|
||||
parallel_config=SimpleNamespace(
|
||||
data_parallel_size=1,
|
||||
data_parallel_rank=0,
|
||||
),
|
||||
)
|
||||
|
||||
speculator = _TestSpeculator(vllm_config, torch.device("cpu"))
|
||||
|
||||
assert speculator.hidden_size == expected
|
||||
|
||||
|
||||
def test_mm_support_configured_after_model_load(monkeypatch):
|
||||
target_model_config = object()
|
||||
draft_model_config = object()
|
||||
@@ -197,9 +238,11 @@ def test_load_model_disables_mm_support_for_text_only_drafter(monkeypatch):
|
||||
|
||||
assert not speculator.supports_mm_inputs
|
||||
assert warning_messages == [
|
||||
"Draft model _TextOnlyDraftModel does not support external multimodal "
|
||||
"embeddings. Embeddings from the target model will not be passed to the "
|
||||
"drafter; using text-only draft inputs instead."
|
||||
(
|
||||
"Draft model _TextOnlyDraftModel does not support external multimodal "
|
||||
"embeddings. Embeddings from the target model will not be passed to the "
|
||||
"drafter; using text-only draft inputs instead."
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -132,6 +132,42 @@ def test_block_tables_apply_staged_writes_single_group():
|
||||
)
|
||||
|
||||
|
||||
def test_block_tables_skip_custom_slot_mapping_groups():
|
||||
device = torch.device("cuda")
|
||||
block_tables = BlockTables(
|
||||
block_sizes=[8, 262144],
|
||||
max_num_reqs=1,
|
||||
max_num_batched_tokens=4,
|
||||
max_num_blocks_per_group=[1, 1],
|
||||
device=device,
|
||||
kernel_block_sizes=[8, 262144],
|
||||
slot_mapping_enabled=[False, True],
|
||||
)
|
||||
block_tables.append_block_ids(
|
||||
req_index=0,
|
||||
new_block_ids=([7], [12]),
|
||||
overwrite=True,
|
||||
)
|
||||
block_tables.apply_staged_writes()
|
||||
|
||||
idx_mapping = torch.tensor([0], dtype=torch.int32, device=device)
|
||||
query_start_loc = torch.tensor([0, 2], dtype=torch.int32, device=device)
|
||||
positions = torch.tensor([153797, 165757], dtype=torch.int64, device=device)
|
||||
slot_mappings = block_tables.compute_slot_mappings(
|
||||
idx_mapping,
|
||||
query_start_loc,
|
||||
positions,
|
||||
num_tokens_padded=2,
|
||||
)
|
||||
torch.accelerator.synchronize()
|
||||
|
||||
assert slot_mappings[0].tolist() == [-1, -1]
|
||||
assert slot_mappings[1].tolist() == [
|
||||
12 * 262144 + 153797,
|
||||
12 * 262144 + 165757,
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("cp_rank", range(4))
|
||||
def test_dcp_slot_mapping_with_smaller_kernel_blocks(cp_rank: int):
|
||||
"""DCP interleave is expressed in logical-block token coordinates."""
|
||||
|
||||
@@ -8,15 +8,107 @@ import torch
|
||||
|
||||
import vllm.v1.worker.gpu.model_runner as model_runner_module
|
||||
from vllm.v1.kv_cache_interface import (
|
||||
CircularBufferSpec,
|
||||
FullAttentionSpec,
|
||||
KVCacheConfig,
|
||||
KVCacheGroupSpec,
|
||||
MambaSpec,
|
||||
UniformTypeKVCacheSpecs,
|
||||
)
|
||||
from vllm.v1.worker.gpu.block_table import BlockTables
|
||||
from vllm.v1.worker.gpu.model_runner import GPUModelRunner
|
||||
|
||||
|
||||
def test_qsa_circular_group_uses_custom_slot_mapping(monkeypatch):
|
||||
runner = GPUModelRunner.__new__(GPUModelRunner)
|
||||
runner.max_model_len = 262144
|
||||
runner.is_encoder_decoder = False
|
||||
runner.dcp_size = 1
|
||||
runner.dcp_rank = 0
|
||||
runner.cp_interleave = 1
|
||||
runner.cache_config = SimpleNamespace(enable_prefix_caching=True)
|
||||
parallel_config = SimpleNamespace(
|
||||
decode_context_parallel_size=1,
|
||||
cp_kv_cache_interleave_size=1,
|
||||
)
|
||||
runner.parallel_config = parallel_config
|
||||
runner.vllm_config = SimpleNamespace(
|
||||
parallel_config=parallel_config,
|
||||
cache_config=SimpleNamespace(mamba_cache_mode="none"),
|
||||
)
|
||||
runner.model_state = SimpleNamespace(
|
||||
get_additional_cg_support=lambda: (),
|
||||
num_new_sampled_tokens_per_step=1,
|
||||
)
|
||||
runner.speculator = None
|
||||
runner.req_states = []
|
||||
runner.input_buffers = SimpleNamespace(query_start_loc=None)
|
||||
runner.vocab_size = 1
|
||||
runner.max_num_reqs = 1
|
||||
runner.max_num_tokens = 2
|
||||
runner.device = torch.device("cuda")
|
||||
|
||||
raw_spec = CircularBufferSpec(
|
||||
block_size=8,
|
||||
num_kv_heads=1,
|
||||
head_size=128,
|
||||
dtype=torch.bfloat16,
|
||||
)
|
||||
compressed_spec = FullAttentionSpec(
|
||||
block_size=262144,
|
||||
num_kv_heads=1,
|
||||
head_size=128,
|
||||
dtype=torch.bfloat16,
|
||||
)
|
||||
kv_cache_config = KVCacheConfig(
|
||||
num_blocks=1,
|
||||
kv_cache_tensors=[],
|
||||
kv_cache_groups=[
|
||||
KVCacheGroupSpec(
|
||||
layer_names=["raw"],
|
||||
kv_cache_spec=UniformTypeKVCacheSpecs(
|
||||
block_size=8,
|
||||
kv_cache_specs={"raw": raw_spec},
|
||||
),
|
||||
),
|
||||
KVCacheGroupSpec(layer_names=["compressed"], kv_cache_spec=compressed_spec),
|
||||
],
|
||||
)
|
||||
|
||||
class FakeAttnCGSupport:
|
||||
def narrow(self, *args):
|
||||
return self
|
||||
|
||||
attn_cg_support = FakeAttnCGSupport()
|
||||
monkeypatch.setattr(
|
||||
model_runner_module,
|
||||
"init_attn_backend",
|
||||
lambda *args: ([], attn_cg_support, [8, 262144]),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
model_runner_module,
|
||||
"maybe_create_adaptive_verification_manager",
|
||||
lambda **kwargs: None,
|
||||
)
|
||||
|
||||
captured = {}
|
||||
|
||||
class BlockTablesCaptured(Exception):
|
||||
pass
|
||||
|
||||
def capture_block_tables(**kwargs):
|
||||
captured.update(kwargs)
|
||||
raise BlockTablesCaptured
|
||||
|
||||
monkeypatch.setattr(model_runner_module, "BlockTables", capture_block_tables)
|
||||
|
||||
with pytest.raises(BlockTablesCaptured):
|
||||
runner.initialize_kv_cache(kv_cache_config)
|
||||
|
||||
assert captured["max_num_blocks_per_group"] == [1, 1]
|
||||
assert captured["slot_mapping_enabled"] == [False, True]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("mamba_cache_mode", "num_speculative_blocks", "expected"),
|
||||
[
|
||||
|
||||
@@ -20,6 +20,7 @@ from vllm.config.vllm import VllmConfig
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.math_utils import cdiv
|
||||
from vllm.v1.kv_cache_interface import (
|
||||
CircularBufferSpec,
|
||||
FullAttentionSpec,
|
||||
KVCacheConfig,
|
||||
KVCacheGroupSpec,
|
||||
@@ -53,6 +54,18 @@ def _attention_group() -> KVCacheGroupSpec:
|
||||
)
|
||||
|
||||
|
||||
def _circular_group() -> KVCacheGroupSpec:
|
||||
return KVCacheGroupSpec(
|
||||
["circular"],
|
||||
CircularBufferSpec(
|
||||
block_size=BLOCK_SIZE,
|
||||
num_kv_heads=1,
|
||||
head_size=1,
|
||||
dtype=torch.float32,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _mamba_group(mamba_cache_mode: str) -> KVCacheGroupSpec:
|
||||
# Name carries the mode so several groups can coexist in one config.
|
||||
return KVCacheGroupSpec(
|
||||
@@ -212,8 +225,7 @@ def test_warmup_reserves_mamba_speculative_blocks(mamba_cache_mode):
|
||||
|
||||
|
||||
def _hybrid_kv_cache_config(num_blocks: int) -> KVCacheConfig:
|
||||
"""Full attention plus one Mamba group per cache mode, so a single manager
|
||||
exercises every branch `_reserved_block_count` has.
|
||||
"""Attention, circular, and Mamba groups exercise every reservation branch.
|
||||
|
||||
"none" and "all" reach the same branch of both `_reserved_block_count` and
|
||||
`MambaManager`, which tests only for "align". They are still both listed:
|
||||
@@ -226,6 +238,7 @@ def _hybrid_kv_cache_config(num_blocks: int) -> KVCacheConfig:
|
||||
kv_cache_tensors=[],
|
||||
kv_cache_groups=[
|
||||
_attention_group(),
|
||||
_circular_group(),
|
||||
_mamba_group("none"),
|
||||
_mamba_group("all"),
|
||||
_mamba_group("align"),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
@@ -10,11 +9,20 @@ import pytest
|
||||
import torch
|
||||
|
||||
from vllm.model_executor.layers.mamba.mamba_utils import (
|
||||
MambaStateCopyFunc,
|
||||
MambaStateCopyFuncsByType,
|
||||
get_conv_copy_spec,
|
||||
get_temporal_copy_spec,
|
||||
)
|
||||
from vllm.v1.attention.backends.registry import MambaAttentionBackendEnum
|
||||
from vllm.v1.core.sched.output import CachedRequestData, SchedulerOutput
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig, KVCacheGroupSpec, MambaSpec
|
||||
from vllm.v1.kv_cache_interface import (
|
||||
KVCacheConfig,
|
||||
KVCacheGroupSpec,
|
||||
MambaSpec,
|
||||
UniformTypeKVCacheSpecs,
|
||||
)
|
||||
from vllm.v1.worker.gpu.model_states.mamba_hybrid import MambaHybridModelState
|
||||
from vllm.v1.worker.mamba_utils import (
|
||||
MambaCopyBuffers,
|
||||
MambaSpecDecodeGPUContext,
|
||||
@@ -22,17 +30,21 @@ from vllm.v1.worker.mamba_utils import (
|
||||
batch_memcpy,
|
||||
collect_mamba_copy_meta,
|
||||
do_mamba_copy_block,
|
||||
get_mamba_groups,
|
||||
preprocess_mamba,
|
||||
stage_postprocess_inputs_to_gpu,
|
||||
)
|
||||
|
||||
MambaStateCopyFunc = Callable[..., Any]
|
||||
|
||||
# Conv + temporal copy specs, in the order the tests' MambaSpec shapes expect.
|
||||
_COPY_FUNCS: tuple[MambaStateCopyFunc, ...] = (
|
||||
_DEFAULT_COPY_FUNCS: tuple[MambaStateCopyFunc, ...] = (
|
||||
get_conv_copy_spec,
|
||||
get_temporal_copy_spec,
|
||||
)
|
||||
_COPY_FUNCS: MambaStateCopyFuncsByType = {
|
||||
MambaAttentionBackendEnum.MAMBA2: _DEFAULT_COPY_FUNCS,
|
||||
MambaAttentionBackendEnum.GDN_ATTN: _DEFAULT_COPY_FUNCS,
|
||||
MambaAttentionBackendEnum.SHORT_CONV: (get_conv_copy_spec,),
|
||||
}
|
||||
|
||||
|
||||
def postprocess_mamba(
|
||||
@@ -41,7 +53,7 @@ def postprocess_mamba(
|
||||
input_batch: Any,
|
||||
requests: dict[str, Any],
|
||||
forward_context: dict[str, Any],
|
||||
mamba_state_copy_funcs: tuple[MambaStateCopyFunc, ...],
|
||||
mamba_state_copy_funcs: MambaStateCopyFuncsByType,
|
||||
copy_bufs: "MambaCopyBuffers",
|
||||
):
|
||||
"""CPU reference for the align-mode postprocess.
|
||||
@@ -147,7 +159,7 @@ def test_resumed_req_ids_cleared_from_mamba_state_idx():
|
||||
input_batch,
|
||||
{}, # requests
|
||||
{}, # forward_context
|
||||
(), # mamba_state_copy_funcs
|
||||
{}, # mamba_state_copy_funcs
|
||||
copy_bufs,
|
||||
)
|
||||
|
||||
@@ -430,7 +442,10 @@ def _make_requests(
|
||||
|
||||
|
||||
def _make_copy_bufs(
|
||||
cfg: _TestConfig, kv_cache_config: KVCacheConfig, device: torch.device
|
||||
cfg: _TestConfig,
|
||||
kv_cache_config: KVCacheConfig,
|
||||
device: torch.device,
|
||||
copy_funcs: MambaStateCopyFuncsByType = _COPY_FUNCS,
|
||||
) -> MambaCopyBuffers:
|
||||
"""Create MambaCopyBuffers for the Python path."""
|
||||
|
||||
@@ -440,13 +455,16 @@ def _make_copy_bufs(
|
||||
return MambaCopyBuffers.create(
|
||||
max_num_reqs=cfg.max_num_reqs,
|
||||
kv_cache_config=kv_cache_config,
|
||||
copy_funcs=(get_conv_copy_spec, get_temporal_copy_spec),
|
||||
copy_funcs=copy_funcs,
|
||||
make_buffer=make_buffer,
|
||||
)
|
||||
|
||||
|
||||
def _make_gpu_ctx(
|
||||
cfg: _TestConfig, kv_cache_config: KVCacheConfig, device: torch.device
|
||||
cfg: _TestConfig,
|
||||
kv_cache_config: KVCacheConfig,
|
||||
device: torch.device,
|
||||
copy_funcs: MambaStateCopyFuncsByType = _COPY_FUNCS,
|
||||
) -> MambaSpecDecodeGPUContext:
|
||||
"""Create MambaSpecDecodeGPUContext for the GPU path."""
|
||||
|
||||
@@ -456,12 +474,170 @@ def _make_gpu_ctx(
|
||||
return MambaSpecDecodeGPUContext.create(
|
||||
max_num_reqs=cfg.max_num_reqs,
|
||||
kv_cache_config=kv_cache_config,
|
||||
num_state_types=2,
|
||||
copy_funcs=copy_funcs,
|
||||
device=device,
|
||||
make_buffer=make_buffer,
|
||||
)
|
||||
|
||||
|
||||
def test_mamba_groups_support_different_state_specs():
|
||||
gdn_spec = MambaSpec(
|
||||
block_size=16,
|
||||
shapes=((4, 4), (2, 4, 4)),
|
||||
dtypes=(torch.float16, torch.float32),
|
||||
mamba_type=MambaAttentionBackendEnum.GDN_ATTN,
|
||||
mamba_cache_mode="align",
|
||||
num_speculative_blocks=3,
|
||||
)
|
||||
short_conv_spec = MambaSpec(
|
||||
block_size=16,
|
||||
shapes=((12, 8),),
|
||||
dtypes=(torch.float16,),
|
||||
mamba_type=MambaAttentionBackendEnum.SHORT_CONV,
|
||||
mamba_cache_mode="align",
|
||||
num_speculative_blocks=3,
|
||||
)
|
||||
kv_cache_config = KVCacheConfig(
|
||||
num_blocks=8,
|
||||
kv_cache_tensors=[],
|
||||
kv_cache_groups=[
|
||||
KVCacheGroupSpec(["gdn.0", "gdn.1"], gdn_spec),
|
||||
KVCacheGroupSpec(["ple.0"], short_conv_spec),
|
||||
],
|
||||
)
|
||||
|
||||
mamba_groups = get_mamba_groups(kv_cache_config)
|
||||
assert mamba_groups == {gdn_spec: [0], short_conv_spec: [1]}
|
||||
|
||||
model_state = object.__new__(MambaHybridModelState)
|
||||
model_state._mamba_group_ids = []
|
||||
model_state._mamba_spec = None
|
||||
group_ids, representative_spec = model_state._get_mamba_group_info(kv_cache_config)
|
||||
assert group_ids == [0, 1]
|
||||
assert representative_spec is gdn_spec
|
||||
|
||||
cfg = _TestConfig()
|
||||
copy_bufs = _make_copy_bufs(cfg, kv_cache_config, torch.device("cpu"))
|
||||
assert copy_bufs.src_ptrs.cpu.numel() == cfg.max_num_reqs * 5
|
||||
assert copy_bufs.dst_ptrs.cpu.numel() == cfg.max_num_reqs * 5
|
||||
assert copy_bufs.sizes.cpu.numel() == cfg.max_num_reqs * 5
|
||||
|
||||
ctx = _make_gpu_ctx(cfg, kv_cache_config, torch.device("cpu"))
|
||||
assert ctx.num_states == 5
|
||||
|
||||
forward_context = {}
|
||||
gdn_spec_layer_names = ["gdn.0", "gdn.1"]
|
||||
for layer_name in gdn_spec_layer_names:
|
||||
attention = MagicMock()
|
||||
attention.kv_cache = (
|
||||
torch.empty(8, 4, 4, dtype=torch.float16),
|
||||
torch.empty(8, 2, 4, 4, dtype=torch.float32),
|
||||
)
|
||||
forward_context[layer_name] = attention
|
||||
ple_attention = MagicMock()
|
||||
ple_attention.kv_cache = (torch.empty(8, 12, 8, dtype=torch.float16),)
|
||||
forward_context["ple.0"] = ple_attention
|
||||
assert gdn_spec_layer_names == kv_cache_config.kv_cache_groups[0].layer_names
|
||||
|
||||
block_tables = [
|
||||
torch.zeros(4, 8, dtype=torch.int32),
|
||||
torch.zeros(4, 8, dtype=torch.int32),
|
||||
]
|
||||
ctx.initialize_from_forward_context(
|
||||
kv_cache_config,
|
||||
forward_context,
|
||||
_COPY_FUNCS,
|
||||
block_tables,
|
||||
)
|
||||
assert ctx.is_initialized
|
||||
assert ctx.state_group_indices.tolist() == [0, 0, 0, 0, 1]
|
||||
assert ctx.state_conv_widths.tolist() == [4, 0, 4, 0, 12]
|
||||
|
||||
|
||||
def test_mamba_groups_support_mixed_specs_in_uniform_group():
|
||||
gdn_spec = MambaSpec(
|
||||
block_size=16,
|
||||
shapes=((4, 4), (2, 4, 4)),
|
||||
dtypes=(torch.float16, torch.float32),
|
||||
mamba_type=MambaAttentionBackendEnum.GDN_ATTN,
|
||||
mamba_cache_mode="align",
|
||||
num_speculative_blocks=3,
|
||||
)
|
||||
short_conv_spec = MambaSpec(
|
||||
block_size=16,
|
||||
shapes=((12, 8),),
|
||||
dtypes=(torch.float16,),
|
||||
mamba_type=MambaAttentionBackendEnum.SHORT_CONV,
|
||||
mamba_cache_mode="align",
|
||||
num_speculative_blocks=3,
|
||||
)
|
||||
layer_specs = {
|
||||
"gdn.0": gdn_spec,
|
||||
"gdn.1": gdn_spec,
|
||||
"ple.0": short_conv_spec,
|
||||
}
|
||||
kv_cache_config = KVCacheConfig(
|
||||
num_blocks=8,
|
||||
kv_cache_tensors=[],
|
||||
kv_cache_groups=[
|
||||
KVCacheGroupSpec(
|
||||
list(layer_specs),
|
||||
UniformTypeKVCacheSpecs(
|
||||
block_size=16,
|
||||
kv_cache_specs=layer_specs,
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
assert kv_cache_config.has_mamba_layers
|
||||
assert get_mamba_groups(kv_cache_config) == {
|
||||
gdn_spec: [0],
|
||||
short_conv_spec: [0],
|
||||
}
|
||||
|
||||
# The group is listed once per spec, so its id must not be repeated.
|
||||
model_state = object.__new__(MambaHybridModelState)
|
||||
model_state._mamba_group_ids = []
|
||||
model_state._mamba_spec = None
|
||||
group_ids, representative_spec = model_state._get_mamba_group_info(kv_cache_config)
|
||||
assert group_ids == [0]
|
||||
assert representative_spec is gdn_spec
|
||||
|
||||
cfg = _TestConfig()
|
||||
copy_bufs = _make_copy_bufs(cfg, kv_cache_config, torch.device("cpu"))
|
||||
assert copy_bufs.mamba_group_ids == [0]
|
||||
assert copy_bufs.src_ptrs.cpu.numel() == cfg.max_num_reqs * 5
|
||||
|
||||
ctx = _make_gpu_ctx(cfg, kv_cache_config, torch.device("cpu"))
|
||||
assert ctx.mamba_group_ids == [0]
|
||||
assert ctx.num_states == 5
|
||||
|
||||
forward_context = {
|
||||
"gdn.0": MagicMock(
|
||||
kv_cache=(
|
||||
torch.empty(8, 4, 4, dtype=torch.float16),
|
||||
torch.empty(8, 2, 4, 4, dtype=torch.float32),
|
||||
)
|
||||
),
|
||||
"gdn.1": MagicMock(
|
||||
kv_cache=(
|
||||
torch.empty(8, 4, 4, dtype=torch.float16),
|
||||
torch.empty(8, 2, 4, 4, dtype=torch.float32),
|
||||
)
|
||||
),
|
||||
"ple.0": MagicMock(kv_cache=(torch.empty(8, 12, 8, dtype=torch.float16),)),
|
||||
}
|
||||
ctx.initialize_from_forward_context(
|
||||
kv_cache_config,
|
||||
forward_context,
|
||||
_COPY_FUNCS,
|
||||
[torch.zeros(4, 8, dtype=torch.int32)],
|
||||
)
|
||||
assert ctx.state_group_indices.tolist() == [0, 0, 0, 0, 0]
|
||||
assert ctx.state_conv_widths.tolist() == [4, 0, 4, 0, 12]
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# stage_postprocess_inputs_to_gpu: single-pass staging into pinned views
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -620,7 +796,7 @@ def _run_gpu_postprocess(
|
||||
*,
|
||||
kv_cache_config: KVCacheConfig,
|
||||
forward_context: dict[str, Any],
|
||||
copy_funcs: tuple,
|
||||
copy_funcs: MambaStateCopyFuncsByType,
|
||||
block_table: torch.Tensor,
|
||||
req_ids: list[str],
|
||||
num_accepted_tokens: list[int],
|
||||
|
||||
Reference in New Issue
Block a user