Repository navigation
Conversation
This was referenced Sep 29, 2026
|
Is this PR going to get merged at some point, it seems like a small change 🙂 |
For hrm-text models with prefix_lm set, the KQ mask drops the causal check, so the prompt attends in both directions and generated tokens stay causal. decode warns when a prompt is split across ubatches, and llama-server disables prompt caching for these models. Adds a test-llama-archs check for the mask.
bolgacg
force-pushed
the
hrm-text-prefix-lm-upstream
branch
from
November 13, 2026 20:15
bda5dcd to
0f460f6
Compare
Author
|
Thanks @LarsVonQualen. I rebased the branch onto current master and resolved the conflicts in @CISC, could you take a look when you have time? |
This branch has not been deployed
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.
Overview
HRM-Text models (DFM Mimir) are trained as prefix LMs: prompt tokens attend to each other in both
directions and only generated tokens are causal. Master reads
prefix_lmintohparams.hrm_prefix_lmsince #27625 but still builds a causal mask, so Mimir runs in a mode it was not trained for.
For these models
set_input_kq_maskdrops the causal check, so a token attends to every token ofits own sequence in the cache or the current ubatch. Generation appends one token per sequence per
step, so generated tokens still see only the past. This reproduces the training mask. Two guards:
llama_context::decodewarns when a prompt is split across ubatches (tokens in different ubatchescannot see each other; use
-ubat least the longest prompt).llama-serverturns off prompt caching for these models, because a cached prefix was computedwithout the tokens that followed it. It reads the flag from the model metadata, so there is no new
public API.
Additional information
Checked on DAISY (592 Danish questions from the model's own group) with a Q8_0 GGUF converted by
master's own converter from the official DFM-Mimir weights, greedy,
--reasoning off,-ub 2048:With one Wikipedia passage in the prompt (about 1,000 tokens) the PR build scores 65.9.
Test:
test-llama-archs -a hrm_textgains a check that the first token's logits change when thelast prompt token changes with
prefix_lmset, and stay the same without it. It fails on masterand passes with this PR.
Other models are unaffected. Llama-3.2-1B Q8_0 on a GTX 1060: perplexity on wikitext-2 (40 chunks)
is 14.3649 on both builds; llama-bench pp512 2380 vs 2381 t/s and tg128 90.3 vs 90.7 t/s
(PR vs master, means of the last two of three alternating runs).
History: first opened as noctrex#1 on 6 Sep; @noctrex named it the prefix-LM follow-up on
8 Sep in #27625. @peter-sk has a fuller implementation in schneiderkamplab/llama.cpp (an explicit
llama_decode_prefixAPI, parallel sequences, prefix caching). This PR is only the mask, so thatwork can build on it in later PRs.
Not covered: speculative decoding, parallel slots sharing one ubatch, prompt caching for these models.
Requirements