feat(early-exit): CALM-style adaptive per-token threshold + arch gating (v0.27.0) - #18
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
EarlyExitDecoderused 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. AndAutoProfilerecommendedearly_exitfor 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 viaadaptive=True(static path bit-for-bit unchanged):threshold(t) = min_confidence + (confidence_threshold − min_confidence)·exp(−adapt_decay·t).Early tokens must clear a high bar; it relaxes toward
min_confidenceas decoding proceeds. Neweffective_confidence(step)exposes the schedule.min_confidenceis clamped to the base so the schedule is monotone non-increasing. The constructor now validates inputs (it previously accepted any value). Stats gainadaptive+final_confidence_threshold.kairu/auto_profile.py— arch-suitability gating:_early_exit_suitable(model, name)rules out encoder-style families (BERT/RoBERTa/ELECTRA/DeBERTa/T5/encoder) and sub-6-layer models. Bothearly_exitandlayered_early_exitrecommendations fall back tovanillawith an explanatory rationale when the gate fails. (Correctly resolvesnum_layersas a method onLayeredModelInterface.)kairu/wrapper.py—adaptive_early_exit: bool = Falseflag (parallel toadaptive_gamma) forwards to the decoder, making the feature reachable fromwrap_model.Quality gates
tests/test_early_exit.pytakes 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;recommendstays 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=Falsebranch); the arch gate is extracted as a single helper sorecommendstays one readable decision tree.🤖 Generated with Claude Code
https://claude.ai/code/session_01TmSqgYqcYfzPnkpDVR5vdw
Generated by Claude Code