Skip to content

fix(modeling): reject missing decoder weights - #135

Merged
nonatofabio merged 1 commit into
strands-labs:mainfrom
ikenyal:fix/reject-missing-decoder-weights
Nov 24, 2026
Merged

nonatofabio merged 1 commit into
strands-labs:mainfrom
ikenyal:fix/reject-missing-decoder-weights

Conversation

@ikenyal

@ikenyal ikenyal commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Human Overview

I wanted checkpoint loading to fail clearly instead of silently leaving decoder weights randomly initialized. This change checks the loading results and rejects missing decoder weights, while preserving intentional omissions and keeping checkpoint-format support unchanged.

Description

An unmapped checkpoint can leave decoder weights randomly initialized while loading appears to succeed. _load_torso now requests loading information on each branch and raises a ValueError naming the checkpoint, missing-weight count, and first missing decoder keys.

Only weights belonging to the retained decoder are checked. Discarded LM heads and Gemma 4 vision/audio encoders remain optional. This does not add checkpoint layouts or change the training recipe, calibration, or correctly loaded weights. The architecture guide describes the failure behavior.

Related Issues

Closes #131. This is separate from the token-readout work in #124, as agreed in the issue.

Type of Change

Bug fix

Testing

Python 3.12: 517 passed, 19 skipped. Python 3.10 with CI's floor pins: 501 passed, 20 skipped. CPU distributed: 11 passed, 1 skipped. Twelve offline CPU regression cases cover complete/missing weights, an unmapped layout, and intentional omissions; six fail on main. CI-equivalent formatting, lint, and type checks pass. CUDA untested; see the environment note below.

  • I ran pytest -q locally (GPU tests skip automatically without CUDA)
  • I ran ruff check . and mypy ./src locally and both pass

Additional Details

Validation environment
  • Latest runtime: Python 3.12.12, torch 2.15.0, transformers 5.22.2. The standard suite also exercised available Mac MPS tests. The new loader tests themselves use tiny CPU checkpoints only.
  • Floor runtime: Python 3.10.19, torch 2.7.1, transformers 5.15.0, peft 0.21.0, huggingface_hub 1.5.0, matching CI's floor pins. All tests ran with HF_HUB_OFFLINE=1, without downloading base models.
  • Formatting, lint, and mypy ./src ./training --exclude training/tests passed with the dependencies declared for CI's detached lint environment. Type-checking with the latest runtime's torch stubs instead reports the same 24 existing errors on main and this branch; no new errors were introduced.
  • Existing suite warnings remain. No CUDA, full-size model, benchmark, or training-recipe run was performed.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings
  • Any dependent changes have been merged and published — N/A: no dependent changes.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Check loading results for the retained decoder so incompatible checkpoints cannot silently leave random weights in use. Keep discarded heads and encoders outside the check.
@ikenyal
ikenyal marked this pull request as ready for review November 9, 2026 21:25
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@nonatofabio
nonatofabio self-requested a review November 24, 2026 01:18

@nonatofabio nonatofabio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nonatofabio
nonatofabio merged commit 6d85079 into strands-labs:main Nov 24, 2026
13 checks passed
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.

_load_torso leaves the decoder at random init, without an error, when a checkpoint's weight names do not map

2 participants