Repository navigation
inkling2: skip redundant softcap before argmax in lm_head_argmax #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -672,18 +672,16 @@ impl Device { | |
| Err(last_err.unwrap()) | ||
| } | ||
|
|
||
| /// Project a single corrected hidden vector `h_corr` (`[n_embd]`) through the target's LM head on GPU, | ||
| /// apply optional `softcap`, and return the argmax token ID (`0..c.n_vocab`). | ||
| pub(super) fn lm_head_argmax(&self, m: &Inkling2Model, h_corr: &[f32], softcap: f32) -> Result<u32> { | ||
| /// 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 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 agentReply |
||
| let c = &m.cfg; | ||
| let (s, o) = (self.s, self.scr.addr()); | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 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 agentReply |
||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 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 agentReply |
||
| let id = be.get::<i32>(&self.scr, ((s.amax - o) / 4) as usize, 1)?[0] as u32; | ||
| Ok(id) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 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
Reply
/dismiss(optionally with a reason) if this isn't helpful - Aletheore won't raise it again on this repo.