From f5cb9530828fa0364eeddf158668c863f415b0aa Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Mon, 23 Mar 2026 14:40:30 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20gradient=20clip=2010.0=E2=86=921.0=20?= =?UTF-8?q?=E2=80=94=20prevents=20grad=20accumulation=20with=20complex=20r?= =?UTF-8?q?eward?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit grad_norm was growing 5x per epoch (523→2673→13K→67K→NaN). The old clip at 10.0 allowed gradients to accumulate. With clip=1.0, the Adam optimizer receives bounded updates. Trial 2 (TPE-guided params) trains cleanly for 4 epochs: train_loss: 4.5→3.3 (decreasing!) Q-value: 12-19 (stable) grad_norm: 162-567 (bounded) Trial 1 (random initial params) still NaN's — this is expected and handled by the hyperopt penalty (1M objective). The optimizer learns to avoid unstable parameter regions. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/ml/src/trainers/dqn/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ml/src/trainers/dqn/config.rs b/crates/ml/src/trainers/dqn/config.rs index 44945f209..9c4130eb1 100644 --- a/crates/ml/src/trainers/dqn/config.rs +++ b/crates/ml/src/trainers/dqn/config.rs @@ -1262,7 +1262,7 @@ impl DQNHyperparameters { use_huber_loss: true, // Default: Huber loss enabled (more robust) huber_delta: 100.0, // BUG #12 FIX: Scale delta 100x for gradient explosion fix (was 1.0) use_double_dqn: true, // Default: Double DQN enabled (prevents overestimation bias) - gradient_clip_norm: Some(10.0), // REVERTED: Back to 10.0 default (production standard) + gradient_clip_norm: Some(1.0), // Tight clip — prevents grad explosion with complex reward hold_penalty_weight: 0.01, // Default: 1% penalty weight movement_threshold: 0.02, // Default: 2% price movement threshold enable_preprocessing: true, // Default: preprocessing enabled (Wave 14 Agent 32)