[Model] Add HrmTextForCausalLM (Hierarchical Reasoning Model — Text) (#43098)

Signed-off-by: Wuyifei <wuyifei@me.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
yifei wu
2026-06-16 22:41:41 +08:00
committed by GitHub
co-authored by Harry Mellor
parent 3d34f8cbdc
commit a52205bccf
8 changed files with 658 additions and 0 deletions
+22
View File
@@ -246,6 +246,28 @@ class EngineCore:
# Get all kv cache needed by the model
kv_cache_specs = self.model_executor.get_kv_cache_specs()
# Some layers (e.g. Prefix LM attention) run non-causally and tag their
# KV cache spec with ``non_causal=True``. The specs are collected here in
# the engine-core process (the same process that builds the scheduler),
# so this is the multiproc-safe place to translate that layer-level
# signal into a scheduling policy: chunked prefill and prefix caching
# both assume causal attention and would corrupt non-causal prefill.
if any(
getattr(spec, "non_causal", False)
for worker_specs in kv_cache_specs
for spec in worker_specs.values()
):
if vllm_config.scheduler_config.enable_chunked_prefill:
logger.info(
"Disabling chunked prefill: model has non-causal attention layers."
)
vllm_config.scheduler_config.enable_chunked_prefill = False
if vllm_config.cache_config.enable_prefix_caching:
logger.info(
"Disabling prefix caching: model has non-causal attention layers."
)
vllm_config.cache_config.enable_prefix_caching = False
has_kv_cache = any(kv_cache_spec for kv_cache_spec in kv_cache_specs)
if has_kv_cache:
if envs.VLLM_ELASTIC_EP_SCALE_UP_LAUNCH:
+13
View File
@@ -219,6 +219,15 @@ class FullAttentionSpec(AttentionSpec):
"""
attention_chunk_size: int | None = None
non_causal: bool = False
"""
Whether the layer attends non-causally (e.g. Prefix LM). Carried on the
spec so the engine core, which collects specs from all workers before the
scheduler is built, can adjust scheduling policy (chunked prefill / prefix
caching) regardless of tensor-parallel layout. It does not affect the KV
cache layout itself.
"""
def __post_init__(self):
if self.head_size_v is None:
object.__setattr__(self, "head_size_v", self.head_size)
@@ -276,6 +285,9 @@ class FullAttentionSpec(AttentionSpec):
page_size_padded=specs[0].page_size_padded,
sliding_window=cls.merge_window_sizes(sliding_window),
attention_chunk_size=cls.merge_window_sizes(attention_chunk_size),
# If any layer in the group is non-causal, treat the group as
# non-causal so the engine core disables incompatible scheduling.
non_causal=any(spec.non_causal for spec in specs),
)
for spec in specs:
for f in fields(AttentionSpec):
@@ -701,6 +713,7 @@ class SinkFullAttentionSpec(FullAttentionSpec):
page_size_padded=specs[0].page_size_padded,
sliding_window=cls.merge_window_sizes(sliding_window),
attention_chunk_size=cls.merge_window_sizes(attention_chunk_size),
non_causal=any(spec.non_causal for spec in specs),
)
for spec in specs:
for f in fields(AttentionSpec):