auto-diffusers 2.0.36.dev0__py3-none-any.whl → 2.0.37__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
- # coding=utf-8
2
- # Copyright 2025 suzukimain
1
+ # Copyright 2026 suzukimain
3
2
  #
4
3
  # Licensed under the Apache License, Version 2.0 (the "License");
5
4
  # you may not use this file except in compliance with the License.
@@ -13,201 +12,336 @@
13
12
  # See the License for the specific language governing permissions and
14
13
  # limitations under the License.
15
14
 
15
+ from __future__ import annotations
16
+
17
+ # Standard library imports
16
18
  import os
17
19
  import re
18
- import types
19
- from dataclasses import asdict, dataclass, field
20
- from typing import Dict, List, Optional, Union
21
20
  from collections import OrderedDict
21
+ from dataclasses import asdict, dataclass, field
22
+ from types import MethodType
23
+ from typing import Optional, Union
24
+ from urllib.parse import urlparse
22
25
 
23
-
26
+ # Third-party imports
24
27
  import requests
25
28
  import torch
29
+ from diffusers import (
30
+ StableDiffusionInpaintPipeline,
31
+ StableDiffusionUpscalePipeline,
32
+ StableDiffusionXLInpaintPipeline,
33
+ )
34
+ from diffusers import __version__ as diffusers_version
26
35
 
36
+ # Diffusers core imports
27
37
  from diffusers.loaders.single_file_utils import (
28
38
  VALID_URL_PREFIXES,
29
39
  _extract_repo_id_and_weights_name,
30
40
  infer_diffusers_model_type,
31
41
  load_single_file_checkpoint,
32
42
  )
33
-
34
- from diffusers import (
35
- StableDiffusionPipeline,
36
- StableDiffusionImg2ImgPipeline,
37
- StableDiffusionInpaintPipeline,
38
- )
39
43
  from diffusers.pipelines.auto_pipeline import (
44
+ AUTO_IMAGE2IMAGE_PIPELINES_MAPPING,
45
+ AUTO_INPAINT_PIPELINES_MAPPING,
46
+ AUTO_TEXT2IMAGE_PIPELINES_MAPPING,
40
47
  AutoPipelineForImage2Image,
41
48
  AutoPipelineForInpainting,
42
49
  AutoPipelineForText2Image,
43
- AUTO_TEXT2IMAGE_PIPELINES_MAPPING,
44
- AUTO_IMAGE2IMAGE_PIPELINES_MAPPING,
45
- AUTO_INPAINT_PIPELINES_MAPPING,
46
50
  )
47
51
  from diffusers.pipelines.pipeline_utils import DiffusionPipeline
48
52
  from diffusers.utils import logging
49
-
53
+ from packaging.version import Version
54
+
55
+ # Flux pipelines (import separately to avoid Flax deprecation warnings)
56
+ try:
57
+ from diffusers.pipelines.flux import (
58
+ FluxControlImg2ImgPipeline,
59
+ FluxControlInpaintPipeline,
60
+ FluxControlNetImg2ImgPipeline,
61
+ FluxControlNetInpaintPipeline,
62
+ FluxControlNetPipeline,
63
+ FluxControlPipeline,
64
+ FluxImg2ImgPipeline,
65
+ FluxInpaintPipeline,
66
+ FluxKontextPipeline,
67
+ FluxPipeline,
68
+ )
69
+ except ImportError:
70
+ FluxImg2ImgPipeline = None
71
+ FluxInpaintPipeline = None
72
+ FluxPipeline = None
73
+ FluxControlImg2ImgPipeline = None
74
+ FluxControlInpaintPipeline = None
75
+ FluxControlNetImg2ImgPipeline = None
76
+ FluxControlNetInpaintPipeline = None
77
+ FluxControlNetPipeline = None
78
+ FluxControlPipeline = None
79
+ FluxKontextPipeline = None
80
+
81
+ # AnimateDiff pipelines
50
82
  from diffusers import (
51
83
  AnimateDiffPipeline,
52
84
  AnimateDiffSDXLPipeline,
53
- StableDiffusionControlNetPipeline,
54
- StableDiffusionControlNetImg2ImgPipeline,
55
- StableDiffusionControlNetInpaintPipeline,
56
- StableDiffusionXLImg2ImgPipeline,
57
- StableDiffusionXLPipeline,
58
- StableDiffusionXLInpaintPipeline,
59
- StableDiffusionUpscalePipeline,
60
- StableDiffusion3Pipeline,
61
- StableDiffusion3Img2ImgPipeline,
62
- FluxPipeline,
63
- FluxImg2ImgPipeline,
64
- StableDiffusionXLControlNetPipeline,
65
- StableDiffusionXLControlNetImg2ImgPipeline,
66
85
  )
67
86
 
87
+ # Optional pipelines (newer versions only)
88
+ try:
89
+ from diffusers import (
90
+ AuraFlowPipeline,
91
+ ChromaPipeline,
92
+ CogView3PlusPipeline,
93
+ CogView4ControlPipeline,
94
+ CogView4Pipeline,
95
+ HunyuanDiTPipeline,
96
+ Kandinsky3Img2ImgPipeline,
97
+ Kandinsky3Pipeline,
98
+ KandinskyCombinedPipeline,
99
+ KandinskyImg2ImgCombinedPipeline,
100
+ KandinskyInpaintCombinedPipeline,
101
+ KandinskyV22CombinedPipeline,
102
+ KandinskyV22Img2ImgCombinedPipeline,
103
+ KandinskyV22InpaintCombinedPipeline,
104
+ LatentConsistencyModelImg2ImgPipeline,
105
+ LatentConsistencyModelPipeline,
106
+ Lumina2Pipeline,
107
+ LuminaPipeline,
108
+ OvisImagePipeline,
109
+ PixArtAlphaPipeline,
110
+ PixArtSigmaPipeline,
111
+ QwenImageControlNetPipeline,
112
+ QwenImageEditInpaintPipeline,
113
+ QwenImageEditPipeline,
114
+ QwenImageEditPlusPipeline,
115
+ QwenImageImg2ImgPipeline,
116
+ QwenImageInpaintPipeline,
117
+ QwenImageLayeredPipeline,
118
+ QwenImagePipeline,
119
+ SanaPipeline,
120
+ StableDiffusion3ControlNetInpaintingPipeline,
121
+ StableDiffusion3ControlNetPipeline,
122
+ StableDiffusionXLControlNetUnionImg2ImgPipeline,
123
+ StableDiffusionXLControlNetUnionInpaintPipeline,
124
+ StableDiffusionXLControlNetUnionPipeline,
125
+ WanImageToVideoPipeline,
126
+ WanPipeline,
127
+ WanVideoToVideoPipeline,
128
+ ZImageControlNetInpaintPipeline,
129
+ ZImageControlNetPipeline,
130
+ ZImageImg2ImgPipeline,
131
+ ZImageOmniPipeline,
132
+ ZImagePipeline,
133
+ )
134
+ except ImportError:
135
+ # Fallback to None for pipelines not available in older versions
136
+ AuraFlowPipeline = None
137
+ ChromaPipeline = None
138
+ CogView3PlusPipeline = None
139
+ CogView4ControlPipeline = None
140
+ CogView4Pipeline = None
141
+ HunyuanDiTPipeline = None
142
+ KandinskyCombinedPipeline = None
143
+ KandinskyImg2ImgCombinedPipeline = None
144
+ KandinskyInpaintCombinedPipeline = None
145
+ KandinskyV22CombinedPipeline = None
146
+ KandinskyV22Img2ImgCombinedPipeline = None
147
+ KandinskyV22InpaintCombinedPipeline = None
148
+ Kandinsky3Img2ImgPipeline = None
149
+ Kandinsky3Pipeline = None
150
+ LatentConsistencyModelImg2ImgPipeline = None
151
+ LatentConsistencyModelPipeline = None
152
+ Lumina2Pipeline = None
153
+ LuminaPipeline = None
154
+ OvisImagePipeline = None
155
+ PixArtAlphaPipeline = None
156
+ PixArtSigmaPipeline = None
157
+ QwenImageControlNetPipeline = None
158
+ QwenImageEditInpaintPipeline = None
159
+ QwenImageEditPipeline = None
160
+ QwenImageEditPlusPipeline = None
161
+ QwenImageImg2ImgPipeline = None
162
+ QwenImageInpaintPipeline = None
163
+ QwenImageLayeredPipeline = None
164
+ QwenImagePipeline = None
165
+ SanaPipeline = None
166
+ StableDiffusion3ControlNetInpaintingPipeline = None
167
+ StableDiffusion3ControlNetPipeline = None
168
+ StableDiffusionXLControlNetUnionImg2ImgPipeline = None
169
+ StableDiffusionXLControlNetUnionInpaintPipeline = None
170
+ StableDiffusionXLControlNetUnionPipeline = None
171
+ WanImageToVideoPipeline = None
172
+ WanPipeline = None
173
+ WanVideoToVideoPipeline = None
174
+ ZImageControlNetInpaintPipeline = None
175
+ ZImageControlNetPipeline = None
176
+ ZImageImg2ImgPipeline = None
177
+ ZImageOmniPipeline = None
178
+ ZImagePipeline = None
179
+
68
180
  from huggingface_hub import hf_api, hf_hub_download, hf_hub_url
69
181
  from huggingface_hub.file_download import http_get
70
182
  from huggingface_hub.utils import validate_hf_hub_args
71
183
 
72
-
73
184
  logger = logging.get_logger(__name__)
