| 16 | |
| 17 | |
| 18 | class MappingHuber(Mapping[MappingHuberCfg]): |
| 19 | def forward_undistorted( |
| 20 | self, |
| 21 | delta: Float[Tensor, "*batch 2"], |
| 22 | ) -> Float[Tensor, " *batch"]: |
| 23 | norm = delta.norm(dim=-1) |
| 24 | |
| 25 | mapped = F.huber_loss( |
| 26 | norm, |
| 27 | torch.zeros_like(norm), |
| 28 | reduction="none", |
| 29 | delta=self.cfg.delta, |
| 30 | ) |
| 31 | |
| 32 | # Divide by the delta so that the gradient magnitude in the linear region |
| 33 | # matches that of a regular L1 loss. |
| 34 | return mapped / self.cfg.delta |
nothing calls this directly
no outgoing calls
no test coverage detected