I also ran some additional measurements using the actual callback:
I reproduced the reconstruction issue with TRL 1.19.0. The saved model and the actual averaging state can have different dtypes.
This is relevant to the question about FP32 and numerical stability in #8549: a float32 running_model does not imply a float32 EMA. The running copy is the destination, while the initial snapshots and EMA tensors are separate objects.
My additional observations:
| Check | Result in my small CPU fixture |
|---|---|
| BF16 or FP16 dense model | 19,776 bytes of source parameters; 39,552 bytes of FP32 running-model parameters |
| BF16 averaging state, FP32 running model | Maximum EMA error of about 0.01191 against an FP64 reference on a controlled 32-step trajectory |
| FP32 averaging state, BF16 running model, same input trajectory | Maximum EMA error of about 1.34e-7; the running model still has the final BF16 rounding error |
| Real PEFT LoRA model | The stock initialization raises a constructor TypeError ; an experimental copy-based initialization preserves the mixed BF16/FP32 parameter layout and reaches adapter export and reload |
| Reusing the callback with a second model and freezing one parameter | A stale reference from the first model changes the frozen parameter in the second running copy; a fresh callback does not |
The byte counts are parameter payload, not total CUDA memory. The numerical tests measure a recurrence, not trained-model accuracy.
I would start with the installed TRL version and actual parameter dtypes. Use a fresh callback for independent training sessions. If stock PEFT initialization fails and BEMA is optional, ordinary adapter training/export is an alternative, not an equivalent averaged checkpoint. If BEMA is required, test topology and export on a tiny model before trying a larger run.
The tests below used Python 3.13.18, PyTorch 2.14.1+cpu, TRL 1.19.0, Transformers 5.24.0, PEFT 0.22.0, Accelerate 1.16.0 and Datasets 4.7.0. The fixture is a tiny, randomly initialized Qwen2 model, not a downloaded full-size checkpoint. I used the actual callback hooks and controlled parameter changes instead of training an optimizer. The installed callback source matched the Git blob of the release (51cade794f29fde1edc91bc262f690ef354afc7f). There were five initial BEMA cases and seven follow-up cases, including the deliberately observed initialization failure. The environment’s pip check was not entirely clean (IPython’s missing jedi dependency), although the relevant imports and probe stages completed.
The tests are direct hooks, not a full Trainer or GPU/distributed/quantized benchmark.
A. What the reconstruction preserves, and what the byte counts actually mean