Repository navigation
Commit a0e2e9d
committed
fix(batch-invariant): full-reduction mean returned the sum
Under batch-invariant mode, `x.mean()` and `torch.mean(x)` reach the
`aten::mean.dim` override (`mean_batch_invariant`) with an empty dim list.
The multi-dim branch divided the sum by the product over that empty list
(1), so every full-reduction mean returned the sum; `dim=None` raised.
Autograd was unaffected (the `mean` derivative divides by numel itself),
but every forward value of a full mean was wrong.
Treat an empty or None dim as all dimensions, as aten::mean does.
Signed-off-by: wdykas <wdykas@nvidia.com>1 parent 4e23fd6 commit a0e2e9d
2 files changed
Lines changed: 27 additions & 0 deletions
File tree
- megatron/core/transformer/custom_layers
- tests/unit_tests/transformer
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
585 | 588 | | |
586 | 589 | | |
587 | 590 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
68 | 92 | | |
69 | 93 | | |
70 | 94 | | |
| |||
0 commit comments