74
185
 
75
186
 
76
- SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING = OrderedDict(
187
+ SINGLE_FILE_MODEL_TYPE_TO_AUTO_PIPELINE_KEY = OrderedDict(
77
188
  [
78
- ("animatediff_rgb", AnimateDiffPipeline),
79
- ("animatediff_scribble", AnimateDiffPipeline),
80
- ("animatediff_sdxl_beta", AnimateDiffSDXLPipeline),
81
- ("animatediff_v1", AnimateDiffPipeline),
82
- ("animatediff_v2", AnimateDiffPipeline),
83
- ("animatediff_v3", AnimateDiffPipeline),
84
- ("autoencoder-dc-f128c512", None),
85
- ("autoencoder-dc-f32c32", None),
86
- ("autoencoder-dc-f32c32-sana", None),
87
- ("autoencoder-dc-f64c128", None),
88
- ("controlnet", StableDiffusionControlNetPipeline),
89
- ("controlnet_xl", StableDiffusionXLControlNetPipeline),
90
- ("controlnet_xl_large", StableDiffusionXLControlNetPipeline),
91
- ("controlnet_xl_mid", StableDiffusionXLControlNetPipeline),
92
- ("controlnet_xl_small", StableDiffusionXLControlNetPipeline),
93
- ("flux-depth", FluxPipeline),
94
- ("flux-dev", FluxPipeline),
95
- ("flux-fill", FluxPipeline),
96
- ("flux-schnell", FluxPipeline),
97
- ("hunyuan-video", None),
98
- ("inpainting", None),
99
- ("inpainting_v2", None),
100
- ("ltx-video", None),
101
- ("ltx-video-0.9.1", None),
102
- ("mochi-1-preview", None),
103
- ("playground-v2-5", StableDiffusionXLPipeline),
104
- ("sd3", StableDiffusion3Pipeline),
105
- ("sd35_large", StableDiffusion3Pipeline),
106
- ("sd35_medium", StableDiffusion3Pipeline),
107
- ("stable_cascade_stage_b", None),
108
- ("stable_cascade_stage_b_lite", None),
109
- ("stable_cascade_stage_c", None),
110
- ("stable_cascade_stage_c_lite", None),
111
- ("upscale", StableDiffusionUpscalePipeline),
112
- ("v1", StableDiffusionPipeline),
113
- ("v2", StableDiffusionPipeline),
114
- ("xl_base", StableDiffusionXLPipeline),
115
- ("xl_inpaint", None),
116
- ("xl_refiner", StableDiffusionXLPipeline),
117
- ],
189
+ ("auraflow", "auraflow"),
190
+ ("chroma", "chroma"),
191
+ ("cogview3", "cogview3"),
192
+ ("cogview4", "cogview4"),
193
+ ("cogview4-control", "cogview4-control"),
194
+ ("controlnet", "stable-diffusion-controlnet"),
195
+ ("controlnet_xl", "stable-diffusion-xl-controlnet"),
196
+ ("controlnet_xl_large", "stable-diffusion-xl-controlnet"),
197
+ ("controlnet_xl_mid", "stable-diffusion-xl-controlnet"),
198
+ ("controlnet_xl_small", "stable-diffusion-xl-controlnet"),
199
+ ("controlnet_xl_union", "stable-diffusion-xl-controlnet-union"),
200
+ ("flux-control", "flux-control"),
201
+ ("flux-controlnet", "flux-controlnet"),
202
+ ("flux-depth", "flux"),
203
+ ("flux-dev", "flux"),
204
+ ("flux-fill", "flux"),
205
+ ("flux-kontext", "flux-kontext"),
206
+ ("flux-schnell", "flux"),
207
+ ("hunyuan", "hunyuan"),
208
+ ("kandinsky", "kandinsky"),
209
+ ("kandinsky22", "kandinsky22"),
210
+ ("kandinsky3", "kandinsky3"),
211
+ ("lcm", "lcm"),
212
+ ("lumina", "lumina"),
213
+ ("lumina2", "lumina2"),
214
+ ("pixart-alpha", "pixart-alpha"),
215
+ ("pixart-sigma", "pixart-sigma"),
216
+ ("playground-v2-5", "stable-diffusion-xl"),
217
+ ("qwenimage", "qwenimage"),
218
+ ("qwenimage-controlnet", "qwenimage-controlnet"),
219
+ ("qwenimage-edit", "qwenimage-edit"),
220
+ ("qwenimage-edit-plus", "qwenimage-edit-plus"),
221
+ ("sana", "sana"),
222
+ ("sd3", "stable-diffusion-3"),
223
+ ("sd35_large", "stable-diffusion-3"),
224
+ ("sd35_medium", "stable-diffusion-3"),
225
+ ("sd3-controlnet", "stable-diffusion-3-controlnet"),
226
+ ("v1", "stable-diffusion"),
227
+ ("v2", "stable-diffusion"),
228
+ ("xl_base", "stable-diffusion-xl"),
229
+ ("xl_refiner", "stable-diffusion-xl"),
230
+ ("z-image", "z-image"),
231
+ ("z-image-controlnet", "z-image-controlnet"),
232
+ ]
118
233
  )
119
234
 
120
- # For single-file checkpoints we expose separate mappings for each task so callers
121
- # can pick the most appropriate pipeline class set. The full, explicit mappings
122
- # for image2image and inpaint are defined below; keep distinct names so they can
123
- # be customized independently.
235
+ UNSUPPORTED_SINGLE_FILE_MODEL_TYPES = (
236
+ "autoencoder-dc-f128c512",
237
+ "autoencoder-dc-f32c32",
238
+ "autoencoder-dc-f32c32-sana",
239
+ "autoencoder-dc-f64c128",
240
+ "cosmos-1.0-t2w-7B",
241
+ "cosmos-1.0-t2w-14B",
242
+ "cosmos-1.0-v2w-7B",
243
+ "cosmos-1.0-v2w-14B",
244
+ "cosmos-2.0-t2i-2B",
245
+ "cosmos-2.0-t2i-14B",
246
+ "cosmos-2.0-v2w-2B",
247
+ "cosmos-2.0-v2w-14B",
248
+ "hidream",
249
+ "hunyuan-video",
250
+ "instruct-pix2pix",
251
+ "ltx-video",
252
+ "ltx-video-0.9.1",
253
+ "ltx-video-0.9.5",
254
+ "ltx-video-0.9.7",
255
+ "mochi-1-preview",
256
+ "stable_cascade_stage_b",
257
+ "stable_cascade_stage_b_lite",
258
+ "stable_cascade_stage_c",
259
+ "stable_cascade_stage_c_lite",
260
+ "z-image-turbo",
261
+ "z-image-turbo-controlnet",
262
+ "z-image-turbo-controlnet-2.0",
263
+ "z-image-turbo-controlnet-2.1",
264
+ )
124
265
 
