Skip to content

Use one beta per head in the Gated DeltaNet code - #1119

Open
Medamineelkhattabi wants to merge 1 commit into
rasbt:mainfrom
Medamineelkhattabi:deltanet-beta-per-head
Open

Medamineelkhattabi wants to merge 1 commit into
rasbt:mainfrom
Medamineelkhattabi:deltanet-beta-per-head

Conversation

@Medamineelkhattabi

Copy link
Copy Markdown

Follow-up to #1115.

In the GatedDeltaNet code in ch04/08_deltanet/README.md, W_beta maps to d_out, so the write strength β is computed per channel. Qwen3-Next and the Gated DeltaNet paper use one β per head (in_proj_b outputs num_v_heads, then beta = b.sigmoid() in modeling_qwen3_5.py).

This changes W_beta to nn.Linear(d_in, num_heads) and keeps β as (b, num_tokens, num_heads, 1), so delta = (v_t - kv_mem) * b_t broadcasts over the head dimension. The recurrence loop and the snippet further down the README are unchanged.

I checked it by running the README class and comparing its recurrence with HF's torch_recurrent_gated_delta_rule on random inputs (same q, k, v, decay and β): max abs difference 3.7e-9. With the previous per-channel β the two can't be compared directly, since the shapes differ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant