Commit 534d46d
committed
Fix diffusers HF export crash on configs without torch_dtype
`_resolve_export_dtype` accessed `model.config.torch_dtype` directly, which
raises `AttributeError` for a diffusers `FrozenDict` config that has no
`torch_dtype` key. This broke `export_hf_checkpoint` for diffusers models
(UNet/DiT/Flux) under the minimum transformers/diffusers versions, failing the
`tf_min` unit matrix (tests/unit/torch/export/test_export_diffusers.py).
Read it via `getattr(..., None)` and fall back to the model's parameter dtype
(`next(model.parameters()).dtype`), matching how `diffusers_utils` already
resolves a diffusers model's dtype. Behavior is unchanged when the config
carries `torch_dtype`. Adds version-independent unit tests for the helper.
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>1 parent 913f5e2 commit 534d46d
2 files changed
Lines changed: 46 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
829 | 835 | | |
830 | | - | |
831 | | - | |
| 836 | + | |
| 837 | + | |
832 | 838 | | |
833 | | - | |
| 839 | + | |
834 | 840 | | |
835 | 841 | | |
836 | 842 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| |||
484 | 487 | | |
485 | 488 | | |
486 | 489 | | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
0 commit comments