feat(dqn): checkpoint architecture validation via safetensors metadata

Embed DQNConfig architecture hash (SHA-256 of state_dim, num_actions,
hidden_dims, dueling/distributional/noisy/IQN flags) in safetensors
file header on save. Validate hash on load to catch shape mismatches
before touching the VarMap - prevents silent corruption from loading
checkpoints trained with different network architectures.

All 5 save paths (trainable_adapter, trainer serialize_model,
DQNAgentType::save_checkpoint, RegimeConditionalDQN per-head) now
embed metadata. All 3 load paths (DQN::load_from_safetensors,
trainable_adapter::load_checkpoint, ensemble adapter) validate.

No backward compatibility: checkpoints without metadata are rejected
with a clear error message to re-train.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-03-03 22:06:56 +01:00
parent 2f60e0cda0
commit ba841f7c8b
8 changed files with 225 additions and 50 deletions

View File

@@ -145,6 +145,7 @@ once_cell = "1.19"
lazy_static.workspace = true
flate2 = "1.0"
sha2 = "0.10"
safetensors = "0.4" # Direct dep for checkpoint metadata (config hash validation)
hmac = "0.12" # HMAC for checkpoint signatures (SEC-001 fix)
hex = "0.4" # Hex encoding for signatures
bincode = "1.3"