huggingface / huggingface/diffusers
fix underlying issue with `test_from_save_pretrained_dtype_inference` is that the `model.to(dtype)` cast at
- Vorherrschende Sprache
- Python
- Sterne
- 34.5k
- Forks
- 7.3k
- Ø Merge
- 3 T. 3 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
I think an underlying issue with `test_from_save_pretrained_dtype_inference` is that the `model.to(dtype)` cast at
https://github.com/huggingface/diffusers/blob/5d10b4de3b65b1debb8a94de3a0e3bfa51fc628a/tests/models/testing_utils/common.py#L484
is not dtype-aware (it will cast everything to `dtype`), but `from_pretrained(..., torch_dtype=dtype)` is dtype-aware (it respects `_keep_in_fp32_modules`, etc.). This causes the behavior of the two to diverge in several scenarios:
1. There are `_keep_in_fp32_modules` specified on the `model` (the more common case)
2. A non-persistent buffer like `inv_freq` is created with an explicit dtype (which is the case here)
which leads to a divergence between the outputs of `model` and `model_loaded`.
_Originally posted by @dg845 in https://github.com/huggingface/diffusers/pull/13862#discussion_r3359815645_
Cc: @dn6
Beitragsleitfaden
Rechercherichtung
Start in tests/models/testing_utils/common.py around line 484 and read test_from_save_pretrained_dtype_inference. Compare the model.to(dtype) setup with from_pretrained(..., torch_dtype=dtype), focusing on _keep_in_fp32_modules and the explicitly typed inv_freq buffer. Done when the test setup and loading path agree in these scenarios without output divergence.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python, pytorch
- Bereich
- machine-learning, testing-qa
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100