Repository navigation
inkling2: skip redundant softcap before argmax in lm_head_argmax - #75
Conversation
| if softcap != 0.0 { | ||
| be.softcap(s.logits, c.n_vocab, softcap)?; | ||
| } | ||
| be.argmax_rows(s.logits, c.n_vocab, 1, s.amax)?; |
There was a problem hiding this comment.
🟠 High · Correctness · 1 of 4
Dropping softcap can change argmax through f32 saturation ties. softcap*tanh(x/softcap) is monotonic in exact arithmetic, but in f32 large logits saturate to the same value. Two distinct raw logits that the capped reference maps to a tie can now differ, so argmax_rows can pick a different token than the softcapped path, and tie-breaking may differ too. Output can diverge from the reference model on those steps.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 685
Symbol: prefill_chunk_seq
Issue: Dropping softcap can change argmax through f32 saturation ties. softcap*tanh(x/softcap) is monotonic in exact arithmetic, but in f32 large logits saturate to the same value. Two distinct raw logits that the capped reference maps to a tie can now differ, so argmax_rows can pick a different token than the softcapped path, and tie-breaking may differ too. Output can diverge from the reference model on those steps.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| /// Project a single corrected hidden vector `h_corr` (`[n_embd]`) through the target's LM head on GPU | ||
| /// and return the argmax token ID (`0..c.n_vocab`). `softcap * tanh(x / softcap)` is strictly monotonic | ||
| /// so argmax does not need the softcap kernel. | ||
| pub(super) fn lm_head_argmax(&self, m: &Inkling2Model, h_corr: &[f32], _softcap: f32) -> Result<u32> { |
There was a problem hiding this comment.
🟠 High · Correctness · 2 of 4
Doc claims strict monotonicity, which does not hold in f32. The new doc says the transform is strictly monotonic so argmax does not need it. In f32 saturation makes it non-injective for large |x|, so a future maintainer may trust the claim and remove other numerical safeguards or miss the tie behaviour when debugging divergent tokens.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 678
Symbol: record_dspark_visit
Issue: Doc claims strict monotonicity, which does not hold in f32. The new doc says the transform is strictly monotonic so argmax does not need it. In f32 saturation makes it non-injective for large |x|, so a future maintainer may trust the claim and remove other numerical safeguards or miss the tie behaviour when debugging divergent tokens.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| let d = dev::get().unwrap().lock().unwrap(); | ||
| let be = &*d.parts[0].be; | ||
| be.put(h_corr, &self.scr, ((s.hn - o) / 4) as usize)?; | ||
| be.gemvq(d.tensor(m.output.gpu.unwrap()), s.hn, c.n_embd, 0, s.logits, c.n_vocab, 1)?; |
There was a problem hiding this comment.
🟠 High · Correctness · 3 of 4
s.logits now holds uncapped values for any later reader. s.logits used to hold softcapped values. If anything reads it after this function (logprobs, top-k sampling, speculative acceptance, debug dumps), it now gets raw logits. Those values are not in the same scale as before, so probabilities or thresholds computed from them are wrong. The diff does not show whether any such reader exists.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 684
Symbol: prefill_chunk_seq
Issue: s.logits now holds uncapped values for any later reader. s.logits used to hold softcapped values. If anything reads it after this function (logprobs, top-k sampling, speculative acceptance, debug dumps), it now gets raw logits. Those values are not in the same scale as before, so probabilities or thresholds computed from them are wrong. The diff does not show whether any such reader exists.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
| /// Project a single corrected hidden vector `h_corr` (`[n_embd]`) through the target's LM head on GPU | ||
| /// and return the argmax token ID (`0..c.n_vocab`). `softcap * tanh(x / softcap)` is strictly monotonic | ||
| /// so argmax does not need the softcap kernel. | ||
| pub(super) fn lm_head_argmax(&self, m: &Inkling2Model, h_corr: &[f32], _softcap: f32) -> Result<u32> { |
There was a problem hiding this comment.
🔵 Low · Maintainability · 4 of 4
Unused _softcap parameter left in signature and callers. The softcap argument is now ignored, but every caller still computes and passes it. This keeps a misleading parameter that a future edit could assume is applied. Removing it from the signature and call sites would make the no-op explicit.
Prompt for your AI agent
File: src/inkling2/forward/device.rs
Line: 678
Symbol: record_dspark_visit
Issue: Unused _softcap parameter left in signature and callers. The softcap argument is now ignored, but every caller still computes and passes it. This keeps a misleading parameter that a future edit could assume is applied. Removing it from the signature and call sites would make the no-op explicit.
Make the smallest change that fixes this, add a test, and change nothing unrelated.
Reply /dismiss (optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.
Aletheore Flash Lite reviewWhat this PR does. This change removes the softcap kernel call from
4 finding(s) posted as inline review comment(s).
Review detailsReviewed 1 file(s); skipped 0. Dismissed 0; outside PR diff 0. Grounding: 4 of 4 proposed finding(s). Fix all with your agent |
🔍 Aletheore evidence diffgraph LR
n0["device.rs"]
n1["forward.rs"]
n0 --> n1
classDef changed fill:#d9772c,color:#fff,stroke:#b85f1c;
classDef changedFinding fill:#c0392b,color:#fff,stroke:#922b21;
classDef dependent fill:#f2f0ec,color:#18140f,stroke:#d6d0c5;
class n0 changed
class n1 dependent
What changed
Aggregate deltas
|
|
@ybenyedder Merged, ty. The token is a draft that the target checks, so the text cannot change: 200 greedy tokens with the DSpark file are the same before and after on UD-IQ2_XXS and UD-IQ3_XXS, on CUDA and Vulkan. On top of the PR I removed the unused parameter, the softcap of the CPU fallback and the |
Since
softcap * tanh(x / softcap)is strictly monotonic for positivesoftcap,argmaxis invariant. Skippingbe.softcapinDevice::lm_head_argmaxavoids an extra 200k-element kernel dispatch + barrier on every DSpark draft token (17.2 -> 17.5 tok/son Radeon 890M Vulkan).