auto-diffusers 2.0.36.dev1__py3-none-any.whl → 2.0.38__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.
- auto_diffusers/__init__.py +15 -6
- auto_diffusers/pipeline_easy.py +468 -429
- {auto_diffusers-2.0.36.dev1.dist-info → auto_diffusers-2.0.38.dist-info}/METADATA +63 -45
- auto_diffusers-2.0.38.dist-info/RECORD +8 -0
- {auto_diffusers-2.0.36.dev1.dist-info → auto_diffusers-2.0.38.dist-info}/WHEEL +1 -1
- auto_diffusers-2.0.36.dev1.dist-info/RECORD +0 -8
- {auto_diffusers-2.0.36.dev1.dist-info → auto_diffusers-2.0.38.dist-info}/licenses/LICENSE +0 -0
- {auto_diffusers-2.0.36.dev1.dist-info → auto_diffusers-2.0.38.dist-info}/top_level.txt +0 -0
auto_diffusers/pipeline_easy.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
1
|
# Copyright 2026 suzukimain
|
|
3
2
|
#
|
|
4
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -13,17 +12,26 @@
|
|
|
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
|
+
|
|
16
17
|
# Standard library imports
|
|
17
18
|
import os
|
|
18
19
|
import re
|
|
19
|
-
import types
|
|
20
20
|
from collections import OrderedDict
|
|
21
21
|
from dataclasses import asdict, dataclass, field
|
|
22
|
-
from
|
|
22
|
+
from types import MethodType
|
|
23
|
+
from typing import Optional, Union
|
|
24
|
+
from urllib.parse import urlparse
|
|
23
25
|
|
|
24
26
|
# Third-party imports
|
|
25
27
|
import requests
|
|
26
28
|
import torch
|
|
29
|
+
from diffusers import (
|
|
30
|
+
StableDiffusionInpaintPipeline,
|
|
31
|
+
StableDiffusionUpscalePipeline,
|
|
32
|
+
StableDiffusionXLInpaintPipeline,
|
|
33
|
+
)
|
|
34
|
+
from diffusers import __version__ as diffusers_version
|
|
27
35
|
|
|
28
36
|
# Diffusers core imports
|
|
29
37
|
from diffusers.loaders.single_file_utils import (
|
|
@@ -42,45 +50,21 @@ from diffusers.pipelines.auto_pipeline import (
|
|
|
42
50
|
)
|
|
43
51
|
from diffusers.pipelines.pipeline_utils import DiffusionPipeline
|
|
44
52
|
from diffusers.utils import logging
|
|
45
|
-
|
|
46
|
-
# Stable Diffusion v1/v2 pipelines
|
|
47
|
-
from diffusers import (
|
|
48
|
-
StableDiffusionImg2ImgPipeline,
|
|
49
|
-
StableDiffusionInpaintPipeline,
|
|
50
|
-
StableDiffusionPipeline,
|
|
51
|
-
StableDiffusionUpscalePipeline,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
# Stable Diffusion XL pipelines
|
|
55
|
-
from diffusers import (
|
|
56
|
-
StableDiffusionXLControlNetImg2ImgPipeline,
|
|
57
|
-
StableDiffusionXLControlNetInpaintPipeline,
|
|
58
|
-
StableDiffusionXLControlNetPipeline,
|
|
59
|
-
StableDiffusionXLImg2ImgPipeline,
|
|
60
|
-
StableDiffusionXLInpaintPipeline,
|
|
61
|
-
StableDiffusionXLPipeline,
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
# Stable Diffusion 3 pipelines
|
|
65
|
-
from diffusers import (
|
|
66
|
-
StableDiffusion3Img2ImgPipeline,
|
|
67
|
-
StableDiffusion3InpaintPipeline,
|
|
68
|
-
StableDiffusion3Pipeline,
|
|
69
|
-
)
|
|
53
|
+
from packaging.version import Version
|
|
70
54
|
|
|
71
55
|
# Flux pipelines (import separately to avoid Flax deprecation warnings)
|
|
72
56
|
try:
|
|
73
57
|
from diffusers.pipelines.flux import (
|
|
74
|
-
FluxImg2ImgPipeline,
|
|
75
|
-
FluxInpaintPipeline,
|
|
76
|
-
FluxPipeline,
|
|
77
58
|
FluxControlImg2ImgPipeline,
|
|
78
59
|
FluxControlInpaintPipeline,
|
|
79
60
|
FluxControlNetImg2ImgPipeline,
|
|
80
61
|
FluxControlNetInpaintPipeline,
|
|
81
62
|
FluxControlNetPipeline,
|
|
82
63
|
FluxControlPipeline,
|
|
64
|
+
FluxImg2ImgPipeline,
|
|
65
|
+
FluxInpaintPipeline,
|
|
83
66
|
FluxKontextPipeline,
|
|
67
|
+
FluxPipeline,
|
|
84
68
|
)
|
|
85
69
|
except ImportError:
|
|
86
70
|
FluxImg2ImgPipeline = None
|
|
@@ -94,13 +78,6 @@ except ImportError:
|
|
|
94
78
|
FluxControlPipeline = None
|
|
95
79
|
FluxKontextPipeline = None
|
|
96
80
|
|
|
97
|
-
# ControlNet pipelines
|
|
98
|
-
from diffusers import (
|
|
99
|
-
StableDiffusionControlNetImg2ImgPipeline,
|
|
100
|
-
StableDiffusionControlNetInpaintPipeline,
|
|
101
|
-
StableDiffusionControlNetPipeline,
|
|
102
|
-
)
|
|
103
|
-
|
|
104
81
|
# AnimateDiff pipelines
|
|
105
82
|
from diffusers import (
|
|
106
83
|
AnimateDiffPipeline,
|
|
@@ -116,14 +93,14 @@ try:
|
|
|
116
93
|
CogView4ControlPipeline,
|
|
117
94
|
CogView4Pipeline,
|
|
118
95
|
HunyuanDiTPipeline,
|
|
96
|
+
Kandinsky3Img2ImgPipeline,
|
|
97
|
+
Kandinsky3Pipeline,
|
|
119
98
|
KandinskyCombinedPipeline,
|
|
120
99
|
KandinskyImg2ImgCombinedPipeline,
|
|
121
100
|
KandinskyInpaintCombinedPipeline,
|
|
122
101
|
KandinskyV22CombinedPipeline,
|
|
123
102
|
KandinskyV22Img2ImgCombinedPipeline,
|
|
124
103
|
KandinskyV22InpaintCombinedPipeline,
|
|
125
|
-
Kandinsky3Img2ImgPipeline,
|
|
126
|
-
Kandinsky3Pipeline,
|
|
127
104
|
LatentConsistencyModelImg2ImgPipeline,
|
|
128
105
|
LatentConsistencyModelPipeline,
|
|
129
106
|
Lumina2Pipeline,
|
|
@@ -204,273 +181,167 @@ from huggingface_hub import hf_api, hf_hub_download, hf_hub_url
|
|
|
204
181
|
from huggingface_hub.file_download import http_get
|
|
205
182
|
from huggingface_hub.utils import validate_hf_hub_args
|
|
206
183
|
|
|
207
|
-
|
|
208
184
|
logger = logging.get_logger(__name__)
|
|
209
185
|
|
|
210
|
-
# Suppress verbose warnings from dependencies
|
|
211
|
-
logging.set_verbosity_error()
|
|
212
|
-
# Reduce logging level for torchao
|
|
213
|
-
try:
|
|
214
|
-
import logging as std_logging
|
|
215
|
-
std_logging.getLogger("torchao").setLevel(std_logging.WARNING)
|
|
216
|
-
std_logging.getLogger("torchao.kernel.intmm").setLevel(std_logging.ERROR)
|
|
217
|
-
except Exception:
|
|
218
|
-
pass
|
|
219
|
-
|
|
220
186
|
|
|
221
|
-
|
|
187
|
+
SINGLE_FILE_MODEL_TYPE_TO_AUTO_PIPELINE_KEY = OrderedDict(
|
|
222
188
|
[
|
|
223
|
-
("
|
|
224
|
-
("
|
|
225
|
-
("
|
|
226
|
-
("
|
|
227
|
-
("
|
|
228
|
-
("
|
|
229
|
-
("
|
|
230
|
-
("
|
|
231
|
-
("
|
|
232
|
-
("
|
|
233
|
-
("
|
|
234
|
-
("
|
|
235
|
-
("
|
|
236
|
-
("
|
|
237
|
-
("
|
|
238
|
-
("
|
|
239
|
-
("
|
|
240
|
-
("
|
|
241
|
-
("
|
|
242
|
-
("
|
|
243
|
-
("
|
|
244
|
-
("
|
|
245
|
-
("
|
|
246
|
-
("
|
|
247
|
-
("
|
|
248
|
-
("
|
|
249
|
-
("
|
|
250
|
-
("
|
|
251
|
-
("
|
|
252
|
-
("
|
|
253
|
-
("
|
|
254
|
-
("
|
|
255
|
-
("
|
|
256
|
-
("
|
|
257
|
-
("
|
|
258
|
-
("
|
|
259
|
-
("
|
|
260
|
-
("
|
|
261
|
-
("
|
|
262
|
-
("
|
|
263
|
-
("
|
|
264
|
-
("
|
|
265
|
-
("
|
|
266
|
-
|
|
267
|
-
("kandinsky22", KandinskyV22CombinedPipeline),
|
|
268
|
-
("kandinsky3", Kandinsky3Pipeline),
|
|
269
|
-
("lcm", LatentConsistencyModelPipeline),
|
|
270
|
-
("lumina", LuminaPipeline),
|
|
271
|
-
("lumina2", Lumina2Pipeline),
|
|
272
|
-
("ltx-video", None),
|
|
273
|
-
("ltx-video-0.9.1", None),
|
|
274
|
-
("ltx-video-0.9.5", None),
|
|
275
|
-
("ltx-video-0.9.7", None),
|
|
276
|
-
("mochi-1-preview", None),
|
|
277
|
-
("ovis", OvisImagePipeline),
|
|
278
|
-
("pixart-alpha", PixArtAlphaPipeline),
|
|
279
|
-
("pixart-sigma", PixArtSigmaPipeline),
|
|
280
|
-
("playground-v2-5", StableDiffusionXLPipeline),
|
|
281
|
-
("qwenimage", QwenImagePipeline),
|
|
282
|
-
("qwenimage-controlnet", QwenImageControlNetPipeline),
|
|
283
|
-
("sana", SanaPipeline),
|
|
284
|
-
("sd3", StableDiffusion3Pipeline),
|
|
285
|
-
("sd35_large", StableDiffusion3Pipeline),
|
|
286
|
-
("sd35_medium", StableDiffusion3Pipeline),
|
|
287
|
-
("sd3-controlnet", StableDiffusion3ControlNetPipeline),
|
|
288
|
-
("stable_cascade_stage_b", None),
|
|
289
|
-
("stable_cascade_stage_b_lite", None),
|
|
290
|
-
("stable_cascade_stage_c", None),
|
|
291
|
-
("stable_cascade_stage_c_lite", None),
|
|
292
|
-
("upscale", StableDiffusionUpscalePipeline),
|
|
293
|
-
("v1", StableDiffusionPipeline),
|
|
294
|
-
("v2", StableDiffusionPipeline),
|
|
295
|
-
("wan-i2v-14B", WanImageToVideoPipeline),
|
|
296
|
-
("wan-t2v-1.3B", WanPipeline),
|
|
297
|
-
("wan-t2v-14B", WanPipeline),
|
|
298
|
-
("wan-vace-1.3B", WanVideoToVideoPipeline),
|
|
299
|
-
("wan-vace-14B", WanVideoToVideoPipeline),
|
|
300
|
-
("xl_base", StableDiffusionXLPipeline),
|
|
301
|
-
("xl_refiner", StableDiffusionXLPipeline),
|
|
302
|
-
("z-image", ZImagePipeline),
|
|
303
|
-
("z-image-controlnet", ZImageControlNetPipeline),
|
|
304
|
-
("z-image-omni", ZImageOmniPipeline),
|
|
305
|
-
("z-image-turbo", None),
|
|
306
|
-
("z-image-turbo-controlnet", None),
|
|
307
|
-
("z-image-turbo-controlnet-2.0", None),
|
|
308
|
-
("z-image-turbo-controlnet-2.1", None),
|
|
309
|
-
],
|
|
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
|
+
]
|
|
310
233
|
)
|
|
311
234
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
+
)
|
|
316
265
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
("lumina", None),
|
|
361
|
-
("lumina2", None),
|
|
362
|
-
("ltx-video", None),
|
|
363
|
-
("ltx-video-0.9.1", None),
|
|
364
|
-
("ltx-video-0.9.5", None),
|
|
365
|
-
("ltx-video-0.9.7", None),
|
|
366
|
-
("mochi-1-preview", None),
|
|
367
|
-
("playground-v2-5", StableDiffusionXLImg2ImgPipeline),
|
|
368
|
-
("qwenimage", QwenImageImg2ImgPipeline),
|
|
369
|
-
("qwenimage-edit", QwenImageEditPipeline),
|
|
370
|
-
("qwenimage-edit-plus", QwenImageEditPlusPipeline),
|
|
371
|
-
("qwenimage-layered", QwenImageLayeredPipeline),
|
|
372
|
-
("sana", None),
|
|
373
|
-
("sd3", StableDiffusion3Img2ImgPipeline),
|
|
374
|
-
("sd35_large", StableDiffusion3Img2ImgPipeline),
|
|
375
|
-
("sd35_medium", StableDiffusion3Img2ImgPipeline),
|
|
376
|
-
("stable_cascade_stage_b", None),
|
|
377
|
-
("stable_cascade_stage_b_lite", None),
|
|
378
|
-
("stable_cascade_stage_c", None),
|
|
379
|
-
("stable_cascade_stage_c_lite", None),
|
|
380
|
-
("upscale", StableDiffusionUpscalePipeline),
|
|
381
|
-
("v1", StableDiffusionImg2ImgPipeline),
|
|
382
|
-
("v2", StableDiffusionImg2ImgPipeline),
|
|
383
|
-
("wan-i2v-14B", WanImageToVideoPipeline),
|
|
384
|
-
("wan-t2v-1.3B", None),
|
|
385
|
-
("wan-t2v-14B", None),
|
|
386
|
-
("wan-vace-1.3B", WanVideoToVideoPipeline),
|
|
387
|
-
("wan-vace-14B", WanVideoToVideoPipeline),
|
|
388
|
-
("xl_base", StableDiffusionXLImg2ImgPipeline),
|
|
389
|
-
("xl_refiner", StableDiffusionXLImg2ImgPipeline),
|
|
390
|
-
("z-image", ZImageImg2ImgPipeline),
|
|
391
|
-
("z-image-turbo", None),
|
|
392
|
-
("z-image-turbo-controlnet", None),
|
|
393
|
-
("z-image-turbo-controlnet-2.0", None),
|
|
394
|
-
("z-image-turbo-controlnet-2.1", None),
|
|
395
|
-
]
|
|
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
|
+
},
|
|
396
309
|
)
|
|
397
310
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
("hunyuan-video", None),
|
|
433
|
-
("inpainting", StableDiffusionInpaintPipeline),
|
|
434
|
-
("inpainting_v2", StableDiffusionInpaintPipeline),
|
|
435
|
-
("instruct-pix2pix", None),
|
|
436
|
-
("kandinsky", KandinskyInpaintCombinedPipeline),
|
|
437
|
-
("kandinsky22", KandinskyV22InpaintCombinedPipeline),
|
|
438
|
-
("lcm", None),
|
|
439
|
-
("lumina", None),
|
|
440
|
-
("lumina2", None),
|
|
441
|
-
("ltx-video", None),
|
|
442
|
-
("ltx-video-0.9.1", None),
|
|
443
|
-
("ltx-video-0.9.5", None),
|
|
444
|
-
("ltx-video-0.9.7", None),
|
|
445
|
-
("mochi-1-preview", None),
|
|
446
|
-
("playground-v2-5", None),
|
|
447
|
-
("qwenimage", QwenImageInpaintPipeline),
|
|
448
|
-
("qwenimage-edit", QwenImageEditInpaintPipeline),
|
|
449
|
-
("sana", None),
|
|
450
|
-
("sd3", StableDiffusion3InpaintPipeline),
|
|
451
|
-
("sd35_large", StableDiffusion3InpaintPipeline),
|
|
452
|
-
("sd35_medium", StableDiffusion3InpaintPipeline),
|
|
453
|
-
("sd3-controlnet", StableDiffusion3ControlNetInpaintingPipeline),
|
|
454
|
-
("stable_cascade_stage_b", None),
|
|
455
|
-
("stable_cascade_stage_b_lite", None),
|
|
456
|
-
("stable_cascade_stage_c", None),
|
|
457
|
-
("stable_cascade_stage_c_lite", None),
|
|
458
|
-
("upscale", StableDiffusionUpscalePipeline),
|
|
459
|
-
("v1", StableDiffusionInpaintPipeline),
|
|
460
|
-
("v2", StableDiffusionInpaintPipeline),
|
|
461
|
-
("wan-i2v-14B", None),
|
|
462
|
-
("wan-t2v-1.3B", None),
|
|
463
|
-
("wan-t2v-14B", None),
|
|
464
|
-
("wan-vace-1.3B", None),
|
|
465
|
-
("wan-vace-14B", None),
|
|
466
|
-
("xl_base", StableDiffusionXLInpaintPipeline),
|
|
467
|
-
("xl_inpaint", StableDiffusionXLInpaintPipeline),
|
|
468
|
-
("z-image-controlnet-inpaint", ZImageControlNetInpaintPipeline),
|
|
469
|
-
("z-image-turbo", None),
|
|
470
|
-
("z-image-turbo-controlnet", None),
|
|
471
|
-
("z-image-turbo-controlnet-2.0", None),
|
|
472
|
-
("z-image-turbo-controlnet-2.1", None),
|
|
473
|
-
]
|
|
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
|
+
},
|
|
474
345
|
)
|
|
475
346
|
|
|
476
347
|
CONFIG_FILE_LIST = [
|
|
@@ -525,17 +396,17 @@ TOKENIZER_SHAPE_MAP = {
|
|
|
525
396
|
}
|
|
526
397
|
|
|
527
398
|
|
|
528
|
-
def get_allowed_extensions(allow_unsafe_formats: bool =
|
|
399
|
+
def get_allowed_extensions(allow_unsafe_formats: bool = False) -> list[str]:
|
|
529
400
|
r"""
|
|
530
401
|
Get the list of allowed file extensions based on safety preferences.
|
|
531
402
|
|
|
532
403
|
Parameters:
|
|
533
|
-
allow_unsafe_formats (`bool`, *optional*, defaults to `
|
|
534
|
-
If True
|
|
535
|
-
If False, only allows .safetensors format
|
|
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.
|
|
536
407
|
|
|
537
408
|
Returns:
|
|
538
|
-
`
|
|
409
|
+
`list[str]`: List of allowed file extensions.
|
|
539
410
|
"""
|
|
540
411
|
if allow_unsafe_formats:
|
|
541
412
|
return [".safetensors", ".ckpt", ".bin"]
|
|
@@ -547,6 +418,82 @@ def get_allowed_extensions(allow_unsafe_formats: bool = True) -> List[str]:
|
|
|
547
418
|
EXTENSION = [".safetensors", ".ckpt", ".bin"]
|
|
548
419
|
|
|
549
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
|
+
|
|
464
|
+
|
|
465
|
+
def _validate_remote_url(url, allowed_hosts=ALLOWED_DOWNLOAD_HOSTS):
|
|
466
|
+
parsed = urlparse(str(url))
|
|
467
|
+
host = (parsed.hostname or "").lower()
|
|
468
|
+
|
|
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
|
|
550
497
|
|
|
551
498
|
|
|
552
499
|
@dataclass
|
|
@@ -603,7 +550,7 @@ class ExtraStatus:
|
|
|
603
550
|
The words used to trigger the model
|
|
604
551
|
"""
|
|
605
552
|
|
|
606
|
-
trained_words: Union[
|
|
553
|
+
trained_words: Union[list[str], None] = None
|
|
607
554
|
|
|
608
555
|
|
|
609
556
|
@dataclass
|
|
@@ -649,15 +596,15 @@ def load_pipeline_from_single_file(
|
|
|
649
596
|
pipeline_mapping (`dict`):
|
|
650
597
|
A mapping of model types to their corresponding pipeline classes. This is used to determine
|
|
651
598
|
which pipeline class to instantiate based on the model type inferred from the checkpoint.
|
|
652
|
-
|
|
653
|
-
Override the default
|
|
599
|
+
dtype (`torch.dtype` or `dict`, *optional*):
|
|
600
|
+
Override the default dtype. `torch_dtype` remains accepted for compatibility.
|
|
654
601
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
655
602
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
656
603
|
cached versions if they exist.
|
|
657
604
|
cache_dir (`Union[str, os.PathLike]`, *optional*):
|
|
658
605
|
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
|
|
659
606
|
is not used.
|
|
660
|
-
proxies (`
|
|
607
|
+
proxies (`dict[str, str]`, *optional*):
|
|
661
608
|
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
|
|
662
609
|
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
|
663
610
|
local_files_only (`bool`, *optional*, defaults to `False`):
|
|
@@ -692,8 +639,9 @@ def load_pipeline_from_single_file(
|
|
|
692
639
|
# Infer the model type from the loaded checkpoint
|
|
693
640
|
model_type = infer_diffusers_model_type(checkpoint)
|
|
694
641
|
|
|
695
|
-
# Get the corresponding pipeline class from the
|
|
696
|
-
|
|
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)
|
|
697
645
|
|
|
698
646
|
# For tasks not supported by this pipeline
|
|
699
647
|
if pipeline_class is None:
|
|
@@ -706,7 +654,9 @@ def load_pipeline_from_single_file(
|
|
|
706
654
|
|
|
707
655
|
else:
|
|
708
656
|
# Load the pipeline from the checkpoint
|
|
709
|
-
return pipeline_class.from_single_file(
|
|
657
|
+
return pipeline_class.from_single_file(
|
|
658
|
+
pretrained_model_or_path, **_pipeline_loading_kwargs(kwargs)
|
|
659
|
+
)
|
|
710
660
|
|
|
711
661
|
|
|
712
662
|
def get_keyword_types(keyword):
|
|
@@ -742,6 +692,11 @@ def get_keyword_types(keyword):
|
|
|
742
692
|
# Check if the keyword is an HTTP or HTTPS URL
|
|
743
693
|
status["extra_type"]["url"] = bool(re.search(r"^(https?)://", keyword))
|
|
744
694
|
|
|
695
|
+
is_supported_url = any(
|
|
696
|
+
keyword.startswith(prefix)
|
|
697
|
+
for prefix in VALID_URL_PREFIXES
|
|
698
|
+
)
|
|
699
|
+
|
|
745
700
|
# Check if the keyword is a file
|
|
746
701
|
if os.path.isfile(keyword):
|
|
747
702
|
status["type"]["local"] = True
|
|
@@ -769,7 +724,7 @@ def get_keyword_types(keyword):
|
|
|
769
724
|
status["loading_method"] = None
|
|
770
725
|
|
|
771
726
|
# Check if the keyword starts with any valid URL prefixes
|
|
772
|
-
elif
|
|
727
|
+
elif is_supported_url:
|
|
773
728
|
repo_id, weights_name = _extract_repo_id_and_weights_name(keyword)
|
|
774
729
|
if weights_name:
|
|
775
730
|
status["type"]["hf_url"] = True
|
|
@@ -798,8 +753,8 @@ def get_keyword_types(keyword):
|
|
|
798
753
|
def validate_url_with_head(
|
|
799
754
|
url: str,
|
|
800
755
|
token: Optional[str] = None,
|
|
801
|
-
headers: Optional[
|
|
802
|
-
timeout: int =
|
|
756
|
+
headers: Optional[dict] = None,
|
|
757
|
+
timeout: int = 10,
|
|
803
758
|
) -> None:
|
|
804
759
|
"""
|
|
805
760
|
Validates a URL is accessible by performing a HEAD request.
|
|
@@ -820,6 +775,8 @@ def validate_url_with_head(
|
|
|
820
775
|
Raises:
|
|
821
776
|
requests.HTTPError: If the URL returns any 4xx or 5xx status code.
|
|
822
777
|
"""
|
|
778
|
+
_validate_remote_url(url)
|
|
779
|
+
|
|
823
780
|
if headers is None:
|
|
824
781
|
headers = {}
|
|
825
782
|
else:
|
|
@@ -828,11 +785,17 @@ def validate_url_with_head(
|
|
|
828
785
|
|
|
829
786
|
# If token is provided and authorization not already in headers, add it
|
|
830
787
|
# Check case-insensitively since HTTP headers are case-insensitive
|
|
831
|
-
|
|
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:
|
|
832
794
|
headers["Authorization"] = f"Bearer {token}"
|
|
833
795
|
|
|
834
796
|
try:
|
|
835
797
|
response = requests.head(url, headers=headers, allow_redirects=True, timeout=timeout)
|
|
798
|
+
_validate_remote_url(response.url)
|
|
836
799
|
# Raise HTTPError for any 4xx/5xx status codes (including 401)
|
|
837
800
|
response.raise_for_status()
|
|
838
801
|
except requests.HTTPError:
|
|
@@ -872,6 +835,8 @@ def file_downloader(
|
|
|
872
835
|
None
|
|
873
836
|
"""
|
|
874
837
|
|
|
838
|
+
_validate_remote_url(url)
|
|
839
|
+
|
|
875
840
|
# Get optional parameters from kwargs, with their default values
|
|
876
841
|
resume = kwargs.pop("resume", False)
|
|
877
842
|
headers = kwargs.pop("headers", None)
|
|
@@ -997,6 +962,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
|
|
|
997
962
|
search_word_status = get_keyword_types(search_word)
|
|
998
963
|
|
|
999
964
|
if search_word_status["type"]["hf_repo"]:
|
|
965
|
+
repo_id = search_word
|
|
1000
966
|
hf_repo_info = asdict(
|
|
1001
967
|
hf_api.model_info(repo_id=search_word, securityStatus=True)
|
|
1002
968
|
)
|
|
@@ -1017,6 +983,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
|
|
|
1017
983
|
model_path = hf_hub_download(
|
|
1018
984
|
repo_id=repo_id,
|
|
1019
985
|
filename=weights_name,
|
|
986
|
+
revision=revision,
|
|
1020
987
|
token=token,
|
|
1021
988
|
force_download=force_download,
|
|
1022
989
|
cache_dir=cache_dir,
|
|
@@ -1036,7 +1003,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
|
|
|
1036
1003
|
# Get model data from HF API
|
|
1037
1004
|
hf_models = hf_api.list_models(
|
|
1038
1005
|
search=search_word,
|
|
1039
|
-
|
|
1006
|
+
sort="downloads",
|
|
1040
1007
|
limit=100,
|
|
1041
1008
|
fetch_config=True,
|
|
1042
1009
|
pipeline_tag=pipeline_tag,
|
|
@@ -1044,7 +1011,9 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
|
|
|
1044
1011
|
gated=gated,
|
|
1045
1012
|
token=token,
|
|
1046
1013
|
)
|
|
1047
|
-
model_dicts = [
|
|
1014
|
+
model_dicts = []
|
|
1015
|
+
for model in hf_models:
|
|
1016
|
+
model_dicts.append(asdict(model))
|
|
1048
1017
|
|
|
1049
1018
|
# Collect all valid candidates first
|
|
1050
1019
|
candidates = []
|
|
@@ -1060,12 +1029,18 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
|
|
|
1060
1029
|
continue
|
|
1061
1030
|
|
|
1062
1031
|
# Lists files with security issues.
|
|
1063
|
-
hf_security_info = hf_repo_info
|
|
1064
|
-
|
|
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"])
|
|
1065
1040
|
|
|
1066
1041
|
# Checks for multi-folder diffusers model or valid files (models with security issues are excluded).
|
|
1067
1042
|
if hf_security_info["scansDone"]:
|
|
1068
|
-
for info in repo_info
|
|
1043
|
+
for info in repo_info.get("siblings", []):
|
|
1069
1044
|
file_path = info["rfilename"]
|
|
1070
1045
|
if "model_index.json" == file_path and checkpoint_format in [
|
|
1071
1046
|
"diffusers",
|
|
@@ -1079,30 +1054,48 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
|
|
|
1079
1054
|
})
|
|
1080
1055
|
break
|
|
1081
1056
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
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
|
|
1091
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
|
|
1092
1088
|
):
|
|
1093
1089
|
file_list.append(file_path)
|
|
1094
1090
|
|
|
1095
1091
|
# Add single file candidates
|
|
1096
1092
|
if file_list:
|
|
1097
1093
|
# Sort and find the safest model
|
|
1098
|
-
file_name =
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
),
|
|
1104
|
-
file_list[0],
|
|
1105
|
-
)
|
|
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
|
|
1106
1099
|
candidates.append({
|
|
1107
1100
|
"type": "single_file",
|
|
1108
1101
|
"repo_id": repo_id,
|
|
@@ -1268,6 +1261,7 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
1268
1261
|
cache_dir = kwargs.pop("cache_dir", None)
|
|
1269
1262
|
skip_error = kwargs.pop("skip_error", False)
|
|
1270
1263
|
allow_unsafe_formats = kwargs.pop("allow_unsafe_formats", False)
|
|
1264
|
+
request_timeout = kwargs.pop("request_timeout", REQUEST_TIMEOUT)
|
|
1271
1265
|
|
|
1272
1266
|
# Get allowed extensions based on safety preference
|
|
1273
1267
|
allowed_extensions = get_allowed_extensions(allow_unsafe_formats)
|
|
@@ -1286,6 +1280,7 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
1286
1280
|
|
|
1287
1281
|
# Handle direct Civitai API download URLs
|
|
1288
1282
|
if search_word.startswith("https://civitai.com/api/download/"):
|
|
1283
|
+
_validate_remote_url(search_word, allowed_hosts=("civitai.com",))
|
|
1289
1284
|
# Extract model version ID from URL
|
|
1290
1285
|
match = re.search(r'/models/(\d+)', search_word)
|
|
1291
1286
|
if match:
|
|
@@ -1299,7 +1294,8 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
1299
1294
|
# Get version info to extract model name and ID
|
|
1300
1295
|
response = requests.get(
|
|
1301
1296
|
f"https://civitai.com/api/v1/model-versions/{version_id}",
|
|
1302
|
-
headers=headers
|
|
1297
|
+
headers=headers,
|
|
1298
|
+
timeout=request_timeout,
|
|
1303
1299
|
)
|
|
1304
1300
|
response.raise_for_status()
|
|
1305
1301
|
version_data = response.json()
|
|
@@ -1308,26 +1304,55 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
1308
1304
|
repo_id = str(version_data.get("modelId", ""))
|
|
1309
1305
|
trainedWords = version_data.get("trainedWords", [])
|
|
1310
1306
|
|
|
1311
|
-
#
|
|
1312
|
-
files =
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
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"])
|
|
1318
1343
|
|
|
1319
1344
|
except Exception as e:
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
file_name = f"model_{version_id}.safetensors"
|
|
1324
|
-
trainedWords = []
|
|
1345
|
+
if skip_error:
|
|
1346
|
+
return None
|
|
1347
|
+
raise ValueError("Could not verify the Civitai model version metadata.") from e
|
|
1325
1348
|
|
|
1326
1349
|
download_url = search_word
|
|
1327
1350
|
|
|
1328
1351
|
if download:
|
|
1329
1352
|
# Download from the direct URL
|
|
1330
|
-
local_path =
|
|
1353
|
+
local_path = _safe_cache_path(
|
|
1354
|
+
civitai_cache_dir, str(repo_id), str(version_id), file_name
|
|
1355
|
+
)
|
|
1331
1356
|
|
|
1332
1357
|
try:
|
|
1333
1358
|
file_downloader(
|
|
@@ -1395,35 +1420,32 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
1395
1420
|
try:
|
|
1396
1421
|
# Make the request to the CivitAI API
|
|
1397
1422
|
response = requests.get(
|
|
1398
|
-
"https://civitai.com/api/v1/models",
|
|
1423
|
+
"https://civitai.com/api/v1/models",
|
|
1424
|
+
params=params,
|
|
1425
|
+
headers=headers,
|
|
1426
|
+
timeout=request_timeout,
|
|
1399
1427
|
)
|
|
1400
1428
|
response.raise_for_status()
|
|
1401
|
-
except requests.exceptions.
|
|
1429
|
+
except requests.exceptions.RequestException as err:
|
|
1402
1430
|
if skip_error:
|
|
1403
1431
|
return None
|
|
1404
1432
|
else:
|
|
1405
|
-
raise requests.
|
|
1433
|
+
raise requests.RequestException("Could not query the Civitai API.") from err
|
|
1406
1434
|
else:
|
|
1407
1435
|
try:
|
|
1408
1436
|
data = response.json()
|
|
1409
|
-
except
|
|
1437
|
+
except (TypeError, ValueError):
|
|
1410
1438
|
if skip_error:
|
|
1411
1439
|
return None
|
|
1412
1440
|
else:
|
|
1413
1441
|
raise ValueError("Invalid JSON response")
|
|
1414
1442
|
|
|
1415
|
-
|
|
1416
|
-
# sorted_repos = sorted(
|
|
1417
|
-
# data["items"], key=lambda x: x["stats"]["downloadCount"], reverse=True
|
|
1418
|
-
# )
|
|
1419
|
-
|
|
1420
|
-
# Since the Civitai API is broken, I will temporarily sort by name.
|
|
1421
|
-
sorted_repos = sorted(data["items"], key=lambda x: x["name"], reverse=True)
|
|
1443
|
+
repositories = data.get("items", [])
|
|
1422
1444
|
|
|
1423
1445
|
# Collect all valid candidates instead of selecting one
|
|
1424
1446
|
all_candidates = []
|
|
1425
1447
|
|
|
1426
|
-
for selected_repo in
|
|
1448
|
+
for selected_repo in repositories:
|
|
1427
1449
|
repo_name = selected_repo["name"]
|
|
1428
1450
|
repo_id = selected_repo["id"]
|
|
1429
1451
|
|
|
@@ -1442,11 +1464,19 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
1442
1464
|
for model_data in selected_version["files"]:
|
|
1443
1465
|
# Check if the file passes security scans and has a valid extension
|
|
1444
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
|
+
|
|
1445
1473
|
if (
|
|
1446
|
-
model_data
|
|
1447
|
-
and model_data
|
|
1448
|
-
and
|
|
1474
|
+
model_data.get("pickleScanResult") == "Success"
|
|
1475
|
+
and model_data.get("virusScanResult") == "Success"
|
|
1476
|
+
and has_allowed_extension
|
|
1449
1477
|
):
|
|
1478
|
+
file_name = _safe_filename(file_name)
|
|
1479
|
+
_validate_remote_url(model_data["downloadUrl"])
|
|
1450
1480
|
file_status = {
|
|
1451
1481
|
"filename": file_name,
|
|
1452
1482
|
"download_url": model_data["downloadUrl"],
|
|
@@ -1459,16 +1489,14 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
1459
1489
|
models_list, key=lambda x: x["filename"], reverse=True
|
|
1460
1490
|
)
|
|
1461
1491
|
# Prefer safe/sfw models
|
|
1462
|
-
candidate_model =
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
sorted_models[0],
|
|
1471
|
-
)
|
|
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"]
|
|
1496
|
+
)
|
|
1497
|
+
if is_safe_variant:
|
|
1498
|
+
candidate_model = model_data
|
|
1499
|
+
break
|
|
1472
1500
|
|
|
1473
1501
|
# Add to candidates list (skip URL validation which causes 403 errors)
|
|
1474
1502
|
# Actual download will be attempted and retried recursively
|
|
@@ -1531,8 +1559,11 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
1531
1559
|
logger.info(f"Attempt {idx + 1}/{len(all_candidates)}: {file_name} from {candidate['repo_name']}")
|
|
1532
1560
|
|
|
1533
1561
|
# The path where the model is to be saved
|
|
1534
|
-
model_path =
|
|
1535
|
-
|
|
1562
|
+
model_path = _safe_cache_path(
|
|
1563
|
+
civitai_cache_dir,
|
|
1564
|
+
str(candidate_repo_id),
|
|
1565
|
+
str(candidate_version_id),
|
|
1566
|
+
file_name,
|
|
1536
1567
|
)
|
|
1537
1568
|
|
|
1538
1569
|
# Download Model File
|
|
@@ -1628,21 +1659,22 @@ def _load_pipeline_with_retries(cls, pretrained_model_link_or_path, pipeline_map
|
|
|
1628
1659
|
max_retries = kwargs.pop('_max_retries', 9)
|
|
1629
1660
|
failed_count = 0
|
|
1630
1661
|
|
|
1631
|
-
|
|
1632
|
-
|
|
1662
|
+
search_kwargs = {
|
|
1663
|
+
**kwargs,
|
|
1633
1664
|
"download": True,
|
|
1634
1665
|
"include_params": True,
|
|
1635
1666
|
"skip_error": False,
|
|
1636
|
-
"pipeline_tag": kwargs.
|
|
1667
|
+
"pipeline_tag": kwargs.get("_pipeline_tag"),
|
|
1637
1668
|
}
|
|
1638
|
-
kwargs.update(_status)
|
|
1639
1669
|
|
|
1640
1670
|
# Try each candidate up to max_retries times
|
|
1641
1671
|
for attempt in range(max_retries + 1):
|
|
1642
1672
|
# Search for the model on Hugging Face
|
|
1643
1673
|
try:
|
|
1644
1674
|
hf_checkpoint_status = search_huggingface(
|
|
1645
|
-
pretrained_model_link_or_path,
|
|
1675
|
+
pretrained_model_link_or_path,
|
|
1676
|
+
candidate_index=attempt,
|
|
1677
|
+
**search_kwargs,
|
|
1646
1678
|
)
|
|
1647
1679
|
except Exception as e:
|
|
1648
1680
|
logger.info(f"Candidate {attempt + 1}/{max_retries + 1} search failed: {e}")
|
|
@@ -1669,7 +1701,9 @@ def _load_pipeline_with_retries(cls, pretrained_model_link_or_path, pipeline_map
|
|
|
1669
1701
|
**kwargs,
|
|
1670
1702
|
)
|
|
1671
1703
|
else:
|
|
1672
|
-
pipeline = cls.from_pretrained(
|
|
1704
|
+
pipeline = cls.from_pretrained(
|
|
1705
|
+
checkpoint_path, **_pipeline_loading_kwargs(kwargs)
|
|
1706
|
+
)
|
|
1673
1707
|
|
|
1674
1708
|
logger.info(
|
|
1675
1709
|
f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}" # type: ignore
|
|
@@ -1709,16 +1743,16 @@ def add_methods(pipeline):
|
|
|
1709
1743
|
for attr_name in dir(AutoConfig):
|
|
1710
1744
|
attr_value = getattr(AutoConfig, attr_name)
|
|
1711
1745
|
if callable(attr_value) and not attr_name.startswith("__"):
|
|
1712
|
-
setattr(pipeline, attr_name,
|
|
1746
|
+
setattr(pipeline, attr_name, MethodType(attr_value, pipeline))
|
|
1713
1747
|
return pipeline
|
|
1714
1748
|
|
|
1715
1749
|
|
|
1716
1750
|
class AutoConfig:
|
|
1717
1751
|
def auto_load_textual_inversion(
|
|
1718
1752
|
self,
|
|
1719
|
-
pretrained_model_name_or_path: Union[str,
|
|
1720
|
-
token: Optional[Union[str,
|
|
1721
|
-
base_model: Optional[Union[str,
|
|
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,
|
|
1722
1756
|
tokenizer=None,
|
|
1723
1757
|
text_encoder=None,
|
|
1724
1758
|
**kwargs,
|
|
@@ -1728,7 +1762,7 @@ class AutoConfig:
|
|
|
1728
1762
|
Automatic1111 formats are supported).
|
|
1729
1763
|
|
|
1730
1764
|
Parameters:
|
|
1731
|
-
pretrained_model_name_or_path (`str
|
|
1765
|
+
pretrained_model_name_or_path (`str`, `os.PathLike`, `list`, or `dict`):
|
|
1732
1766
|
Can be either one of the following or a list of them:
|
|
1733
1767
|
|
|
1734
1768
|
- Search keywords for pretrained model (for example `EasyNegative`).
|
|
@@ -1740,7 +1774,7 @@ class AutoConfig:
|
|
|
1740
1774
|
- A [torch state
|
|
1741
1775
|
dict](https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict).
|
|
1742
1776
|
|
|
1743
|
-
token (`str` or `
|
|
1777
|
+
token (`str` or `list[str]`, *optional*):
|
|
1744
1778
|
Override the token to use for the textual inversion weights. If `pretrained_model_name_or_path` is a
|
|
1745
1779
|
list, then `token` must also be a list of equal length.
|
|
1746
1780
|
text_encoder ([`~transformers.CLIPTextModel`], *optional*):
|
|
@@ -1761,7 +1795,7 @@ class AutoConfig:
|
|
|
1761
1795
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
1762
1796
|
cached versions if they exist.
|
|
1763
1797
|
|
|
1764
|
-
proxies (`
|
|
1798
|
+
proxies (`dict[str, str]`, *optional*):
|
|
1765
1799
|
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
|
|
1766
1800
|
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
|
1767
1801
|
local_files_only (`bool`, *optional*, defaults to `False`):
|
|
@@ -1867,9 +1901,9 @@ class AutoConfig:
|
|
|
1867
1901
|
|
|
1868
1902
|
def auto_load_lora_weights(
|
|
1869
1903
|
self,
|
|
1870
|
-
pretrained_model_name_or_path_or_dict: Union[str,
|
|
1904
|
+
pretrained_model_name_or_path_or_dict: Union[str, dict[str, torch.Tensor]],
|
|
1871
1905
|
adapter_name=None,
|
|
1872
|
-
base_model: Optional[Union[str,
|
|
1906
|
+
base_model: Optional[Union[str, list[str]]] = None,
|
|
1873
1907
|
**kwargs,
|
|
1874
1908
|
):
|
|
1875
1909
|
r"""
|
|
@@ -1893,7 +1927,7 @@ class AutoConfig:
|
|
|
1893
1927
|
adapter_name (`str`, *optional*):
|
|
1894
1928
|
Adapter name to be used for referencing the loaded adapter model. If not specified, it will use
|
|
1895
1929
|
`default_{i}` where i is the total number of adapters being loaded.
|
|
1896
|
-
base_model (`str` or `
|
|
1930
|
+
base_model (`str` or `list[str]`, *optional*):
|
|
1897
1931
|
Base model tag(s) to filter LoRA models (e.g., "SD 1.5", "SDXL 1.0"). Used when searching Civitai
|
|
1898
1932
|
to ensure LoRA compatibility with the current pipeline's base model.
|
|
1899
1933
|
low_cpu_mem_usage (`bool`, *optional*):
|
|
@@ -1929,9 +1963,20 @@ class AutoConfig:
|
|
|
1929
1963
|
logger.warning(f"lora_path: {lora_path}")
|
|
1930
1964
|
pretrained_model_name_or_path_or_dict = lora_path
|
|
1931
1965
|
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
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
|
|
1935
1980
|
|
|
1936
1981
|
|
|
1937
1982
|
class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
@@ -1975,9 +2020,8 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
1975
2020
|
The format of the model checkpoint.
|
|
1976
2021
|
pipeline_tag (`str`, *optional*):
|
|
1977
2022
|
Tag to filter models by pipeline.
|
|
1978
|
-
|
|
1979
|
-
Override the default
|
|
1980
|
-
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.
|
|
1981
2025
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
1982
2026
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
1983
2027
|
cached versions if they exist.
|
|
@@ -1985,7 +2029,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
1985
2029
|
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
|
|
1986
2030
|
is not used.
|
|
1987
2031
|
|
|
1988
|
-
proxies (`
|
|
2032
|
+
proxies (`dict[str, str]`, *optional*):
|
|
1989
2033
|
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
|
|
1990
2034
|
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
|
1991
2035
|
output_loading_info(`bool`, *optional*, defaults to `False`):
|
|
@@ -2007,7 +2051,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
2007
2051
|
Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
|
|
2008
2052
|
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
|
|
2009
2053
|
information.
|
|
2010
|
-
device_map (`str` or `
|
|
2054
|
+
device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
|
|
2011
2055
|
A map that specifies where each submodule should go. It doesn’t need to be defined for each
|
|
2012
2056
|
parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
|
|
2013
2057
|
same device.
|
|
@@ -2015,7 +2059,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
2015
2059
|
Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
|
|
2016
2060
|
more information about each option see [designing a device
|
|
2017
2061
|
map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
|
|
2018
|
-
max_memory (`
|
|
2062
|
+
max_memory (`dict`, *optional*):
|
|
2019
2063
|
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
|
|
2020
2064
|
each GPU and the available CPU RAM if unset.
|
|
2021
2065
|
offload_folder (`str` or `os.PathLike`, *optional*):
|
|
@@ -2101,9 +2145,8 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
2101
2145
|
Path to the folder where cached files are stored.
|
|
2102
2146
|
resume (`bool`, *optional*, defaults to `False`):
|
|
2103
2147
|
Whether to resume an incomplete download.
|
|
2104
|
-
|
|
2105
|
-
Override the default
|
|
2106
|
-
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.
|
|
2107
2150
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
2108
2151
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
2109
2152
|
cached versions if they exist.
|
|
@@ -2114,7 +2157,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
2114
2157
|
won't be downloaded from the Hub.
|
|
2115
2158
|
token (`str`, *optional*):
|
|
2116
2159
|
The token to use as HTTP bearer authorization for remote files.
|
|
2117
|
-
device_map (`str` or `
|
|
2160
|
+
device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
|
|
2118
2161
|
A map that specifies where each submodule should go. It doesn’t need to be defined for each
|
|
2119
2162
|
parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
|
|
2120
2163
|
same device.
|
|
@@ -2122,7 +2165,7 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
2122
2165
|
Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
|
|
2123
2166
|
more information about each option see [designing a device
|
|
2124
2167
|
map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
|
|
2125
|
-
max_memory (`
|
|
2168
|
+
max_memory (`dict`, *optional*):
|
|
2126
2169
|
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
|
|
2127
2170
|
each GPU and the available CPU RAM if unset.
|
|
2128
2171
|
offload_folder (`str` or `os.PathLike`, *optional*):
|
|
@@ -2226,9 +2269,8 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
2226
2269
|
The format of the model checkpoint.
|
|
2227
2270
|
pipeline_tag (`str`, *optional*):
|
|
2228
2271
|
Tag to filter models by pipeline.
|
|
2229
|
-
|
|
2230
|
-
Override the default
|
|
2231
|
-
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.
|
|
2232
2274
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
2233
2275
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
2234
2276
|
cached versions if they exist.
|
|
@@ -2236,7 +2278,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
2236
2278
|
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
|
|
2237
2279
|
is not used.
|
|
2238
2280
|
|
|
2239
|
-
proxies (`
|
|
2281
|
+
proxies (`dict[str, str]`, *optional*):
|
|
2240
2282
|
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
|
|
2241
2283
|
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
|
2242
2284
|
output_loading_info(`bool`, *optional*, defaults to `False`):
|
|
@@ -2258,7 +2300,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
2258
2300
|
Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
|
|
2259
2301
|
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
|
|
2260
2302
|
information.
|
|
2261
|
-
device_map (`str` or `
|
|
2303
|
+
device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
|
|
2262
2304
|
A map that specifies where each submodule should go. It doesn’t need to be defined for each
|
|
2263
2305
|
parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
|
|
2264
2306
|
same device.
|
|
@@ -2266,7 +2308,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
2266
2308
|
Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
|
|
2267
2309
|
more information about each option see [designing a device
|
|
2268
2310
|
map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
|
|
2269
|
-
max_memory (`
|
|
2311
|
+
max_memory (`dict`, *optional*):
|
|
2270
2312
|
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
|
|
2271
2313
|
each GPU and the available CPU RAM if unset.
|
|
2272
2314
|
offload_folder (`str` or `os.PathLike`, *optional*):
|
|
@@ -2343,9 +2385,8 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
2343
2385
|
Path to the folder where cached files are stored.
|
|
2344
2386
|
resume (`bool`, *optional*, defaults to `False`):
|
|
2345
2387
|
Whether to resume an incomplete download.
|
|
2346
|
-
|
|
2347
|
-
Override the default
|
|
2348
|
-
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.
|
|
2349
2390
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
2350
2391
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
2351
2392
|
cached versions if they exist.
|
|
@@ -2356,7 +2397,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
2356
2397
|
won't be downloaded from the Hub.
|
|
2357
2398
|
token (`str`, *optional*):
|
|
2358
2399
|
The token to use as HTTP bearer authorization for remote files.
|
|
2359
|
-
device_map (`str` or `
|
|
2400
|
+
device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
|
|
2360
2401
|
A map that specifies where each submodule should go. It doesn’t need to be defined for each
|
|
2361
2402
|
parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
|
|
2362
2403
|
same device.
|
|
@@ -2364,7 +2405,7 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
2364
2405
|
Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
|
|
2365
2406
|
more information about each option see [designing a device
|
|
2366
2407
|
map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
|
|
2367
|
-
max_memory (`
|
|
2408
|
+
max_memory (`dict`, *optional*):
|
|
2368
2409
|
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
|
|
2369
2410
|
each GPU and the available CPU RAM if unset.
|
|
2370
2411
|
offload_folder (`str` or `os.PathLike`, *optional*):
|
|
@@ -2468,9 +2509,8 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
2468
2509
|
The format of the model checkpoint.
|
|
2469
2510
|
pipeline_tag (`str`, *optional*):
|
|
2470
2511
|
Tag to filter models by pipeline.
|
|
2471
|
-
|
|
2472
|
-
Override the default
|
|
2473
|
-
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.
|
|
2474
2514
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
2475
2515
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
2476
2516
|
cached versions if they exist.
|
|
@@ -2478,7 +2518,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
2478
2518
|
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
|
|
2479
2519
|
is not used.
|
|
2480
2520
|
|
|
2481
|
-
proxies (`
|
|
2521
|
+
proxies (`dict[str, str]`, *optional*):
|
|
2482
2522
|
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
|
|
2483
2523
|
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
|
2484
2524
|
output_loading_info(`bool`, *optional*, defaults to `False`):
|
|
@@ -2500,7 +2540,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
2500
2540
|
Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not
|
|
2501
2541
|
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
|
|
2502
2542
|
information.
|
|
2503
|
-
device_map (`str` or `
|
|
2543
|
+
device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
|
|
2504
2544
|
A map that specifies where each submodule should go. It doesn’t need to be defined for each
|
|
2505
2545
|
parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
|
|
2506
2546
|
same device.
|
|
@@ -2508,7 +2548,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
2508
2548
|
Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
|
|
2509
2549
|
more information about each option see [designing a device
|
|
2510
2550
|
map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
|
|
2511
|
-
max_memory (`
|
|
2551
|
+
max_memory (`dict`, *optional*):
|
|
2512
2552
|
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
|
|
2513
2553
|
each GPU and the available CPU RAM if unset.
|
|
2514
2554
|
offload_folder (`str` or `os.PathLike`, *optional*):
|
|
@@ -2585,9 +2625,8 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
2585
2625
|
Path to the folder where cached files are stored.
|
|
2586
2626
|
resume (`bool`, *optional*, defaults to `False`):
|
|
2587
2627
|
Whether to resume an incomplete download.
|
|
2588
|
-
|
|
2589
|
-
Override the default
|
|
2590
|
-
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.
|
|
2591
2630
|
force_download (`bool`, *optional*, defaults to `False`):
|
|
2592
2631
|
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
2593
2632
|
cached versions if they exist.
|
|
@@ -2598,7 +2637,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
2598
2637
|
won't be downloaded from the Hub.
|
|
2599
2638
|
token (`str`, *optional*):
|
|
2600
2639
|
The token to use as HTTP bearer authorization for remote files.
|
|
2601
|
-
device_map (`str` or `
|
|
2640
|
+
device_map (`str` or `dict[str, Union[int, str, torch.device]]`, *optional*):
|
|
2602
2641
|
A map that specifies where each submodule should go. It doesn’t need to be defined for each
|
|
2603
2642
|
parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the
|
|
2604
2643
|
same device.
|
|
@@ -2606,7 +2645,7 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
2606
2645
|
Set `device_map="auto"` to have 🤗 Accelerate automatically compute the most optimized `device_map`. For
|
|
2607
2646
|
more information about each option see [designing a device
|
|
2608
2647
|
map](https://hf.co/docs/accelerate/main/en/usage_guides/big_modeling#designing-a-device-map).
|
|
2609
|
-
max_memory (`
|
|
2648
|
+
max_memory (`dict`, *optional*):
|
|
2610
2649
|
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for
|
|
2611
2650
|
each GPU and the available CPU RAM if unset.
|
|
2612
2651
|
offload_folder (`str` or `os.PathLike`, *optional*):
|