Commit ded2349
Validate fp16 dynamic loss scaling parameters are positive (#8050)
## What
`fp16.loss_scale_window` and `fp16.min_loss_scale` drive dynamic loss
scaling but are not validated, so invalid values initialize silently and
fail later during training:
- **`loss_scale_window`** is used as `stable_interval %
self.scale_window` in `DynamicLossScaler.update_scale`
(`deepspeed/runtime/fp16/loss_scaler.py`), so a value of `0` raises
`ZeroDivisionError` mid-training.
- **`min_loss_scale`** is the loss-scale floor (`max(cur_scale /
scale_factor, min_scale)`); a value `<= 0` collapses dynamic loss
scaling.
This is the same class of silent-misconfiguration bug as
`fp16.loss_scale` accepting `inf`, fixed in #7889.
## Change
Add a single Pydantic `mode="before"` field validator on
`DeepSpeedFP16Config` covering both fields. It rejects `bool`,
non-numeric, non-finite (`inf`/`-inf`/`nan`), and non-positive values,
raising a clear `ValidationError` (e.g. `fp16.loss_scale_window must be
> 0`). Following the #7889 review, `mode="before"` runs prior to type
coercion (so `True` is rejected), and `float()` is wrapped in
`try/except` so `[]`/`{}` surface a clear `ValidationError` rather than
a raw `TypeError`.
## Tests
Adds `tests/unit/runtime/test_precision_config_dynamic_scale.py`,
parametrized over both fields:
- invalid: `0, -1, inf, nan, True, [], {}` -> `ValidationError`
- valid: `1, 1000, "2"` -> accepted
```bash
pytest -q tests/unit/runtime/test_precision_config_dynamic_scale.py
```
The validator logic was verified against the full matrix locally; the
import-level test runs under CI.
---------
Signed-off-by: Aryan <aryansputta@gmail.com>
Co-authored-by: Masahiro Tanaka <81312776+tohtana@users.noreply.github.com>1 parent ad026a1 commit ded2349
2 files changed
Lines changed: 93 additions & 1 deletion
File tree
- deepspeed/runtime
- tests/unit/runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
163 | 197 | | |
164 | 198 | | |
165 | 199 | | |
| |||
Lines changed: 58 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
0 commit comments