Commit ae8aa89
fix: retarget compute_dtype on float dtype casts instead of casting quant state
nn.Module dtype casts (.to(dtype), .half(), .bfloat16()) convert every
floating-point tensor. The packed uint8 weights are naturally immune, but
the fp32 absmax/code buffers would be silently cast, degrading every
subsequent dequantization. Override _apply so a float dtype cast retargets
compute_dtype while the quantization state stays fp32 (re-derived from the
pre-cast tensors — a cast round-trip would be lossy). Device movement is
unaffected.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent d5d8c92 commit ae8aa89
1 file changed
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
215 | 236 | | |
216 | 237 | | |
217 | 238 | | |
| |||
0 commit comments