[superseded by #8 - opened as a discussion by mistake] Fix output_hidden_states / attentions returning None

#7
by Avicennasis - opened

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 discussion title from Fix `output_hidden_states` / `attentions` returning None (missing `@capture_outputs`) to [superseded by #8 - opened as a discussion by mistake] Fix output_hidden_states / attentions returning None

Opened this by mistake - the API flag I used created a plain discussion instead of a PR, and it cannot be converted after the fact. The real pull request with both commits is #8; background and evidence in #6.

Sign up or log in to comment