Commit f6ae111
committed
fix(diffusers): use correct tensor name prefixes for SDXL text encoders
Problem:
When loading SDXL models in diffusers directory format, text encoders were
loaded with prefixes "te." and "te.1." which don't match the expected tensor
names in the model graph. The model expects "cond_stage_model.transformer."
for clip_l and "cond_stage_model.1.transformer." for clip_g.
This caused "tensor not in model file" errors for all text encoder tensors
when loading SDXL diffusers models.
Solution:
- Changed text_encoder prefix from "te." to "cond_stage_model.transformer."
- Changed text_encoder_2 prefix from "te.1." to "cond_stage_model.1.transformer."
- These prefixes now match what's used when loading separate clip_l/clip_g files
- Added early return in get_sd_version() when SDXL is detected to prevent
later components (VAE) from overriding the version
- Added version caching to prevent re-detection from changing SDXL version
Testing:
- SDXL diffusers models now load successfully
- SD 1.5 models continue to work (regression tested)
- All text encoder tensors are found and loaded correctly
Files changed:
- model.cpp: Updated diffusers text encoder prefixes and SDXL detection logic
- stable-diffusion.cpp: Added version caching to preserve SDXL detection1 parent 636d3cb commit f6ae111
2 files changed
+23
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
655 | 655 | | |
656 | 656 | | |
657 | 657 | | |
658 | | - | |
| 658 | + | |
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
662 | | - | |
| 662 | + | |
663 | 663 | | |
664 | 664 | | |
665 | 665 | | |
| |||
1028 | 1028 | | |
1029 | 1029 | | |
1030 | 1030 | | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
1031 | 1036 | | |
1032 | 1037 | | |
1033 | 1038 | | |
| |||
1089 | 1094 | | |
1090 | 1095 | | |
1091 | 1096 | | |
| 1097 | + | |
1092 | 1098 | | |
1093 | | - | |
| 1099 | + | |
| 1100 | + | |
1094 | 1101 | | |
1095 | 1102 | | |
1096 | 1103 | | |
| |||
1122 | 1129 | | |
1123 | 1130 | | |
1124 | 1131 | | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
1125 | 1137 | | |
1126 | 1138 | | |
1127 | 1139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
329 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
330 | 336 | | |
331 | 337 | | |
332 | 338 | | |
| |||
335 | 341 | | |
336 | 342 | | |
337 | 343 | | |
| 344 | + | |
338 | 345 | | |
339 | 346 | | |
340 | 347 | | |
| |||
0 commit comments