Fix `output_hidden_states` / `attentions` returning None (missing `@capture_outputs`)

#8

Follow-up to #6 (full write-up, evidence and repro there).

  • Commit 1: K2HorizonModel.forward declares the hidden_states / attentions entries in _can_record_outputs, but never had the @capture_outputs decorator that reads the output_* flags and installs the capture hooks — so output_hidden_states=True returned None. Adds the import + decorator, mirroring stock Qwen3MoeModel.forward.
  • Commit 2: the attentions entry names K2HorizonAttention, but these checkpoints instantiate K2HorizonMoVAAttention, so output_attentions=True returned an empty tuple. Lists both classes (weights are produced under eager attention, as with stock models).

Verified on K2-Horizon-0.9B, transformers 5.17.0: as shipped → hidden_states=None; with this branch → 29 states for 28 layers ([0] == embeddings, [-1] == last_hidden_state), flag-off → None, greedy generation unchanged; attentions → 28 tensors with eager attention. The modeling file is byte-identical across all 12 full-model K2-Horizon repos, so the fix applies family-wide (tested here on the 0.9B).

Avicennasis changed pull request status to open
Institute of Foundation Models org

It is kind of the same fix we have merged for 7b so it's safe

zhou94539 changed pull request status to merged

Sign up or log in to comment