Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/inkling2/forward/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {

Copy link
Copy Markdown

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
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

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)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

if softcap != 0.0 {
be.softcap(s.logits, c.n_vocab, softcap)?;
}
be.argmax_rows(s.logits, c.n_vocab, 1, s.amax)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 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.

let id = be.get::<i32>(&self.scr, ((s.amax - o) / 4) as usize, 1)?[0] as u32;
Ok(id)
Expand Down
Loading