huggingface / huggingface/diffusers

fix underlying issue with `test_from_save_pretrained_dtype_inference` is that the `model.to(dtype)` cast at

Aperta
#13,869 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
34.5k
Fork
7.3k
Merge medio
3g 3h
PR unite (30g)
91

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python, pytorch
Ambito
machine-learning, testing-qa
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.