Skip to content

feat(early-exit): CALM-style adaptive per-token threshold + arch gating (v0.27.0) - #18

Merged
wesleyscholl merged 1 commit into
mainfrom
claude/konjo-kairu-udsqrp
Jun 22, 2026
Merged

feat(early-exit): CALM-style adaptive per-token threshold + arch gating (v0.27.0)#18
wesleyscholl merged 1 commit into
mainfrom
claude/konjo-kairu-udsqrp

Conversation

@konjoinfinity

Copy link
Copy Markdown
Contributor

Konjo sprint — v0.27.0

Fourth sprint from this session's Discovery sweep (#15 CyclicJudge, #16 reliability, #17 KV eviction — all merged). Continues the inference-optimizer half of kairu picked back up in #17.

Why

EarlyExitDecoder used a single static confidence threshold for every token — but an early-token mistake propagates through the whole sequence, so early and late tokens shouldn't share one bar. And AutoProfile recommended early_exit for any mid-size model regardless of whether the architecture can actually exit (encoder-only models have no left-to-right confidence trajectory; shallow models have nothing to skip).

What

kairu/early_exit.py — CALM-style adaptive threshold (Schuster et al. 2022), opt-in via adaptive=True (static path bit-for-bit unchanged):

  • The bar decays geometrically over decoding steps:
    threshold(t) = min_confidence + (confidence_threshold − min_confidence)·exp(−adapt_decay·t).
    Early tokens must clear a high bar; it relaxes toward min_confidence as decoding proceeds. New effective_confidence(step) exposes the schedule.
  • min_confidence is clamped to the base so the schedule is monotone non-increasing. The constructor now validates inputs (it previously accepted any value). Stats gain adaptive + final_confidence_threshold.

kairu/auto_profile.py — arch-suitability gating:

  • New _early_exit_suitable(model, name) rules out encoder-style families (BERT/RoBERTa/ELECTRA/DeBERTa/T5/encoder) and sub-6-layer models. Both early_exit and layered_early_exit recommendations fall back to vanilla with an explanatory rationale when the gate fails. (Correctly resolves num_layers as a method on LayeredModelInterface.)

kairu/wrapper.pyadaptive_early_exit: bool = False flag (parallel to adaptive_gamma) forwards to the decoder, making the feature reachable from wrap_model.

Quality gates

  • 732 passed, 4 HF-gated skipped (+17 new).
  • New tests/test_early_exit.py takes the module 21% → 100% coverage — validation, the decay schedule, every exit reason (confidence / entropy / max_tokens), and an adaptive-vs-static divergence case with hand-derived expected values (threshold(2)=0.5+0.4·e⁻¹≈0.647). 3 arch-gate tests added.
  • early_exit.py / auto_profile.py: ruff lint + format clean; recommend stays grade C cc=15 (the documented ≤15 ceiling, same grade as before this change and consistent with existing _collect_hardware/paired_t_test).

Reuse note

Pure NumPy + stdlib — no HF/torch in the decode path. The adaptive schedule generalises the existing static threshold (which is just the adaptive=False branch); the arch gate is extracted as a single helper so recommend stays one readable decision tree.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TmSqgYqcYfzPnkpDVR5vdw


Generated by Claude Code

…ng (v0.27.0)

EarlyExitDecoder gains an opt-in CALM-style (Schuster et al. 2022) adaptive
confidence threshold that decays geometrically over decoding steps from
confidence_threshold toward min_confidence: early tokens need high confidence
(an early mistake propagates), later tokens exit more readily. effective_
confidence(step) exposes the schedule; the static path is unchanged. The
constructor now validates its inputs; generate() stats gain adaptive +
final_confidence_threshold.

auto_profile gains _early_exit_suitable() arch gating — encoder-style families
(BERT/RoBERTa/T5/...) and sub-6-layer models fall back to vanilla with an
explanatory rationale, for both early_exit and layered_early_exit.

wrapper exposes adaptive_early_exit (parallel to adaptive_gamma) so the feature
is reachable from wrap_model.

New tests/test_early_exit.py takes the module 21% -> 100%; 3 arch-gate tests
added. Suite: 732 passed, 4 HF-gated skipped. Version 0.26.0 -> 0.27.0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmSqgYqcYfzPnkpDVR5vdw
@wesleyscholl
wesleyscholl marked this pull request as ready for review June 22, 2026 10:47
@wesleyscholl
wesleyscholl merged commit 50dc294 into main Jun 22, 2026
7 checks passed
@wesleyscholl
wesleyscholl deleted the claude/konjo-kairu-udsqrp branch June 22, 2026 10:47
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.

3 participants