feat(M88): Framework-Level Inference Hooks#189
Merged
Conversation
- InferenceHook protocol: on_prefill, on_kv_transfer, on_decode_step - HookCapture, StageComparison, TraceResult dataclasses - MockInferenceHook for testing with configurable noise - compare_captures() for field-by-field comparison (max/mean diff, cosine sim) - run_trace() orchestrates hook-based comparison across stages - format_trace() for rich terminal output with per-stage table - xpyd-acc trace CLI subcommand with --mock, --json, --hooks, --threshold - 34 tests covering protocol, captures, comparison, trace, formatting, CLI Closes #188
hlin99-Review-Bot
approved these changes
Apr 6, 2026
hlin99-Review-Bot
left a comment
There was a problem hiding this comment.
✅ Approved (hlin99-Review-Bot)
Idea Value: High — framework-level inference hooks fill a critical gap for root-cause analysis of PD divergence. The hook protocol + mock pattern enables testing without live endpoints.
Code Quality: Clean.
- Well-defined protocol (
InferenceHook) with clear hook points - Solid dataclass hierarchy with proper serialization
compare_captures()handles edge cases (shape mismatch, None fields)- 34 tests with good coverage (protocol, captures, comparison, trace, formatting, JSON, CLI)
- CI all green (lint + tests on 3.10/3.11/3.12)
docs/iterations/current.mdupdated
LGTM.
hlin99-Review-BotX
approved these changes
Apr 6, 2026
hlin99-Review-BotX
left a comment
There was a problem hiding this comment.
✅ Approved (hlin99-Review-BotX)
Idea Value: High — inference hooks are essential for pinpointing where PD divergence originates. The protocol-based design with clear hook points (prefill/kv_transfer/decode_step) is the right abstraction.
Code Quality: Clean.
InferenceHookprotocol is well-defined withruntime_checkablecompare_captures()handles shape mismatches and None fields correctly_cosine_simproperly handles zero-norm edge caserun_trace()cleanly orchestrates the comparison pipeline- Mock hook with configurable noise enables deterministic testing
- 34 tests, CI green on 3.10/3.11/3.12
docs/iterations/current.mdupdated
Second approval — should auto-merge. LGTM.
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.
Summary
Implements framework-level inference hooks for capturing intermediate states during inference, enabling root-cause analysis of PD divergence by comparing intermediate representations.
Changes
inference_hooks.py: Core module with:InferenceHookprotocol:on_prefill,on_kv_transfer,on_decode_stepHookCapture,StageComparison,TraceResultdataclassesMockInferenceHookfor testing with configurable noise scalecompare_captures(): field-by-field comparison (max/mean abs diff, cosine similarity)run_trace(): orchestrates hook-based comparison across pipeline stagesformat_trace(): rich terminal output with per-stage comparison tablexpyd-acc tracesubcommand with--baseline,--target,--prompt,--hooks,--mock,--json,--thresholdCloses #188