Improve ChaosGrad diagnostics correctness and decay stability - #26
Conversation
Agent-Logs-Url: https://github.com/theomgdev/OdyssNet/sessions/37388dc7-e4b5-4285-bab5-54700c67a571 Co-authored-by: theomgdev <29312699+theomgdev@users.noreply.github.com>
Agent-Logs-Url: https://github.com/theomgdev/OdyssNet/sessions/37388dc7-e4b5-4285-bab5-54700c67a571 Co-authored-by: theomgdev <29312699+theomgdev@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the ChaosGrad optimizer to (1) make diagnostics reflect per-parameter-group LR overrides rather than only optimizer defaults, and (2) add a numerical safety floor to the decoupled weight decay multiplier under extreme LR×decay values.
Changes:
- Compute
avg_init_lringet_diagnostics()using each param group’s effectivelr, and includeavg_init_lrin per-group debug diagnostics. - Floor the decoupled weight decay multiplier in
step()to avoid negative/near-zero scaling under extreme settings. - Add tests ensuring diagnostics reflect LR overrides at both global and per-group levels.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
odyssnet/training/chaos_optimizer.py |
Adjusts decay multiplier guarding and corrects diagnostics to use per-group genesis LR overrides. |
tests/training/test_chaos_optimizer_extra.py |
Adds coverage ensuring LR overrides propagate into global and per-group diagnostics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # ---- Weight decay ---- | ||
| if per_decay > 0.0 and not is_hebbian: | ||
| p.data.mul_(1.0 - genesis_lr * per_decay) | ||
| decay_factor = max(self._EPS, 1.0 - genesis_lr * per_decay) |
There was a problem hiding this comment.
decay_factor is floored with self._EPS (1e-8), but when parameters are float16 this value can underflow to 0 when cast during mul_, reintroducing the pathological “zero scaling” this guard is trying to prevent. Consider using a dtype-aware floor (e.g., max(self._EPS, torch.finfo(p.data.dtype).tiny) or computing the factor as a tensor in the param dtype) so the clamp is effective under AMP/mixed precision as well.
| decay_factor = max(self._EPS, 1.0 - genesis_lr * per_decay) | |
| decay_floor = max(self._EPS, torch.finfo(p.data.dtype).tiny) | |
| decay_factor = max(decay_floor, 1.0 - genesis_lr * per_decay) |
| @@ -569,10 +570,11 @@ def get_diagnostics(self, debug: bool = False) -> dict: | |||
| genesis_lr = self.defaults['lr'] | |||
There was a problem hiding this comment.
genesis_lr = self.defaults['lr'] is now unused after switching avg_init_lr to be computed from each group's lr. Please remove the dead assignment to avoid confusion about which LR is actually being diagnosed.
| genesis_lr = self.defaults['lr'] |
Summary
This PR tightens ChaosGrad behavior in two places: diagnostics now reflect effective per-group genesis LR overrides, and decoupled weight decay is numerically guarded under extreme LR×decay combinations.
Changes
ChaosGrad.get_diagnostics()now computesavg_init_lrfrom each param group’s currentlr(not only optimizer defaults).avg_init_lrto each debugparam_groupsentry for group-level visibility.step(), decay multiplier is now floored withself._EPS:genesis_lr * per_decayis large.avg_init_lr)param_groups[*].avg_init_lr)Checklist
All contributions
python -m pytest tests/orpytest tests/)sys.path.appendhacks — imports usefrom odyssnet import ...directlyLibrary changes (
odyssnet/)tests/New/modified example scripts (
examples/)set_seed(42)is called as the first line ofmain()examples/for core validations,examples/advanced/for complex tasks)OdyssNetTrainer(not a manual training loop)TrainingHistoryto record metrics and callshistory.plot()at the end__file__, not hardcoded