125
- SINGLE_FILE_CHECKPOINT_IMAGE2IMAGE_PIPELINE_MAPPING = OrderedDict(
126
- [
127
- ("animatediff_rgb", AnimateDiffPipeline),
128
- ("animatediff_scribble", AnimateDiffPipeline),
129
- ("animatediff_sdxl_beta", AnimateDiffSDXLPipeline),
130
- ("animatediff_v1", AnimateDiffPipeline),
131
- ("animatediff_v2", AnimateDiffPipeline),
132
- ("animatediff_v3", AnimateDiffPipeline),
133
- ("autoencoder-dc-f128c512", None),
134
- ("autoencoder-dc-f32c32", None),
135
- ("autoencoder-dc-f32c32-sana", None),
136
- ("autoencoder-dc-f64c128", None),
137
- ("controlnet", StableDiffusionControlNetImg2ImgPipeline),
138
- ("controlnet_xl", StableDiffusionXLControlNetImg2ImgPipeline),
139
- ("controlnet_xl_large", StableDiffusionXLControlNetImg2ImgPipeline),
140
- ("controlnet_xl_mid", StableDiffusionXLControlNetImg2ImgPipeline),
141
- ("controlnet_xl_small", StableDiffusionXLControlNetImg2ImgPipeline),
142
- ("flux-depth", FluxImg2ImgPipeline),
143
- ("flux-dev", FluxImg2ImgPipeline),
144
- ("flux-fill", FluxImg2ImgPipeline),
145
- ("flux-schnell", FluxImg2ImgPipeline),
146
- ("hunyuan-video", None),
147
- ("inpainting", None),
148
- ("inpainting_v2", None),
149
- ("ltx-video", None),
150
- ("ltx-video-0.9.1", None),
151
- ("mochi-1-preview", None),
152
- ("playground-v2-5", StableDiffusionXLImg2ImgPipeline),
153
- ("sd3", StableDiffusion3Img2ImgPipeline),
154
- ("sd35_large", StableDiffusion3Img2ImgPipeline),
155
- ("sd35_medium", StableDiffusion3Img2ImgPipeline),
156
- ("stable_cascade_stage_b", None),
157
- ("stable_cascade_stage_b_lite", None),
158
- ("stable_cascade_stage_c", None),
159
- ("stable_cascade_stage_c_lite", None),
160
- ("upscale", StableDiffusionUpscalePipeline),
161
- ("v1", StableDiffusionImg2ImgPipeline),
162
- ("v2", StableDiffusionImg2ImgPipeline),
163
- ("xl_base", StableDiffusionXLImg2ImgPipeline),
164
- ("xl_inpaint", None),
165
- ("xl_refiner", StableDiffusionXLImg2ImgPipeline),
166
- ]
266
+
267
+ def _build_single_file_pipeline_mapping(auto_mapping, overrides):
268
+ mapping = OrderedDict()
269
+ for model_type, auto_key in SINGLE_FILE_MODEL_TYPE_TO_AUTO_PIPELINE_KEY.items():
270
+ mapping[model_type] = auto_mapping.get(auto_key)
271
+
272
+ for model_type in UNSUPPORTED_SINGLE_FILE_MODEL_TYPES:
273
+ mapping[model_type] = None
274
+
275
+ mapping.update(overrides)
276
+ return mapping
277
+
278
+
279
+ _ANIMATEDIFF_OVERRIDES = {
280
+ "animatediff_rgb": AnimateDiffPipeline,
281
+ "animatediff_scribble": AnimateDiffPipeline,
282
+ "animatediff_sdxl_beta": AnimateDiffSDXLPipeline,
283
+ "animatediff_v1": AnimateDiffPipeline,
284
+ "animatediff_v2": AnimateDiffPipeline,
285
+ "animatediff_v3": AnimateDiffPipeline,
286
+ }
287
+
288
+ _ANIMATEDIFF_INPAINT_OVERRIDES = {}
289
+ for model_type in _ANIMATEDIFF_OVERRIDES:
290
+ _ANIMATEDIFF_INPAINT_OVERRIDES[model_type] = None
291
+
292
+ SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING = _build_single_file_pipeline_mapping(
293
+ AUTO_TEXT2IMAGE_PIPELINES_MAPPING,
294
+ {
295
+ **_ANIMATEDIFF_OVERRIDES,
296
+ "flux-2-dev": FluxPipeline,
297
+ "inpainting": None,
298
+ "inpainting_v2": None,
299
+ "ovis": OvisImagePipeline,
300
+ "upscale": StableDiffusionUpscalePipeline,
301
+ "wan-i2v-14B": WanImageToVideoPipeline,
302
+ "wan-t2v-1.3B": WanPipeline,
303
+ "wan-t2v-14B": WanPipeline,
304
+ "wan-vace-1.3B": WanVideoToVideoPipeline,
305
+ "wan-vace-14B": WanVideoToVideoPipeline,
306
+ "xl_inpaint": None,
307
+ "z-image-omni": ZImageOmniPipeline,
308
+ },
167
309
  )
168
310
 
169
- SINGLE_FILE_CHECKPOINT_INPAINT_PIPELINE_MAPPING = OrderedDict(
170
- [
171
- ("animatediff_rgb", None),
172
- ("animatediff_scribble", None),
173
- ("animatediff_sdxl_beta", None),
174
- ("animatediff_v1", None),
175
- ("animatediff_v2", None),
176
- ("animatediff_v3", None),
177
- ("autoencoder-dc-f128c512", None),
178
- ("autoencoder-dc-f32c32", None),
179
- ("autoencoder-dc-f32c32-sana", None),
180
- ("autoencoder-dc-f64c128", None),
181
- ("controlnet", StableDiffusionControlNetInpaintPipeline),
182
- ("controlnet_xl", None),
183
- ("controlnet_xl_large", None),
184
- ("controlnet_xl_mid", None),
185
- ("controlnet_xl_small", None),
186
- ("flux-depth", None),
187
- ("flux-dev", None),
188
- ("flux-fill", None),
189
- ("flux-schnell", None),
190
- ("hunyuan-video", None),
191
- ("inpainting", StableDiffusionInpaintPipeline),
192
- ("inpainting_v2", StableDiffusionInpaintPipeline),
193
- ("ltx-video", None),
194
- ("ltx-video-0.9.1", None),
195
- ("mochi-1-preview", None),
196
- ("playground-v2-5", None),
197
- ("sd3", None),
198
- ("sd35_large", None),
199
- ("sd35_medium", None),
200
- ("stable_cascade_stage_b", None),
201
- ("stable_cascade_stage_b_lite", None),
202
- ("stable_cascade_stage_c", None),
203
- ("stable_cascade_stage_c_lite", None),
204
- ("upscale", StableDiffusionUpscalePipeline),
205
- ("v1", None),
206
- ("v2", None),
207
- ("xl_base", None),
208
- ("xl_inpaint", StableDiffusionXLInpaintPipeline),
209
- ("xl_refiner", None),
210
- ]
311
+ SINGLE_FILE_CHECKPOINT_IMAGE2IMAGE_PIPELINE_MAPPING = _build_single_file_pipeline_mapping(
312
+ AUTO_IMAGE2IMAGE_PIPELINES_MAPPING,
313
+ {
314
+ **_ANIMATEDIFF_OVERRIDES,
315
+ "flux-2-dev": FluxImg2ImgPipeline,
316
+ "inpainting": None,
317
+ "inpainting_v2": None,
318
+ "qwenimage-layered": QwenImageLayeredPipeline,
319
+ "upscale": StableDiffusionUpscalePipeline,
320
+ "wan-i2v-14B": WanImageToVideoPipeline,
321
+ "wan-t2v-1.3B": None,
322
+ "wan-t2v-14B": None,
323
+ "wan-vace-1.3B": WanVideoToVideoPipeline,
324
+ "wan-vace-14B": WanVideoToVideoPipeline,
325
+ "xl_inpaint": None,
326
+ },
327
+ )
328
+
329
+ SINGLE_FILE_CHECKPOINT_INPAINT_PIPELINE_MAPPING = _build_single_file_pipeline_mapping(
330
+ AUTO_INPAINT_PIPELINES_MAPPING,
331
+ {
332
+ **_ANIMATEDIFF_INPAINT_OVERRIDES,
333
+ "flux-2-dev": FluxInpaintPipeline,
334
+ "inpainting": StableDiffusionInpaintPipeline,
335
+ "inpainting_v2": StableDiffusionInpaintPipeline,
336
+ "upscale": StableDiffusionUpscalePipeline,
337
+ "wan-i2v-14B": None,
338
+ "wan-t2v-1.3B": None,
339
+ "wan-t2v-14B": None,
340
+ "wan-vace-1.3B": None,
341
+ "wan-vace-14B": None,
342
+ "xl_inpaint": StableDiffusionXLInpaintPipeline,
343
+ "z-image-controlnet-inpaint": ZImageControlNetInpaintPipeline,
344
+ },
211
345
  )
212
346
 
213
347
  CONFIG_FILE_LIST = [
@@ -262,15 +396,104 @@ TOKENIZER_SHAPE_MAP = {
262
396
  }
263
397
 
264
398
 
399
+ def get_allowed_extensions(allow_unsafe_formats: bool = False) -> list[str]:
400
+ r"""
401
+ Get the list of allowed file extensions based on safety preferences.
402
+
403
+ Parameters:
404
+ allow_unsafe_formats (`bool`, *optional*, defaults to `False`):
405
+ If True, allows all formats (.safetensors, .ckpt, .bin).
406
+ If False (default), only allows .safetensors format.
407
+
408
+ Returns:
409
+ `list[str]`: List of allowed file extensions.
410
+ """
411
+ if allow_unsafe_formats:
412
+ return [".safetensors", ".ckpt", ".bin"]
413
+ else:
414
+ return [".safetensors"]
415
+
416
+
417
+ # Default extension list (for backward compatibility)
265
418
  EXTENSION = [".safetensors", ".ckpt", ".bin"]
266
419
 
267
420
  CACHE_HOME = os.path.expanduser("~/.cache")
421
+ REQUEST_TIMEOUT = 30
422
+ ALLOWED_DOWNLOAD_HOSTS = (
423
+ "civitai.com",
424
+ "civitai.green",
425
+ "huggingface.co",
426
+ "hf.co",
427
+ )
428
+
429
+
430
+ def _normalize_dtype_kwargs(kwargs):
431
+ kwargs = dict(kwargs)
432
+ if "dtype" in kwargs and "torch_dtype" in kwargs:
433
+ raise ValueError("Pass only one of `dtype` or `torch_dtype`, not both.")
434
+
435
+ if "dtype" in kwargs and Version(diffusers_version) < Version("0.39.0"):
436
+ kwargs["torch_dtype"] = kwargs.pop("dtype")
437
+ elif "torch_dtype" in kwargs and Version(diffusers_version) >= Version("0.39.0"):
438
+ kwargs["dtype"] = kwargs.pop("torch_dtype")
439
+ return kwargs
440
+
441
+
442
+ def _pipeline_loading_kwargs(kwargs):
443
+ load_kwargs = dict(kwargs)
444
+ for key in (
445
+ "_max_retries",
446
+ "_pipeline_tag",
447
+ "allow_unsafe_formats",
448
+ "base_model",
449
+ "candidate_index",
450
+ "checkpoint_format",
451
+ "download",
452
+ "gated",
453
+ "include_params",
454
+ "model_type",
455
+ "pipeline_tag",
456
+ "request_timeout",
457
+ "resume",
458
+ "skip_error",
459
+ "sort",
460
+ ):
461
+ load_kwargs.pop(key, None)
462
+ return _normalize_dtype_kwargs(load_kwargs)
463
+
268
464
 
465
+ def _validate_remote_url(url, allowed_hosts=ALLOWED_DOWNLOAD_HOSTS):
466
+ parsed = urlparse(str(url))
467
+ host = (parsed.hostname or "").lower()
269
468
 
270
- # Set up pipeline mappings
271
- AUTO_TEXT2IMAGE_PIPELINES_MAPPING["v1"] = StableDiffusionPipeline
272
- AUTO_IMAGE2IMAGE_PIPELINES_MAPPING["v1"] = StableDiffusionImg2ImgPipeline
273
- AUTO_INPAINT_PIPELINES_MAPPING["v1"] = StableDiffusionInpaintPipeline
469
+ is_allowed_host = any(
470
+ host == allowed_host or host.endswith(f".{allowed_host}")
471
+ for allowed_host in allowed_hosts
472
+ )
473
+
474
+ if parsed.scheme != "https" or not is_allowed_host:
475
+ raise ValueError("Only HTTPS URLs from Civitai or Hugging Face are supported.")
476
+
477
+
478
+ def _safe_filename(file_name):
479
+ if not isinstance(file_name, str) or not file_name or "\x00" in file_name:
480
+ raise ValueError("The remote API returned an invalid filename.")
481
+ if file_name != os.path.basename(file_name) or "/" in file_name or "\\" in file_name:
482
+ raise ValueError("The remote API returned an unsafe filename.")
483
+ return file_name
484
+
485
+
486
+ def _safe_cache_path(cache_dir, *parts):
487
+ cache_root = os.path.abspath(os.fspath(cache_dir))
488
+ path_parts = [os.fspath(part) for part in parts]
489
+ candidate = os.path.abspath(os.path.join(cache_root, *path_parts))
490
+ try:
491
+ contained = os.path.commonpath([cache_root, candidate]) == cache_root
492
+ except ValueError:
493
+ contained = False
494
+ if not contained:
495
+ raise ValueError("The requested cache path is outside the cache directory.")
496
+ return candidate
274
497
 
275
498
 
276
499
  @dataclass
@@ -327,7 +550,7 @@ class ExtraStatus:
327
550
  The words used to trigger the model
328
551
  """
329
552
 
330
- trained_words: Union[List[str], None] = None
553
+ trained_words: Union[list[str], None] = None
331
554
 
332
555
 
333
556
  @dataclass
@@ -373,15 +596,15 @@ def load_pipeline_from_single_file(
373
596
  pipeline_mapping (`dict`):
374
597
  A mapping of model types to their corresponding pipeline classes. This is used to determine
375
598
  which pipeline class to instantiate based on the model type inferred from the checkpoint.
376
- torch_dtype (`str` or `torch.dtype`, *optional*):
377
- Override the default `torch.dtype` and load the model with another dtype.
599
+ dtype (`torch.dtype` or `dict`, *optional*):
600
+ Override the default dtype. `torch_dtype` remains accepted for compatibility.
378
601
  force_download (`bool`, *optional*, defaults to `False`):
379
602
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
380
603
  cached versions if they exist.
381
604
  cache_dir (`Union[str, os.PathLike]`, *optional*):
382
605
  Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
383
606
  is not used.
384
- proxies (`Dict[str, str]`, *optional*):
607
+ proxies (`dict[str, str]`, *optional*):
385
608
  A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
386
609
  'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
387
610
  local_files_only (`bool`, *optional*, defaults to `False`):
@@ -416,8 +639,9 @@ def load_pipeline_from_single_file(
416
639
  # Infer the model type from the loaded checkpoint
417
640
  model_type = infer_diffusers_model_type(checkpoint)
418
641
 
419
- # Get the corresponding pipeline class from the pipeline mapping
420
- pipeline_class = pipeline_mapping[model_type]
642
+ # Get the corresponding pipeline class from the explicit overrides or the
643
+ # installed Diffusers AutoPipeline mapping.
644
+ pipeline_class = pipeline_mapping.get(model_type)
421
645
 
422
646
  # For tasks not supported by this pipeline
423
647
  if pipeline_class is None:
@@ -430,7 +654,9 @@ def load_pipeline_from_single_file(
430
654
 
431
655
  else:
432
656
  # Load the pipeline from the checkpoint
433
- return pipeline_class.from_single_file(pretrained_model_or_path, **kwargs)
657
+ return pipeline_class.from_single_file(
658
+ pretrained_model_or_path, **_pipeline_loading_kwargs(kwargs)
659
+ )
434
660
 
435
661
 
436
662
  def get_keyword_types(keyword):
@@ -466,6 +692,11 @@ def get_keyword_types(keyword):
466
692
  # Check if the keyword is an HTTP or HTTPS URL
467
693
  status["extra_type"]["url"] = bool(re.search(r"^(https?)://", keyword))
468
694
 
695
+ is_supported_url = any(
696
+ keyword.startswith(prefix)
697
+ for prefix in VALID_URL_PREFIXES
698
+ )
699
+
469
700
  # Check if the keyword is a file
470
701
  if os.path.isfile(keyword):
471
702
  status["type"]["local"] = True
@@ -493,7 +724,7 @@ def get_keyword_types(keyword):
493
724
  status["loading_method"] = None
494
725
 
495
726
  # Check if the keyword starts with any valid URL prefixes
496
- elif any(keyword.startswith(prefix) for prefix in VALID_URL_PREFIXES):
727
+ elif is_supported_url:
497
728
  repo_id, weights_name = _extract_repo_id_and_weights_name(keyword)
498
729
  if weights_name:
499
730
  status["type"]["hf_url"] = True
@@ -522,8 +753,8 @@ def get_keyword_types(keyword):
522
753
  def validate_url_with_head(
523
754
  url: str,
524
755
  token: Optional[str] = None,
525
- headers: Optional[Dict] = None,
526
- timeout: int = 2
756
+ headers: Optional[dict] = None,
757
+ timeout: int = 10,
527
758
  ) -> None:
528
759
  """
529
760
  Validates a URL is accessible by performing a HEAD request.
@@ -544,6 +775,8 @@ def validate_url_with_head(
544
775
  Raises:
545
776
  requests.HTTPError: If the URL returns any 4xx or 5xx status code.
546
777
  """
778
+ _validate_remote_url(url)
779
+
547
780
  if headers is None:
548
781
  headers = {}
549
782
  else:
@@ -552,11 +785,17 @@ def validate_url_with_head(
552
785
 
553
786
  # If token is provided and authorization not already in headers, add it
554
787
  # Check case-insensitively since HTTP headers are case-insensitive
555
- if token and not any(k.lower() == "authorization" for k in headers):
788
+ has_authorization_header = any(
789
+ header_name.lower() == "authorization"
790
+ for header_name in headers
791
+ )
792
+
793
+ if token and not has_authorization_header:
556
794
  headers["Authorization"] = f"Bearer {token}"
557
795
 
558
796
  try:
559
797
  response = requests.head(url, headers=headers, allow_redirects=True, timeout=timeout)
798
+ _validate_remote_url(response.url)
560
799
  # Raise HTTPError for any 4xx/5xx status codes (including 401)
561
800
  response.raise_for_status()
562
801
  except requests.HTTPError:
@@ -596,6 +835,8 @@ def file_downloader(
596
835
  None
597
836
  """
598
837
 
838
+ _validate_remote_url(url)
839
+
599
840
  # Get optional parameters from kwargs, with their default values
600
841
  resume = kwargs.pop("resume", False)
601
842
  headers = kwargs.pop("headers", None)
@@ -632,10 +873,14 @@ def file_downloader(
632
873
  mode = "ab"
633
874
  file_size = os.path.getsize(save_path)
634
875
 
635
- # Check if the URL is accessible before downloading. If the HEAD request returns any
636
- # 4xx or 5xx status code, an HTTPError is raised so callers can try the next candidate.
637
- # Only successful (2xx) responses will proceed to download.
638
- validate_url_with_head(url, headers=headers)
876
+ # Try HEAD validation but don't fail if it returns errors (Cloudflare R2 blocks HEAD requests)
877
+ # The actual download attempt will reveal if the URL is truly inaccessible
878
+ try:
879
+ validate_url_with_head(url, headers=headers)
880
+ except requests.HTTPError as e:
881
+ # Log but continue - HEAD requests may fail even when GET succeeds
882
+ status_code = e.response.status_code if hasattr(e, 'response') else 'unknown'
883
+ logger.info(f"HEAD request returned {status_code} for {url}, attempting download anyway...")
639
884
 
640
885
  # Open the file in the appropriate mode (write or append)
641
886
  with open(save_path, mode) as model_file:
@@ -677,6 +922,9 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
677
922
  A boolean to filter models on the Hub that are gated or not.
678
923
  skip_error (`bool`, *optional*, defaults to `False`):
679
924
  Whether to skip errors and return None.
925
+ allow_unsafe_formats (`bool`, *optional*, defaults to `False`):
926
+ If True, allows potentially unsafe formats (.ckpt, .bin) in addition to .safetensors.
927
+ If False (default), only allows .safetensors format for maximum security.
680
928
 
681
929
  Returns:
682
930
  `Union[str, SearchResult, None]`: The model path or SearchResult or None.
@@ -698,6 +946,10 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
698
946
  gated = kwargs.pop("gated", False)
699
947
  cache_dir = kwargs.pop("cache_dir", None)
700
948
  skip_error = kwargs.pop("skip_error", False)
949
+ allow_unsafe_formats = kwargs.pop("allow_unsafe_formats", False)
950
+
951
+ # Get allowed extensions based on safety preference
952
+ allowed_extensions = get_allowed_extensions(allow_unsafe_formats)
701
953
 
702
954
  file_list = []
703
955
  hf_repo_info = {}
@@ -710,6 +962,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
710
962
  search_word_status = get_keyword_types(search_word)
711
963
 
712
964
  if search_word_status["type"]["hf_repo"]:
965
+ repo_id = search_word
713
966
  hf_repo_info = asdict(
714
967
  hf_api.model_info(repo_id=search_word, securityStatus=True)
715
968
  )
@@ -730,6 +983,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
730
983
  model_path = hf_hub_download(
731
984
  repo_id=repo_id,
732
985
  filename=weights_name,
986
+ revision=revision,
733
987
  token=token,
734
988
  force_download=force_download,
735
989
  cache_dir=cache_dir,
@@ -743,13 +997,13 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
743
997
  return None
744
998
  else:
745
999
  raise ValueError(
746
- "The URL for Civitai is invalid with `for_hf`. Please use `for_civitai` instead."
1000
+ "The URL for Civitai is invalid with `from_huggingface`. Please use `from_civitai` instead."
747
1001
  )
748
1002
  else:
749
1003
  # Get model data from HF API
750
1004
  hf_models = hf_api.list_models(
751
1005
  search=search_word,
752
- direction=-1,
1006
+ sort="downloads",
753
1007
  limit=100,
754
1008
  fetch_config=True,
755
1009
  pipeline_tag=pipeline_tag,
@@ -757,7 +1011,9 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
757
1011
  gated=gated,
758
1012
  token=token,
759
1013
  )
760
- model_dicts = [asdict(value) for value in list(hf_models)]
1014
+ model_dicts = []
1015
+ for model in hf_models:
1016
+ model_dicts.append(asdict(model))
761
1017
 
762
1018
  # Collect all valid candidates first
763
1019
  candidates = []
@@ -773,12 +1029,18 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
773
1029
  continue
774
1030
 
775
1031
  # Lists files with security issues.
776
- hf_security_info = hf_repo_info["security_repo_status"]
777
- exclusion = [issue["path"] for issue in hf_security_info["filesWithIssues"]]
1032
+ hf_security_info = hf_repo_info.get("security_repo_status") or {}
1033
+ if not hf_security_info.get("scansDone"):
1034
+ logger.info(f"Skipping {repo_id} because its security scan is incomplete.")
1035
+ continue
1036
+ exclusion = []
1037
+ for issue in hf_security_info.get("filesWithIssues", []):
1038
+ if "path" in issue:
1039
+ exclusion.append(issue["path"])
778
1040
 
779
1041
  # Checks for multi-folder diffusers model or valid files (models with security issues are excluded).
780
1042
  if hf_security_info["scansDone"]:
781
- for info in repo_info["siblings"]:
1043
+ for info in repo_info.get("siblings", []):
782
1044
  file_path = info["rfilename"]
783
1045
  if "model_index.json" == file_path and checkpoint_format in [
784
1046
  "diffusers",
@@ -792,30 +1054,48 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
792
1054
  })
793
1055
  break
794
1056
 
795
- elif (
796
- any(file_path.endswith(ext) for ext in EXTENSION)
797
- and not any(config in file_path for config in CONFIG_FILE_LIST)
798
- and not any(exc in file_path for exc in exclusion)
799
- and os.path.basename(os.path.dirname(file_path)) not in DIFFUSERS_CONFIG_DIR
800
- # If caller requested checkpoint-only, exclude filenames that look like LoRA/Textual-Inversion
801
- and not (
802
- model_type == "checkpoint"
803
- and any(kw in file_path.lower() for kw in ["lora", "textual", "inversion"])
1057
+ has_allowed_extension = any(
1058
+ file_path.endswith(extension)
1059
+ for extension in allowed_extensions
1060
+ )
1061
+ is_config_file = any(
1062
+ config_name in file_path
1063
+ for config_name in CONFIG_FILE_LIST
1064
+ )
1065
+ has_security_issue = any(
1066
+ excluded_path in file_path
1067
+ for excluded_path in exclusion
1068
+ )
1069
+
1070
+ parent_directory = os.path.basename(os.path.dirname(file_path))
1071
+ is_diffusers_component = parent_directory in DIFFUSERS_CONFIG_DIR
1072
+
1073
+ is_checkpoint_auxiliary = False
1074
+ if model_type == "checkpoint":
1075
+ lower_file_path = file_path.lower()
1076
+ auxiliary_markers = ["lora", "textual", "inversion"]
1077
+ is_checkpoint_auxiliary = any(
1078
+ marker in lower_file_path
1079
+ for marker in auxiliary_markers
804
1080
  )
1081
+
1082
+ if (
1083
+ has_allowed_extension
1084
+ and not is_config_file
1085
+ and not has_security_issue
1086
+ and not is_diffusers_component
1087
+ and not is_checkpoint_auxiliary
805
1088
  ):
806
1089
  file_list.append(file_path)
807
1090
 
808
1091
  # Add single file candidates
809
1092
  if file_list:
810
1093
  # Sort and find the safest model
811
- file_name = next(
812
- (
813
- model
814
- for model in sorted(file_list, reverse=True)
815
- if re.search(r"(?i)[-_](safe|sfw)", model)
816
- ),
817
- file_list[0],
818
- )
1094
+ file_name = file_list[0]
1095
+ for model_file in sorted(file_list, reverse=True):
1096
+ if re.search(r"(?i)[-_](safe|sfw)", model_file):
1097
+ file_name = model_file
1098
+ break
819
1099
  candidates.append({
820
1100
  "type": "single_file",
821
1101
  "repo_id": repo_id,
@@ -961,6 +1241,9 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
961
1241
  Whether to resume an incomplete download.
962
1242
  skip_error (`bool`, *optional*, defaults to `False`):
963
1243
  Whether to skip errors and return None.
1244
+ allow_unsafe_formats (`bool`, *optional*, defaults to `False`):
1245
+ If True, allows potentially unsafe formats (.ckpt, .bin) in addition to .safetensors.
1246
+ If False (default), only allows .safetensors format for maximum security.
964
1247
 
965
1248
  Returns:
966
1249
  `Union[str, SearchResult, None]`: The model path or ` SearchResult` or None.
@@ -977,6 +1260,11 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
977
1260
  resume = kwargs.pop("resume", False)
978
1261
  cache_dir = kwargs.pop("cache_dir", None)
979
1262
  skip_error = kwargs.pop("skip_error", False)
1263
+ allow_unsafe_formats = kwargs.pop("allow_unsafe_formats", False)
1264
+ request_timeout = kwargs.pop("request_timeout", REQUEST_TIMEOUT)
1265
+
1266
+ # Get allowed extensions based on safety preference
1267
+ allowed_extensions = get_allowed_extensions(allow_unsafe_formats)
980
1268
 
981
1269
  # Initialize additional variables with default values
982
1270
  model_path = ""
@@ -992,6 +1280,7 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
992
1280
 
993
1281
  # Handle direct Civitai API download URLs
994
1282
  if search_word.startswith("https://civitai.com/api/download/"):
1283
+ _validate_remote_url(search_word, allowed_hosts=("civitai.com",))
995
1284
  # Extract model version ID from URL
996
1285
  match = re.search(r'/models/(\d+)', search_word)
997
1286
  if match:
@@ -1005,7 +1294,8 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1005
1294
  # Get version info to extract model name and ID
1006
1295
  response = requests.get(
1007
1296
  f"https://civitai.com/api/v1/model-versions/{version_id}",
1008
- headers=headers
1297
+ headers=headers,
1298
+ timeout=request_timeout,
1009
1299
  )
1010
1300
  response.raise_for_status()
1011
1301
  version_data = response.json()
@@ -1014,26 +1304,55 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1014
1304
  repo_id = str(version_data.get("modelId", ""))
1015
1305
  trainedWords = version_data.get("trainedWords", [])
1016
1306
 
1017
- # Get primary file info
1018
- files = version_data.get("files", [])
1019
- if files:
1020
- primary_file = files[0]
1021
- file_name = primary_file.get("name", f"model_{version_id}.safetensors")
1022
- else:
1023
- file_name = f"model_{version_id}.safetensors"
1307
+ # Keep only files that passed both scans and use an allowed extension.
1308
+ files = []
1309
+ for file_info in version_data.get("files", []):
1310
+ pickle_scan_passed = (
1311
+ file_info.get("pickleScanResult") == "Success"
1312
+ )
1313
+ virus_scan_passed = (
1314
+ file_info.get("virusScanResult") == "Success"
1315
+ )
1316
+
1317
+ file_name = str(file_info.get("name", ""))
1318
+ has_allowed_extension = any(
1319
+ file_name.endswith(extension)
1320
+ for extension in allowed_extensions
1321
+ )
1322
+
1323
+ if (
1324
+ pickle_scan_passed
1325
+ and virus_scan_passed
1326
+ and has_allowed_extension
1327
+ ):
1328
+ files.append(file_info)
1329
+
1330
+ if not files:
1331
+ raise ValueError(
1332
+ "The Civitai model version has no file that passed its "
1333
+ "security scans."
1334
+ )
1335
+
1336
+ selected_file = files[0]
1337
+ for file_info in files:
1338
+ if file_info.get("primary"):
1339
+ selected_file = file_info
1340
+ break
1341
+
1342
+ file_name = _safe_filename(selected_file["name"])
1024
1343
 
1025
1344
  except Exception as e:
1026
- logger.info(f"Could not fetch model info from API: {e}. Using fallback values.")
1027
- repo_name = f"model_{version_id}"
1028
- repo_id = ""
1029
- file_name = f"model_{version_id}.safetensors"
1030
- trainedWords = []
1345
+ if skip_error:
1346
+ return None
1347
+ raise ValueError("Could not verify the Civitai model version metadata.") from e
1031
1348
 
1032
1349
  download_url = search_word
1033
1350
 
1034
1351
  if download:
1035
1352
  # Download from the direct URL
1036
- local_path = os.path.join(civitai_cache_dir, file_name)
1353
+ local_path = _safe_cache_path(
1354
+ civitai_cache_dir, str(repo_id), str(version_id), file_name
1355
+ )
1037
1356
 
1038
1357
  try:
1039
1358
  file_downloader(
@@ -1101,32 +1420,32 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1101
1420
  try:
1102
1421
  # Make the request to the CivitAI API
1103
1422
  response = requests.get(
1104
- "https://civitai.com/api/v1/models", params=params, headers=headers
1423
+ "https://civitai.com/api/v1/models",
1424
+ params=params,
1425
+ headers=headers,
1426
+ timeout=request_timeout,
1105
1427
  )
1106
1428
  response.raise_for_status()
1107
- except requests.exceptions.HTTPError as err:
1429
+ except requests.exceptions.RequestException as err:
1108
1430
  if skip_error:
1109
1431
  return None
1110
1432
  else:
1111
- raise requests.HTTPError(f"Could not get elements from the URL: {err}")
1433
+ raise requests.RequestException("Could not query the Civitai API.") from err
1112
1434
  else:
1113
1435
  try:
1114
1436
  data = response.json()
1115
- except AttributeError:
1437
+ except (TypeError, ValueError):
1116
1438
  if skip_error:
1117
1439
  return None
1118
1440
  else:
1119
1441
  raise ValueError("Invalid JSON response")
1120
1442
 
1121
- # Sort repositories by download count in descending order
1122
- # sorted_repos = sorted(
1123
- # data["items"], key=lambda x: x["stats"]["downloadCount"], reverse=True
1124
- # )
1443
+ repositories = data.get("items", [])
1125
1444
 
1126
- # Since the Civitai API is broken, I will temporarily sort by name.
1127
- sorted_repos = sorted(data["items"], key=lambda x: x["name"], reverse=True)
1445
+ # Collect all valid candidates instead of selecting one
1446
+ all_candidates = []
1128
1447
 
1129
- for selected_repo in sorted_repos:
1448
+ for selected_repo in repositories:
1130
1449
  repo_name = selected_repo["name"]
1131
1450
  repo_id = selected_repo["id"]
1132
1451
 
@@ -1145,13 +1464,19 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1145
1464
  for model_data in selected_version["files"]:
1146
1465
  # Check if the file passes security scans and has a valid extension
1147
1466
  file_name = model_data["name"]
1467
+
1468
+ has_allowed_extension = any(
1469
+ file_name.endswith(extension)
1470
+ for extension in allowed_extensions
1471
+ )
1472
+
1148
1473
  if (
1149
- model_data["pickleScanResult"] == "Success"
1150
- and model_data["virusScanResult"] == "Success"
1151
- and any(file_name.endswith(ext) for ext in EXTENSION)
1152
- and os.path.basename(os.path.dirname(file_name))
1153
- not in DIFFUSERS_CONFIG_DIR
1474
+ model_data.get("pickleScanResult") == "Success"
1475
+ and model_data.get("virusScanResult") == "Success"
1476
+ and has_allowed_extension
1154
1477
  ):
1478
+ file_name = _safe_filename(file_name)
1479
+ _validate_remote_url(model_data["downloadUrl"])
1155
1480
  file_status = {
1156
1481
  "filename": file_name,
1157
1482
  "download_url": model_data["downloadUrl"],
@@ -1164,76 +1489,81 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1164
1489
  models_list, key=lambda x: x["filename"], reverse=True
1165
1490
  )
1166
1491
  # Prefer safe/sfw models
1167
- candidate_model = next(
1168
- (
1169
- model_data
1170
- for model_data in sorted_models
1171
- if bool(
1172
- re.search(r"(?i)[-_](safe|sfw)", model_data["filename"])
1173
- )
1174
- ),
1175
- sorted_models[0],
1176
- )
1177
-
1178
- # Validate download URL accessibility (check first file only)
1179
- try:
1180
- # Since models requiring authentication do not return results, there is no need to determine their status via status codes.
1181
- _resp = requests.head(
1182
- candidate_model["download_url"],
1183
- headers=headers,
1184
- timeout=2,
1185
- allow_redirects=True
1492
+ candidate_model = sorted_models[0]
1493
+ for model_data in sorted_models:
1494
+ is_safe_variant = re.search(
1495
+ r"(?i)[-_](safe|sfw)", model_data["filename"]
1186
1496
  )
1187
- _resp.raise_for_status()
1188
- selected_model = candidate_model
1189
- logger.info(f"Validated download URL: {candidate_model['download_url']}")
1190
- break # Exit the version loop if a valid model is found
1191
- except requests.HTTPError as e:
1192
- if "403" in str(e) or "401" in str(e):
1193
- logger.info(f"Access denied ({e.response.status_code}) for {candidate_model['download_url']}, trying next version...")
1194
- continue
1195
- else:
1196
- logger.info(f"HTTP error for {candidate_model['download_url']}: {e}, trying next version...")
1197
- continue
1198
- except requests.exceptions.RequestException as e:
1199
- logger.info(f"Failed to validate URL {candidate_model['download_url']}: {e}, trying next version...")
1200
- continue
1201
-
1202
- # If we found a valid model in this repo, exit outer repo loop
1203
- if selected_model:
1204
- break
1205
-
1206
-
1207
- # Exception handling when search candidates are not found
1208
- if not selected_model:
1497
+ if is_safe_variant:
1498
+ candidate_model = model_data
1499
+ break
1500
+
1501
+ # Add to candidates list (skip URL validation which causes 403 errors)
1502
+ # Actual download will be attempted and retried recursively
1503
+ all_candidates.append({
1504
+ 'model': candidate_model,
1505
+ 'repo_name': repo_name,
1506
+ 'repo_id': repo_id,
1507
+ 'version_id': version_id,
1508
+ 'trainedWords': trainedWords,
1509
+ })
1510
+ logger.info(f"Added candidate: {candidate_model['filename']} from {repo_name}")
1511
+
1512
+
1513
+ # Exception handling when no candidates are found
1514
+ if not all_candidates:
1209
1515
  if skip_error:
1210
1516
  return None
1211
1517
  else:
1212
- raise ValueError(
1213
- "No model found. Please try changing the word you are searching for."
1214
- )
1215
-
1216
- # Define model file status
1518
+ # Provide helpful error message based on token availability
1519
+ if token:
1520
+ error_msg = (
1521
+ "No model found. Please try changing the search word or filter criteria "
1522
+ "(e.g., base_model, sort). You can also check if your CivitAI token has "
1523
+ "access to the models you're searching for."
1524
+ )
1525
+ else:
1526
+ error_msg = (
1527
+ "No model found. Please try changing the search word or filter criteria. "
1528
+ "If you're looking for private or exclusive models, provide a CivitAI token: "
1529
+ "search_civitai(search_word, token='your_civitai_token')"
1530
+ )
1531
+ raise ValueError(error_msg)
1532
+
1533
+ # Select first candidate for initial metadata
1534
+ selected = all_candidates[0]
1535
+ selected_model = selected['model']
1536
+ repo_name = selected['repo_name']
1537
+ repo_id = selected['repo_id']
1538
+ version_id = selected['version_id']
1539
+ trainedWords = selected['trainedWords']
1540
+
1217
1541
  file_name = selected_model["filename"]
1218
1542
  download_url = selected_model["download_url"]
1219
1543
 
1220
1544
  # Handle file download and setting model information
1221
1545
  if download:
1222
- # Try downloading from the models list, retrying on 401/403 errors
1546
+ # Try downloading from all candidates recursively
1223
1547
  download_success = False
1224
- # Create a sorted list of all available models to try
1225
- sorted_models = sorted(
1226
- models_list, key=lambda x: x["filename"], reverse=True
1227
- )
1228
1548
 
1229
- for model_candidate in sorted_models:
1549
+ logger.info(f"Attempting to download from {len(all_candidates)} candidate(s)...")
1550
+
1551
+ for idx, candidate in enumerate(all_candidates):
1230
1552
  try:
1231
- file_name = model_candidate["filename"]
1232
- download_url = model_candidate["download_url"]
1553
+ candidate_model = candidate['model']
1554
+ file_name = candidate_model["filename"]
1555
+ download_url = candidate_model["download_url"]
1556
+ candidate_repo_id = candidate['repo_id']
1557
+ candidate_version_id = candidate['version_id']
1233
1558
 
1234
- # The path where the model is to be saved.
1235
- model_path = os.path.join(
1236
- str(civitai_cache_dir), str(repo_id), str(version_id), str(file_name)
1559
+ logger.info(f"Attempt {idx + 1}/{len(all_candidates)}: {file_name} from {candidate['repo_name']}")
1560
+
1561
+ # The path where the model is to be saved
1562
+ model_path = _safe_cache_path(
1563
+ civitai_cache_dir,
1564
+ str(candidate_repo_id),
1565
+ str(candidate_version_id),
1566
+ file_name,
1237
1567
  )
1238
1568
 
1239
1569
  # Download Model File
@@ -1246,22 +1576,44 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1246
1576
  headers=headers,
1247
1577
  **kwargs,
1248
1578
  )
1579
+
1580
+ # Update selected metadata on success
1249
1581
  download_success = True
1250
- logger.info(f"Successfully downloaded model from: {download_url}")
1582
+ selected_model = candidate_model
1583
+ repo_name = candidate['repo_name']
1584
+ repo_id = candidate_repo_id
1585
+ version_id = candidate_version_id
1586
+ trainedWords = candidate['trainedWords']
1587
+ file_name = candidate_model["filename"]
1588
+ download_url = candidate_model["download_url"]
1589
+
1590
+ logger.info(f"Successfully downloaded: {file_name} from {repo_name}")
1251
1591
  break
1592
+
1252
1593
  except requests.HTTPError as e:
1253
- if "401" in str(e) or "403" in str(e):
1254
- logger.info(f"Access denied ({e.response.status_code if hasattr(e, 'response') else 'unknown'}) for {download_url}, trying next candidate...")
1255
- continue
1256
- else:
1257
- logger.info(f"HTTP error for {download_url}: {e}, trying next candidate...")
1258
- continue
1594
+ status_code = e.response.status_code if hasattr(e, 'response') else 'unknown'
1595
+ logger.info(f"HTTP error {status_code} for {download_url}, trying next candidate...")
1596
+ continue
1597
+ except Exception as e:
1598
+ logger.info(f"Download failed for {download_url}: {e}, trying next candidate...")
1599
+ continue
1259
1600
 
1260
1601
  if not download_success:
1261
1602
  if skip_error:
1262
1603
  return None
1263
1604
  else:
1264
- raise ValueError(f"Failed to download any model file from {repo_name}. All URLs returned access denied or other errors.")
1605
+ # Show helpful error message based on token availability
1606
+ if token:
1607
+ error_msg = (
1608
+ f"Failed to download any model file after trying {len(all_candidates)} candidate(s). "
1609
+ "All downloads returned errors. Please check your CivitAI token permissions or try different search criteria."
1610
+ )
1611
+ else:
1612
+ error_msg = (
1613
+ f"Failed to download any model file after trying {len(all_candidates)} candidate(s). "
1614
+ "If models require authentication, provide a CivitAI token: search_civitai(search_word, token='your_token')"
1615
+ )
1616
+ raise ValueError(error_msg)
1265
1617
 
1266
1618
  else:
1267
1619
  model_path = download_url
@@ -1307,21 +1659,22 @@ def _load_pipeline_with_retries(cls, pretrained_model_link_or_path, pipeline_map
1307
1659
  max_retries = kwargs.pop('_max_retries', 9)
1308
1660
  failed_count = 0
1309
1661
 
1310
- # Update kwargs to ensure the model is downloaded and parameters are included
1311
- _status = {
1662
+ search_kwargs = {
1663
+ **kwargs,
1312
1664
  "download": True,
1313
1665
  "include_params": True,
1314
1666
  "skip_error": False,
1315
- "pipeline_tag": kwargs.pop('_pipeline_tag', None),
1667
+ "pipeline_tag": kwargs.get("_pipeline_tag"),
1316
1668
  }
1317
- kwargs.update(_status)
1318
1669
 
1319
1670
  # Try each candidate up to max_retries times
1320
1671
  for attempt in range(max_retries + 1):
1321
1672
  # Search for the model on Hugging Face
1322
1673
  try:
1323
1674
  hf_checkpoint_status = search_huggingface(
1324
- pretrained_model_link_or_path, candidate_index=attempt, **kwargs
1675
+ pretrained_model_link_or_path,
1676
+ candidate_index=attempt,
1677
+ **search_kwargs,
1325
1678
  )
1326
1679
  except Exception as e:
1327
1680
  logger.info(f"Candidate {attempt + 1}/{max_retries + 1} search failed: {e}")
@@ -1348,7 +1701,9 @@ def _load_pipeline_with_retries(cls, pretrained_model_link_or_path, pipeline_map
1348
1701
  **kwargs,
1349
1702
  )
1350
1703
  else:
1351
- pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
1704
+ pipeline = cls.from_pretrained(
1705
+ checkpoint_path, **_pipeline_loading_kwargs(kwargs)
1706
+ )
1352
1707
 
1353
1708
  logger.info(
1354
1709
  f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}" # type: ignore
@@ -1388,16 +1743,16 @@ def add_methods(pipeline):
1388
1743
  for attr_name in dir(AutoConfig):
1389
1744
  attr_value = getattr(AutoConfig, attr_name)
1390
1745
  if callable(attr_value) and not attr_name.startswith("__"):
1391
- setattr(pipeline, attr_name, types.MethodType(attr_value, pipeline))
1746
+ setattr(pipeline, attr_name, MethodType(attr_value, pipeline))
1392
1747
  return pipeline
1393
1748
 
1394
1749
 
1395
1750
  class AutoConfig:
1396
1751
  def auto_load_textual_inversion(
1397
1752
  self,
1398
- pretrained_model_name_or_path: Union[str, List[str]],
1399
- token: Optional[Union[str, List[str]]] = None,
1400
- base_model: Optional[Union[str, List[str]]] = None,
1753
+ pretrained_model_name_or_path: Union[str, list[str]],
1754
+ token: Optional[Union[str, list[str]]] = None,
1755
+ base_model: Optional[Union[str, list[str]]] = None,
1401
1756
  tokenizer=None,
1402
1757
  text_encoder=None,
1403
1758
  **kwargs,
@@ -1407,7 +1762,7 @@ class AutoConfig:
1407
1762
  Automatic1111 formats are supported).
1408
1763
 
1409
1764
  Parameters:
1410
- pretrained_model_name_or_path (`str` or `os.PathLike` or `List[str or os.PathLike]` or `Dict` or `List[Dict]`):
1765
+ pretrained_model_name_or_path (`str`, `os.PathLike`, `list`, or `dict`):
1411
1766
  Can be either one of the following or a list of them:
1412
1767
 
1413
1768
  - Search keywords for pretrained model (for example `EasyNegative`).
@@ -1419,7 +1774,7 @@ class AutoConfig:
1419
1774
  - A [torch state
1420
1775
  dict](https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict).
1421
1776
 
1422
- token (`str` or `List[str]`, *optional*):
1777
+ token (`str` or `list[str]`, *optional*):
1423
1778
  Override the token to use for the textual inversion weights. If `pretrained_model_name_or_path` is a
1424
1779
  list, then `token` must also be a list of equal length.
1425
1780
  text_encoder ([`~transformers.CLIPTextModel`], *optional*):
@@ -1440,7 +1795,7 @@ class AutoConfig:
1440
1795
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
1441
1796
  cached versions if they exist.
1442
1797
 
1443
- proxies (`Dict[str, str]`, *optional*):
1798
+ proxies (`dict[str, str]`, *optional*):
1444
1799
  A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
1445
1800
  'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
1446
1801
  local_files_only (`bool`, *optional*, defaults to `False`):
@@ -1546,9 +1901,9 @@ class AutoConfig:
1546
1901
 
1547
1902
  def auto_load_lora_weights(
1548
1903
  self,
1549
- pretrained_model_name_or_path_or_dict: Union[str, Dict[str, torch.Tensor]],
1904
+ pretrained_model_name_or_path_or_dict: Union[str, dict[str, torch.Tensor]],
1550
1905
  adapter_name=None,
1551
- base_model: Optional[Union[str, List[str]]] = None,
1906
+ base_model: Optional[Union[str, list[str]]] = None,
1552
1907
  **kwargs,
1553
1908
  ):
1554
1909
  r"""
@@ -1572,7 +1927,7 @@ class AutoConfig:
1572
1927
  adapter_name (`str`, *optional*):
1573
1928
  Adapter name to be used for referencing the loaded adapter model. If not specified, it will use
1574
1929
  `default_{i}` where i is the total number of adapters being loaded.
1575
- base_model (`str` or `List[str]`, *optional*):
1930
+ base_model (`str` or `list[str]`, *optional*):
1576
1931
  Base model tag(s) to filter LoRA models (e.g., "SD 1.5", "SDXL 1.0"). Used when searching Civitai
1577
1932
  to ensure LoRA compatibility with the current pipeline's base model.
1578
1933
  low_cpu_mem_usage (`bool`, *optional*):
@@ -1608,9 +1963,20 @@ class AutoConfig:
1608
1963
  logger.warning(f"lora_path: {lora_path}")
1609
1964
  pretrained_model_name_or_path_or_dict = lora_path
1610
1965
 
1611
- self.load_lora_weights(
1612
- pretrained_model_name_or_path_or_dict, adapter_name=adapter_name, **kwargs
1613
- )
1966
+ try:
1967
+ self.load_lora_weights(
1968
+ pretrained_model_name_or_path_or_dict,
1969
+ adapter_name=adapter_name,
1970
+ **kwargs,
1971
+ )
1972
+ except ImportError as error:
1973
+ if "incompatible version of torchao" in str(error):
1974
+ raise ImportError(
1975
+ "The installed torchao version is incompatible with PEFT. "
1976
+ "If torchao quantization is not needed, uninstall torchao and restart the runtime. "
1977
+ "Otherwise install mutually compatible PyTorch, PEFT, and torchao versions."
1978
+ ) from error
1979
+ raise
1614
1980
 
1615
1981
 
1616
1982
  class EasyPipelineForText2Image(AutoPipelineForText2Image):
@@ -1654,9 +2020,8 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1654
2020
  The format of the model checkpoint.
1655
2021
  pipeline_tag (`str`, *optional*):
1656
2022
  Tag to filter models by pipeline.
1657
- torch_dtype (`str` or `torch.dtype`, *optional*):
1658
- Override the default `torch.dtype` and load the model with another dtype. If "auto" is passed, the
1659
- dtype is automatically derived from the model's weights.
2023
+ dtype (`torch.dtype` or `dict`, *optional*):
2024
+ Override the default dtype. `torch_dtype` remains accepted for compatibility.
1660
2025
  force_download (`bool`, *optional*, defaults to `False`):
1661
2026
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
1662
2027
  cached versions if they exist.
@@ -1664,7 +2029,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1664
2029
  Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
1665
2030
  is not used.
1666
2031
 
1667
- proxies (`Dict[str, str]`, *optional*):
2032
+ proxies (`dict[str, str]`, *optional*):
1668
2033
  A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
1669
2034
  'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
1670
2035
  output_loading_info(`bool`, *optional*, defaults to `False`):
@@ -1686,7 +2051,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1686
2051
  Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
1687
2052
  guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
1688
2053
  information.
1689
- device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
2054
+ device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
1690
2055
  A map that specifies where each submodule should go. It doesn’t need to be defined for each
1691
2056
  parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
1692
2057
  same device.
@@ -1694,7 +2059,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1694
2059
  Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
1695
2060
  more information about each option see [designing a device
1696
2061
  map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
1697
- max_memory (`Dict`, *optional*):
2062
+ max_memory (`dict`, *optional*):
1698
2063
  A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
1699
2064
  each GPU and the available CPU RAM if unset.
1700
2065
  offload_folder (`str` or `os.PathLike`, *optional*):
@@ -1780,9 +2145,8 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1780
2145
  Path to the folder where cached files are stored.
1781
2146
  resume (`bool`, *optional*, defaults to `False`):
1782
2147
  Whether to resume an incomplete download.
1783
- torch_dtype (`str` or `torch.dtype`, *optional*):
1784
- Override the default `torch.dtype` and load the model with another dtype. If "auto" is passed, the
1785
- dtype is automatically derived from the model's weights.
2148
+ dtype (`torch.dtype` or `dict`, *optional*):
2149
+ Override the default dtype. `torch_dtype` remains accepted for compatibility.
1786
2150
  force_download (`bool`, *optional*, defaults to `False`):
1787
2151
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
1788
2152
  cached versions if they exist.
@@ -1793,7 +2157,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1793
2157
  won't be downloaded from the Hub.
1794
2158
  token (`str`, *optional*):
1795
2159
  The token to use as HTTP bearer authorization for remote files.
1796
- device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
2160
+ device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
1797
2161
  A map that specifies where each submodule should go. It doesn’t need to be defined for each
1798
2162
  parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
1799
2163
  same device.
@@ -1801,7 +2165,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1801
2165
  Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
1802
2166
  more information about each option see [designing a device
1803
2167
  map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
1804
- max_memory (`Dict`, *optional*):
2168
+ max_memory (`dict`, *optional*):
1805
2169
  A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
1806
2170
  each GPU and the available CPU RAM if unset.
1807
2171
  offload_folder (`str` or `os.PathLike`, *optional*):
@@ -1905,9 +2269,8 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1905
2269
  The format of the model checkpoint.
1906
2270
  pipeline_tag (`str`, *optional*):
1907
2271
  Tag to filter models by pipeline.
1908
- torch_dtype (`str` or `torch.dtype`, *optional*):
1909
- Override the default `torch.dtype` and load the model with another dtype. If "auto" is passed, the
1910
- dtype is automatically derived from the model's weights.
2272
+ dtype (`torch.dtype` or `dict`, *optional*):
2273
+ Override the default dtype. `torch_dtype` remains accepted for compatibility.
1911
2274
  force_download (`bool`, *optional*, defaults to `False`):
1912
2275
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
1913
2276
  cached versions if they exist.
@@ -1915,7 +2278,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1915
2278
  Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
1916
2279
  is not used.
1917
2280
 
1918
- proxies (`Dict[str, str]`, *optional*):
2281
+ proxies (`dict[str, str]`, *optional*):
1919
2282
  A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
1920
2283
  'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
1921
2284
  output_loading_info(`bool`, *optional*, defaults to `False`):
@@ -1937,7 +2300,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1937
2300
  Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
1938
2301
  guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
1939
2302
  information.
1940
- device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
2303
+ device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
1941
2304
  A map that specifies where each submodule should go. It doesn’t need to be defined for each
1942
2305
  parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
1943
2306
  same device.
@@ -1945,7 +2308,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1945
2308
  Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
1946
2309
  more information about each option see [designing a device
1947
2310
  map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
1948
- max_memory (`Dict`, *optional*):
2311
+ max_memory (`dict`, *optional*):
1949
2312
  A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
1950
2313
  each GPU and the available CPU RAM if unset.
1951
2314
  offload_folder (`str` or `os.PathLike`, *optional*):
@@ -2022,9 +2385,8 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
2022
2385
  Path to the folder where cached files are stored.
2023
2386
  resume (`bool`, *optional*, defaults to `False`):
2024
2387
  Whether to resume an incomplete download.
2025
- torch_dtype (`str` or `torch.dtype`, *optional*):
2026
- Override the default `torch.dtype` and load the model with another dtype. If "auto" is passed, the
2027
- dtype is automatically derived from the model's weights.
2388
+ dtype (`torch.dtype` or `dict`, *optional*):
2389
+ Override the default dtype. `torch_dtype` remains accepted for compatibility.
2028
2390
  force_download (`bool`, *optional*, defaults to `False`):
2029
2391
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
2030
2392
  cached versions if they exist.
@@ -2035,7 +2397,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
2035
2397
  won't be downloaded from the Hub.
2036
2398
  token (`str`, *optional*):
2037
2399
  The token to use as HTTP bearer authorization for remote files.
2038
- device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
2400
+ device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
2039
2401
  A map that specifies where each submodule should go. It doesn’t need to be defined for each
2040
2402
  parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
2041
2403
  same device.
@@ -2043,7 +2405,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
2043
2405
  Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
2044
2406
  more information about each option see [designing a device
2045
2407
  map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
2046
- max_memory (`Dict`, *optional*):
2408
+ max_memory (`dict`, *optional*):
2047
2409
  A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
2048
2410
  each GPU and the available CPU RAM if unset.
2049
2411
  offload_folder (`str` or `os.PathLike`, *optional*):
@@ -2147,9 +2509,8 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
2147
2509
  The format of the model checkpoint.
2148
2510
  pipeline_tag (`str`, *optional*):
2149
2511
  Tag to filter models by pipeline.
2150
- torch_dtype (`str` or `torch.dtype`, *optional*):
2151
- Override the default `torch.dtype` and load the model with another dtype. If "auto" is passed, the
2152
- dtype is automatically derived from the model's weights.
2512
+ dtype (`torch.dtype` or `dict`, *optional*):
2513
+ Override the default dtype. `torch_dtype` remains accepted for compatibility.
2153
2514
  force_download (`bool`, *optional*, defaults to `False`):
2154
2515
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
2155
2516
  cached versions if they exist.
@@ -2157,7 +2518,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
2157
2518
  Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
2158
2519
  is not used.
2159
2520
 
2160
- proxies (`Dict[str, str]`, *optional*):
2521
+ proxies (`dict[str, str]`, *optional*):
2161
2522
  A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
2162
2523
  'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
2163
2524
  output_loading_info(`bool`, *optional*, defaults to `False`):
@@ -2179,7 +2540,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
2179
2540
  Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
2180
2541
  guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
2181
2542
  information.
2182
- device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
2543
+ device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
2183
2544
  A map that specifies where each submodule should go. It doesn’t need to be defined for each
2184
2545
  parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
2185
2546
  same device.
@@ -2187,7 +2548,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
2187
2548
  Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
2188
2549
  more information about each option see [designing a device
2189
2550
  map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
2190
- max_memory (`Dict`, *optional*):
2551
+ max_memory (`dict`, *optional*):
2191
2552
  A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
2192
2553
  each GPU and the available CPU RAM if unset.
2193
2554
  offload_folder (`str` or `os.PathLike`, *optional*):
@@ -2264,9 +2625,8 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
2264
2625
  Path to the folder where cached files are stored.
2265
2626
  resume (`bool`, *optional*, defaults to `False`):
2266
2627
  Whether to resume an incomplete download.
2267
- torch_dtype (`str` or `torch.dtype`, *optional*):
2268
- Override the default `torch.dtype` and load the model with another dtype. If "auto" is passed, the
2269
- dtype is automatically derived from the model's weights.
2628
+ dtype (`torch.dtype` or `dict`, *optional*):
2629
+ Override the default dtype. `torch_dtype` remains accepted for compatibility.
2270
2630
  force_download (`bool`, *optional*, defaults to `False`):
2271
2631
  Whether or not to force the (re-)download of the model weights and configuration files, overriding the
2272
2632
  cached versions if they exist.
@@ -2277,7 +2637,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
2277
2637
  won't be downloaded from the Hub.
2278
2638
  token (`str`, *optional*):
2279
2639
  The token to use as HTTP bearer authorization for remote files.
2280
- device_map (`str` or `Dict[str, Union[int, str, torch.device]]`, *optional*):
2640
+ device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
2281
2641
  A map that specifies where each submodule should go. It doesn’t need to be defined for each
2282
2642
  parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
2283
2643
  same device.
@@ -2285,7 +2645,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
2285
2645
  Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
2286
2646
  more information about each option see [designing a device
2287
2647
  map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
2288
- max_memory (`Dict`, *optional*):
2648
+ max_memory (`dict`, *optional*):
2289
2649
  A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
2290
2650
  each GPU and the available CPU RAM if unset.
2291
2651
  offload_folder (`str` or `os.PathLike`, *optional*):