{"slug": "one-more-measured-note-for-trl-a-callback-s-rebuilt-running-model-loses-its", "title": "One more measured note for trl — a callback's rebuilt running model loses its dtype", "summary": "A reproduction on TRL 1.19.0 found that a rebuilt running model can carry a different dtype from its averaging state, so a float32 running_model does not imply a float32 EMA, according to measurements posted in Hugging Face TRL issue #8549. In a small CPU fixture with a BF16 or FP16 dense model, the source parameters totaled 19,776 bytes against 39,552 bytes of FP32 running-model parameters, and a BF16 averaging state with an FP32 running model produced a maximum EMA error of about 0.01191 against an FP64 reference over a controlled 32-step trajectory, versus about 1.34e-7 when the averaging state was FP32 and the running model BF16. The tester also reported that stock PEFT LoRA initialization raised a constructor TypeError, that reusing the callback across a second model let a stale reference alter a frozen parameter, and recommended starting from the installed TRL version and actual parameter dtypes and using a fresh callback for independent training sessions.", "body_md": "I also ran some additional measurements using the actual callback:\n\nI reproduced the reconstruction issue with TRL 1.19.0. The saved model and the actual averaging state can have different dtypes.\n\nThis is relevant to the [question about FP32 and numerical stability in #8549](https://github.com/huggingface/trl/issues/8549#issuecomment-7126202104): 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.\n\nMy additional observations:\n\n| Check | Result in my small CPU fixture | \n|---|---|\n| BF16 or FP16 dense model | 19,776 bytes of source parameters; 39,552 bytes of FP32 running-model parameters | \n| BF16 averaging state, FP32 running model | Maximum EMA error of about 0.01191 against an FP64 reference on a controlled 32-step trajectory | \n| 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 | \n| 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 | \n| 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 | \n\nThe byte counts are parameter payload, not total CUDA memory. The numerical tests measure a recurrence, not trained-model accuracy.\n\nI 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.\n\nThe 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.\n\nThe tests are direct hooks, not a full Trainer or GPU/distributed/quantized benchmark.\n\nA. What the reconstruction preserves, and what the byte counts actually mean", "url": "https://wpnews.pro/news/one-more-measured-note-for-trl-a-callback-s-rebuilt-running-model-loses-its", "canonical_source": "https://discuss.huggingface.co/t/one-more-measured-note-for-trl-a-callbacks-rebuilt-running-model-loses-its-dtype/192482#post_2", "published_at": "2026-11-30 04:41:31+00:00", "updated_at": "2026-11-30 04:46:39.799017+00:00", "lang": "en", "topics": ["machine-learning", "ai-research", "developer-tools"], "entities": ["Hugging Face", "TRL", "TRL 1.19.0", "PEFT", "PEFT 0.22.0", "PyTorch", "Qwen2", "Transformers"], "also_reported_by": [], "takeaway": "A float32 running_model does not guarantee a float32 EMA: with a BF16 averaging state and FP32 running model, maximum EMA error was about 0.01191 against an FP64 reference over 32 steps, versus about 1.34e-7 with an FP32 averaging state and BF16 running model.", "recommendation": {"advice": "Check the installed TRL version and actual parameter dtypes before trusting an EMA, and use a fresh callback per training session so stale references cannot alter frozen parameters.", "playbook": "training-data", "playbook_url": "https://wpnews.pro/playbooks/training-data"}, "alternates": {"html": "https://wpnews.pro/news/one-more-measured-note-for-trl-a-callback-s-rebuilt-running-model-loses-its", "markdown": "https://wpnews.pro/news/one-more-measured-note-for-trl-a-callback-s-rebuilt-running-model-loses-its.md", "text": "https://wpnews.pro/news/one-more-measured-note-for-trl-a-callback-s-rebuilt-running-model-loses-its.txt", "jsonld": "https://wpnews.pro/news/one-more-measured-note-for-trl-a-callback-s-rebuilt-running-model-loses-its.jsonld"}}