transformers - 💡(How to fix) Fix [DeepSeekV4] Compressor does not seem to account for padding tokens when forming compressed KV blocks [4 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#45938Fetched 2026-05-14 03:28:40
View on GitHub
Comments
4
Participants
2
Timeline
9
Reactions
0
Author
Timeline (top)
commented ×4mentioned ×2subscribed ×2cross-referenced ×1

I noticed a potential padding-related issue in the current DeepSeekV4 implementation.

The sliding-window attention path appears to correctly receive the user-provided attention_mask through create_sliding_window_causal_mask, so padded key/value tokens can be masked out in the normal attention path.

However, the HCA / CSA compressor path seems to form compressed KV entries from the projected kv / gate tensors without using the input attention_mask.

From my reading, the compressor first projects hidden states into kv and gate, then stores/chunks them through the cache layer, and finally performs softmax-gated pooling to produce compressed KV entries. This means padding tokens may still participate in compressed KV construction.

For example, with right padding:

attention_mask = [1, 1, 1, 0]
compress_rate = 4

the compressor may form one compressed block from:

[token_0, token_1, token_2, pad]

Even though the pad token is masked in the normal sliding-window attention mask, it may still contribute to the compressed KV entry.

Root Cause

I noticed a potential padding-related issue in the current DeepSeekV4 implementation.

The sliding-window attention path appears to correctly receive the user-provided attention_mask through create_sliding_window_causal_mask, so padded key/value tokens can be masked out in the normal attention path.

However, the HCA / CSA compressor path seems to form compressed KV entries from the projected kv / gate tensors without using the input attention_mask.

From my reading, the compressor first projects hidden states into kv and gate, then stores/chunks them through the cache layer, and finally performs softmax-gated pooling to produce compressed KV entries. This means padding tokens may still participate in compressed KV construction.

For example, with right padding:

attention_mask = [1, 1, 1, 0]
compress_rate = 4

the compressor may form one compressed block from:

[token_0, token_1, token_2, pad]

Even though the pad token is masked in the normal sliding-window attention mask, it may still contribute to the compressed KV entry.

Code Example

attention_mask = [1, 1, 1, 0]
compress_rate = 4

---

[token_0, token_1, token_2, pad]
RAW_BUFFERClick to expand / collapse

Description

I noticed a potential padding-related issue in the current DeepSeekV4 implementation.

The sliding-window attention path appears to correctly receive the user-provided attention_mask through create_sliding_window_causal_mask, so padded key/value tokens can be masked out in the normal attention path.

However, the HCA / CSA compressor path seems to form compressed KV entries from the projected kv / gate tensors without using the input attention_mask.

From my reading, the compressor first projects hidden states into kv and gate, then stores/chunks them through the cache layer, and finally performs softmax-gated pooling to produce compressed KV entries. This means padding tokens may still participate in compressed KV construction.

For example, with right padding:

attention_mask = [1, 1, 1, 0]
compress_rate = 4

the compressor may form one compressed block from:

[token_0, token_1, token_2, pad]

Even though the pad token is masked in the normal sliding-window attention mask, it may still contribute to the compressed KV entry.

Question

If padding is intended to be supported, should the compressor receive attention_mask and use it when forming compressed KV blocks?

Thanks!

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - 💡(How to fix) Fix [DeepSeekV4] Compressor does not seem to account for padding tokens when forming compressed KV blocks [4 comments, 2 participants]