-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathutils.py
More file actions
2506 lines (2325 loc) · 83.3 KB
/
Copy pathutils.py
File metadata and controls
2506 lines (2325 loc) · 83.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import torch
import argparse
import torch.distributed as dist
from diffusers import DiffusionPipeline
from typing import Any, Dict, Optional, List, Tuple
from diffusers.quantizers import PipelineQuantizationConfig
from ..logger import init_logger
from ..platforms import current_platform
from ..compile.utils import (
set_compile_configs,
mindiesd_compile_available,
mindiesd_compile,
)
from ..distributed import ParallelismBackend, ParallelismConfig
from ..caching import enable_cache, steps_mask
from ..attention import set_attn_backend
from ..caching import (
BlockAdapter,
DBCacheConfig,
DMDCalibratorConfig,
TaylorSeerCalibratorConfig,
load_configs,
load_parallelism_config,
)
from ..offload import _find_offload_related_hf_hook
from ..offload import _parse_byte_size_arg
from ..offload import layerwise_cpu_offload
from ..offload import remove_layerwise_offload
from ..quantization import quantize, QuantizeConfig
from ..summary import strify as summary_strify
logger = init_logger(__name__)
class MemoryTracker:
"""Track peak GPU memory usage during execution."""
def __init__(self, device=None):
self.device = device if device is not None else current_platform.current_device()
self.enabled = current_platform.is_accelerator_available()
self.peak_memory = 0
def __enter__(self):
if self.enabled:
current_platform.reset_peak_memory_stats(self.device)
current_platform.synchronize(self.device)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if self.enabled:
current_platform.synchronize(self.device)
self.peak_memory = current_platform.max_memory_allocated(self.device)
def get_peak_memory_gb(self):
"""Get peak memory in GB.
:returns: The resolved peak memory gb.
"""
return self.peak_memory / (1024 ** 3)
def report(self):
"""Print memory usage report."""
if self.enabled:
peak_gb = self.get_peak_memory_gb()
logger.info(f"Peak GPU memory usage: {peak_gb:.2f} GB")
return peak_gb
return 0
def GiB():
try:
if not current_platform.is_accelerator_available():
return 0
total_memory_bytes = current_platform.get_device_properties(
current_platform.current_device(), ).total_memory
total_memory_gib = total_memory_bytes / (1024 ** 3)
return int(total_memory_gib)
except Exception:
return 0
def get_args(parse: bool = True, ) -> argparse.ArgumentParser | argparse.Namespace:
parser = argparse.ArgumentParser()
# Model and data paths
parser.add_argument(
"--model-path",
type=str,
default=None,
help="Override model path if provided",
)
parser.add_argument(
"--controlnet-path",
type=str,
default=None,
help="Override controlnet model path if provided",
)
parser.add_argument(
"--lora-path",
type=str,
default=None,
help="Override lora model path if provided",
)
parser.add_argument(
"--transformer-path",
type=str,
default=None,
help="Override transformer model path if provided",
)
parser.add_argument(
"--image-path",
type=str,
default=None,
help="Override image path if provided",
)
parser.add_argument(
"--mask-image-path",
type=str,
default=None,
help="Override mask image path if provided",
)
# Acceleration Config path
parser.add_argument(
"--config-path",
"--config",
type=str,
default=None,
help="Path to CacheDiT configuration YAML file",
)
# Sampling settings
parser.add_argument(
"--prompt",
type=str,
default=None,
help="Override default prompt if provided",
)
parser.add_argument(
"--negative-prompt",
type=str,
default=None,
help="Override default negative prompt if provided",
)
# Force skip negative prompt in some specific cases
parser.add_argument(
"--skip-negative_prompt",
"--skip-neg",
action="store_true",
help="Force skip negative prompt even if negative prompt is provided.",
)
parser.add_argument(
"--num_inference_steps",
"--steps",
type=int,
default=None,
help="Number of inference steps",
)
parser.add_argument(
"--warmup",
type=int,
default=1,
help="Number of warmup steps before measuring performance",
)
parser.add_argument(
"--warmup-num-inference-steps",
"--warmup-steps",
type=int,
default=None,
help="Number of warmup inference steps per warmup before measuring performance",
)
parser.add_argument(
"--warmup-seed",
type=int,
default=None,
help=(
"Optional random seed used only for warmup forwards. When set, warmup uses this seed while "
"formal repeated inference continues to use --seed. This is especially useful for few-shot "
"SVDQ runs where runtime quantization usually happens during warmup."),
)
parser.add_argument(
"--warmup-prompt",
type=str,
default=None,
help=("Optional prompt used only for warmup forwards. When set, warmup uses this prompt while "
"formal repeated inference continues to use --prompt or the example default prompt."),
)
parser.add_argument(
"--repeat",
type=int,
default=1,
help="Number of times to repeat the inference for performance measurement",
)
parser.add_argument(
"--height",
type=int,
default=None,
help="Height of the generated image",
)
parser.add_argument(
"--width",
type=int,
default=None,
help="Width of the generated image",
)
parser.add_argument(
"--input-height",
type=int,
default=None,
help="Height of the input image",
)
parser.add_argument(
"--input-width",
type=int,
default=None,
help="Width of the input image",
)
parser.add_argument(
"--seed",
type=int,
default=None,
help="Random seed for reproducibility",
)
parser.add_argument(
"--num-frames",
"--frames",
type=int,
default=None,
help="Number of frames to generate for video",
)
# Output settings
parser.add_argument(
"--save-path",
type=str,
default=None,
help="Path to save the generated output, e.g., output.png or output.mp4",
)
# Cache specific settings
parser.add_argument(
"--cache",
action="store_true",
default=False,
help="Enable Cache Acceleration",
)
parser.add_argument(
"--cache-summary",
"--summary",
action="store_true",
default=False,
help="Enable Cache Summary logging",
)
parser.add_argument(
"--Fn-compute-blocks",
"--Fn",
type=int,
default=1,
help="CacheDiT Fn_compute_blocks parameter",
)
parser.add_argument(
"--Bn-compute-blocks",
"--Bn",
type=int,
default=0,
help="CacheDiT Bn_compute_blocks parameter",
)
parser.add_argument(
"--residual-diff-threshold",
"--rdt",
type=float,
default=0.12,
help="CacheDiT residual diff threshold",
)
parser.add_argument(
"--max-warmup-steps",
"--ws",
type=int,
default=8,
help="Maximum warmup steps for CacheDiT",
)
parser.add_argument(
"--warmup-interval",
"--wi",
type=int,
default=1,
help="Warmup interval for CacheDiT",
)
parser.add_argument(
"--max-cached-steps",
"--mc",
type=int,
default=-1,
help="Maximum cached steps for CacheDiT",
)
parser.add_argument(
"--max-continuous-cached-steps",
"--mcc",
type=int,
default=3,
help="Maximum continuous cached steps for CacheDiT",
)
parser.add_argument(
"--taylorseer",
action="store_true",
default=False,
help="Enable TaylorSeer for CacheDiT",
)
parser.add_argument(
"--taylorseer-order",
"-order",
type=int,
default=1,
help="TaylorSeer order",
)
parser.add_argument(
"--dmd",
action="store_true",
default=False,
help="Enable DMD (Dynamic Mode Decomposition / Prony) exponential-basis calibrator for CacheDiT",
)
parser.add_argument(
"--dmd-history",
type=int,
default=6,
help="DMD snapshot-history window length",
)
parser.add_argument(
"--dmd-svd-precision",
"--dmd-svd",
type=str,
default="medium",
choices=["low", "medium", "high"],
help="DMD SVD precision mode: medium (default, balanced), low (randomised), high (accurate)",
)
parser.add_argument(
"--steps-mask",
action="store_true",
default=False,
help="Enable steps mask for CacheDiT",
)
parser.add_argument(
"--mask-policy",
"--scm",
type=str,
default=None,
choices=[
None,
"slow",
"s",
"medium",
"m",
"fast",
"f",
"ultra",
"u",
],
help="Pre-defined steps computation mask policy",
)
# Quantization settings
parser.add_argument(
"--quantize",
"--q",
action="store_true",
default=False,
help="Enable quantization for transformer",
)
# per row quantization
parser.add_argument(
"--disable-per-row",
"--no-per-row",
action="store_true",
default=False,
help="Disable per row quantization for transformer",
)
# float8, float8_weight_only, int8, int8_weight_only, int4, int4_weight_only
parser.add_argument(
"--quantize-type",
"--q-type",
type=str,
default=None,
choices=[
None,
"float8_per_row",
"float8_per_tensor",
"float8_per_block",
"float8_weight_only",
"int8_per_row",
"int8_per_tensor",
"int8_weight_only",
"int4_weight_only",
"svdq_int4_r32_dq",
"svdq_int4_r64_dq",
"svdq_int4_r128_dq",
"svdq_int4_r256_dq",
"svdq_nvfp4_r32_dq",
"svdq_nvfp4_r64_dq",
"svdq_nvfp4_r128_dq",
"svdq_nvfp4_r256_dq",
"bitsandbytes_4bit",
],
)
parser.add_argument(
"--disable-regional-quantize",
"--disable-regional",
"--no-regional",
action="store_true",
default=False,
help="Disable quantization for repeated blocks in transformer",
)
parser.add_argument(
"--disable-per-tensor-fallback",
"--no-per-tensor-fallback",
action="store_true",
default=False,
help="Disable (float8 only) per-tensor fallback quantization for transformer",
)
# some quick start flags for transformer quantization.
parser.add_argument(
"--float8-per-row",
"--float8",
action="store_true",
default=False,
help="Enable float8 per-row quantization for transformer",
)
parser.add_argument(
"--float8-per-tensor",
action="store_true",
default=False,
help="Enable float8 per-tensor quantization for transformer",
)
parser.add_argument(
"--float8-per-block",
action="store_true",
default=False,
help="Enable float8 per-block quantization for transformer",
)
parser.add_argument(
"--float8-weight-only",
"--float8-wo",
action="store_true",
default=False,
help="Enable float8 weight-only quantization for transformer",
)
parser.add_argument(
"--float8-blockwise",
"--float8-bw",
action="store_true",
default=False,
help="Enable float8 blockwise quantization for transformer",
)
parser.add_argument(
"--int8-per-row",
"--int8",
action="store_true",
default=False,
help="Enable int8 per-row quantization for transformer",
)
parser.add_argument(
"--int8-per-tensor",
action="store_true",
default=False,
help="Enable int8 per-tensor quantization for transformer",
)
parser.add_argument(
"--int8-weight-only",
"--int8-wo",
action="store_true",
default=False,
help="Enable int8 weight-only quantization for transformer",
)
parser.add_argument(
"--int4-weight-only",
"--int4-wo",
action="store_true",
default=False,
help="Enable int4 weight-only quantization for transformer",
)
parser.add_argument(
"--svdq-int4-r32-dq",
"--svdq-r32",
action="store_true",
default=False,
help="Enable SVDQ INT4 dynamic quantization with rank 32 for transformer",
)
parser.add_argument(
"--svdq-int4-r64-dq",
"--svdq-r64",
action="store_true",
default=False,
help="Enable SVDQ INT4 dynamic quantization with rank 64 for transformer",
)
parser.add_argument(
"--svdq-int4-r128-dq",
"--svdq-r128",
action="store_true",
default=False,
help="Enable SVDQ INT4 dynamic quantization with rank 128 for transformer",
)
parser.add_argument(
"--svdq-int4-r256-dq",
"--svdq-r256",
action="store_true",
default=False,
help="Enable SVDQ INT4 dynamic quantization with rank 256 for transformer",
)
parser.add_argument(
"--svdq-nvfp4-r32-dq",
action="store_true",
default=False,
help="Enable SVDQ NVFP4 dynamic quantization with rank 32 for transformer",
)
parser.add_argument(
"--svdq-nvfp4-r64-dq",
action="store_true",
default=False,
help="Enable SVDQ NVFP4 dynamic quantization with rank 64 for transformer",
)
parser.add_argument(
"--svdq-nvfp4-r128-dq",
action="store_true",
default=False,
help="Enable SVDQ NVFP4 dynamic quantization with rank 128 for transformer",
)
parser.add_argument(
"--svdq-nvfp4-r256-dq",
action="store_true",
default=False,
help="Enable SVDQ NVFP4 dynamic quantization with rank 256 for transformer",
)
# quantization for extra modules: text encoder, vae, controlnet, etc.
parser.add_argument(
"--quantize-text-encoder",
"--q-text",
action="store_true",
default=False,
help="Enable quantization for text encoder",
)
parser.add_argument(
"--quantize-text-type",
"--q-text-type",
type=str,
default=None,
choices=[
None,
"float8_per_row",
"float8_per_tensor",
"float8_per_block",
"float8_weight_only",
"int8_per_row",
"int8_per_tensor",
"int8_weight_only",
"int4_weight_only",
"bitsandbytes_4bit",
],
)
parser.add_argument(
"--quantize-controlnet",
"--q-controlnet",
action="store_true",
default=False,
help="Enable quantization for ControlNet",
)
parser.add_argument(
"--quantize-controlnet-type",
"--q-controlnet-type",
type=str,
default=None,
choices=[
None,
"float8_per_row",
"float8_per_tensor",
"float8_per_block",
"float8_weight_only",
"int8_per_row",
"int8_per_tensor",
"int8_weight_only",
"int4_weight_only",
"bitsandbytes_4bit",
],
)
parser.add_argument(
"--quantize-verbose",
"--q-verbose",
action="store_true",
default=False,
help="Print the verbose logs of the quantization process",
)
parser.add_argument(
"--svdq-smooth-strategy",
"--svdq-smooth",
type=str,
default="identity",
choices=["identity", "weight", "weight_inv", "few_shot"],
help="Smooth strategy for SVDQ DQ quantization. Default: identity.",
)
parser.add_argument(
"--svdq-calibrate-precision",
"--svdq-calib",
type=str,
default="low",
choices=["low", "medium", "high"],
help="Calibration / decomposition precision for SVDQ quantization. Default: low.",
)
parser.add_argument(
"--svdq-runtime",
type=str,
default="v1",
choices=["v1", "v2"],
help="Runtime SVDQ W4A4 GEMM kernel. Use v2 for the CUDA v2 plain path.",
)
parser.add_argument(
"--svdq-few-shot-steps",
type=int,
default=1,
help=("How many transformer/module forwards to observe before materializing SVDQ few-shot "
"quantization. This counts cumulative root-module forwards on the armed transformer, not "
"pipeline invocations."),
)
parser.add_argument(
"--svdq-few-shot-relax-factor",
type=float,
default=1.5,
help=
("Maximum few-shot relax factor applied to activation spans before smooth-scale recomputation. "
"Must be >= 1.0 so the observed activation span is preserved or amplified, never reduced. "
"Values above about 3.0 are often too aggressive and may oversmooth outputs; try 1.5-2.5 first."
),
)
parser.add_argument(
"--svdq-few-shot-relax-top-ratio",
type=float,
default=0.25,
help="Fraction of the largest few-shot activation spans used to define the relax threshold.",
)
parser.add_argument(
"--svdq-few-shot-relax-strategy",
type=str,
default="auto",
choices=["fixed", "top", "auto", "stable_auto", "power", "log", "rank", "top_q4"],
help=(
"How few-shot relax factors are assigned over activation spans. 'fixed' keeps the original "
"activation span unchanged; 'top' keeps channels below the threshold unchanged; 'auto' uses "
"a linear ramp; 'stable_auto' bucketizes that ramp for better run-to-run stability; "
"'power', 'log', and 'rank' use stronger monotonic curves; 'top_q4' is accepted as an "
"alias of 'top'."),
)
parser.add_argument(
"--svdq-quantize-device",
type=str,
default="cuda",
choices=["auto", "cpu", "cuda"],
help=("Device used for SVDQ decomposition and packing math. The example CLI defaults to 'cuda' "
"so CPU-resident models can still quantize layer-by-layer on GPU before the final move."),
)
parser.add_argument(
"--svdq-offload-quantized-layers-to-cpu",
dest="svdq_offload_quantized_layers_to_cpu",
action="store_true",
default=False,
help=(
"After each SVDQ linear layer is quantized, move it back to CPU immediately. This reduces "
"peak memory during quantization and is forced on when --svdq-layerwise-offload is active."),
)
parser.add_argument(
"--svdq-keep-quantized-layers-on-device",
dest="svdq_offload_quantized_layers_to_cpu",
action="store_false",
help=(
"Keep newly quantized SVDQ layers on the quantization device instead of offloading them to "
"CPU. Ignored when --svdq-layerwise-offload is active."),
)
parser.add_argument(
"--svdq-layerwise-offload",
action="store_true",
default=False,
help=("Enable cache-dit layerwise CPU offload for SVDQ PTQ calibration and DQ few-shot "
"activation collection when the root module is CPU-resident."),
)
parser.add_argument(
"--svdq-defer-final-to-cuda",
dest="svdq_defer_final_to_cuda",
action="store_true",
default=True,
help=(
"Defer the final pipeline move to CUDA until SVDQ few-shot runtime quantization finishes. "
"This only takes effect when quantized layers are offloaded during the few-shot flow."),
)
parser.add_argument(
"--svdq-no-defer-final-to-cuda",
dest="svdq_defer_final_to_cuda",
action="store_false",
help="Do not defer the final pipeline move when using SVDQ few-shot quantization.",
)
parser.add_argument(
"--svdq-few-shot-compile",
action="store_true",
default=False,
help="Compile the transformer only after SVDQ few-shot runtime quantization completes.",
)
parser.add_argument(
"--svdq-fused-mlp",
action="store_true",
default=False,
help=
"Fuse FeedForward GELU MLP blocks into a single fused kernel chain after SVDQ quantization.",
)
# Parallelism settings
parser.add_argument(
"--parallel-type",
"--parallel",
type=str,
default=None,
choices=[
None,
"tp",
"ulysses",
"ring",
"usp",
# hybrid cp + tp
"ulysses_tp", # prefer ulysses first
"ring_tp",
"tp_ulysses", # prefer tp first
"tp_ring",
"usp_tp",
],
)
parser.add_argument(
"--parallel-vae",
action="store_true",
default=False,
help="Enable VAE parallelism if applicable.",
)
parser.add_argument(
"--parallel-text-encoder",
"--parallel-text",
action="store_true",
default=False,
help="Enable text encoder parallelism if applicable.",
)
parser.add_argument(
"--parallel-controlnet",
action="store_true",
default=False,
help="Enable ControlNet parallelism if applicable.",
)
parser.add_argument(
"--attn", # attention backend for context parallelism
type=str,
default=None,
choices=[
None,
"flash",
"_flash_3", # FlashAttention-3
# Based on this fix: https://github.com/huggingface/diffusers/pull/12563
"native", # native pytorch attention: sdpa
"_native_cudnn",
# '_sdpa_cudnn' is only in cache-dit to support context parallelism
# with attn masks, e.g., ZImage. It is not in diffusers yet.
"_sdpa_cudnn",
"sage", # Need install sageattention: https://github.com/thu-ml/SageAttention
"_native_npu", # native npu attention
"_npu_fia", # npu fused infer attention
"_mindiesd_laser", # MindIE-SD laser attention
],
)
# Ulysses context parallelism settings
parser.add_argument(
"--ulysses-anything",
"--uaa",
action="store_true",
default=False,
help="Enable Ulysses Anything Attention for context parallelism",
)
parser.add_argument(
"--ulysses-float8",
"--ufp8",
action="store_true",
default=False,
help="Enable Ulysses Attention/UAA Float8 for context parallelism",
)
parser.add_argument(
"--ulysses-async",
"--uaqkv",
action="store_true",
default=False,
help="Enabled experimental Async QKV Projection with Ulysses for context parallelism",
)
# Ring context parallelism settings
parser.add_argument(
"--ring-rotate-method",
"--rotate",
type=str,
default="p2p",
choices=[
"allgather",
"p2p",
],
help="Ring Attention rotation method for context parallelism",
)
parser.add_argument(
"--ring-no-convert-to-fp32",
"--ring-no-fp32",
"--no-fp32",
action="store_true",
default=False,
help="Disable convert Ring Attention output and lse to fp32 for context parallelism",
)
# Offload settings
offload_group = parser.add_mutually_exclusive_group()
offload_group.add_argument(
"--cpu-offload",
"--cpu-offload-model",
action="store_true",
default=False,
help="Enable diffusers model CPU offload for pipeline components when supported.",
)
offload_group.add_argument(
"--sequential-cpu-offload",
action="store_true",
default=False,
help="Enable diffusers sequential CPU offload for pipeline components when supported.",
)
offload_group.add_argument(
"--module-layerwise-cpu-offload",
"--layerwise-offload",
dest="module_layerwise_cpu_offload",
action="store_true",
default=False,
help=("Enable cache-dit generic sequential CPU offload for nn.Module components. This is "
"intended for custom non-diffusers modules and is mutually exclusive with the diffusers "
"pipeline offload switches."),
)
parser.add_argument(
"--layerwise-async-transfer",
"--svdq-layerwise-async-transfer",
"--svdq-async-transfer",
action="store_true",
default=False,
help=("Enable CUDA-stream-based async_transfer for cache-dit layerwise CPU offload. This "
"shared setting applies to both generic module layerwise offload and SVDQ layerwise "
"collection when --svdq-layerwise-offload is active."),
)
parser.add_argument(
"--layerwise-text-async-transfer",
dest="layerwise_text_async_transfer",
action="store_true",
default=None,
help=("Override text encoder layerwise async_transfer. When omitted, text encoder layerwise "
"offload uses --layerwise-async-transfer."),
)
parser.add_argument(
"--no-layerwise-text-async-transfer",
dest="layerwise_text_async_transfer",
action="store_false",
help=("Disable text encoder layerwise async_transfer even if --layerwise-async-transfer is "
"enabled."),
)
parser.add_argument(
"--layerwise-transfer-buckets",
"--svdq-layerwise-transfer-buckets",
"--svdq-transfer-buckets",
type=int,
default=1,
help=("Base async prefetch depth hint used to size layerwise copy-lane concurrency. "
"Default is 1."),
)
parser.add_argument(
"--layerwise-text-transfer-buckets",
type=int,
default=None,
help=("Override text encoder layerwise transfer_buckets. When omitted, text encoder "
"layerwise offload uses --layerwise-transfer-buckets."),
)
parser.add_argument(
"--layerwise-prefetch-limit",
"--svdq-layerwise-prefetch-limit",
action="store_true",
default=False,
help=("Enable the conservative future-prefetch target-count limit for layerwise async "
"transfer. When set, runtime caps pending/ready future targets to "
"min(4 * --layerwise-transfer-buckets, 8). By default this limit is disabled."),
)
parser.add_argument(
"--layerwise-text-prefetch-limit",
dest="layerwise_text_prefetch_limit",
action="store_true",
default=None,
help=("Override text encoder layerwise prefetch_limit. When omitted, text encoder layerwise "
"offload uses --layerwise-prefetch-limit."),
)
parser.add_argument(
"--no-layerwise-text-prefetch-limit",
dest="layerwise_text_prefetch_limit",
action="store_false",
help=("Disable text encoder layerwise prefetch_limit even if --layerwise-prefetch-limit is "
"enabled."),
)
parser.add_argument(
"--layerwise-max-copy-streams",
"--svdq-layerwise-max-copy-streams",
type=int,
default=None,
help=("Maximum number of async CUDA copy streams used by cache-dit layerwise offload. This "
"shared setting applies to both generic module layerwise offload and SVDQ layerwise "
"collection when --svdq-layerwise-offload is active. When omitted, runtime derives "
"it from --layerwise-transfer-buckets and applies its internal safety cap."),
)
parser.add_argument(
"--layerwise-text-max-copy-streams",
type=int,
default=None,
help=("Override text encoder layerwise max_copy_streams. When omitted, text encoder "
"layerwise offload uses --layerwise-max-copy-streams."),
)
parser.add_argument(
"--layerwise-max-inflight-prefetch-bytes",
"--svdq-layerwise-max-inflight-prefetch-bytes",
type=_parse_byte_size_arg,
default=None,
help=("Maximum total CUDA residency budget, in bytes, for in-flight layerwise future-target "
"prefetch. This shared setting applies to both generic module layerwise offload and "
"SVDQ layerwise collection when --svdq-layerwise-offload is active. Accepts raw bytes "
"or suffixes like 512MiB and 4GiB. When omitted, runtime leaves the byte-budget "
"limit disabled."),
)
parser.add_argument(
"--layerwise-text-max-inflight-prefetch-bytes",
type=_parse_byte_size_arg,
default=None,
help=("Override text encoder layerwise max_inflight_prefetch_bytes. Accepts raw bytes or "
"suffixes like 512MiB and 4GiB. When omitted, text encoder layerwise offload uses "
"--layerwise-max-inflight-prefetch-bytes."),
)
parser.add_argument(
"--layerwise-persistent-buckets",
"--svdq-layerwise-persistent-buckets",
"--svdq-persistent-buckets",
type=int,
default=0,
help=("How many selected layerwise offload targets should stay resident on CUDA for the full "
"handle lifetime. This shared setting applies to both generic module layerwise offload "
"and SVDQ layerwise collection when --svdq-layerwise-offload is active. Default is 0."),
)
parser.add_argument(
"--layerwise-text-persistent-buckets",
type=int,
default=None,
help=("Override text encoder layerwise persistent_buckets. When omitted, text encoder "
"layerwise offload uses --layerwise-persistent-buckets."),
)
parser.add_argument(
"--layerwise-persistent-bins",
"--svdq-layerwise-persistent-bins",
"--svdq-persistent-bins",
type=int,
default=1,
help=("How many evenly distributed bins should be used when placing persistent layerwise "
"offload targets across the selected target list. A value of 1 keeps the original "
"prefix behavior. For example, with 32 targets, --layerwise-persistent-buckets 16 and "
"--layerwise-persistent-bins 4, runtime keeps [0:4), [8:12), [16:20), and [24:28) "
"resident. This shared setting applies to both generic module layerwise offload and "
"SVDQ layerwise collection when --svdq-layerwise-offload is active. Default is 1."),
)
parser.add_argument(
"--layerwise-text-persistent-bins",
type=int,
default=None,
help=("Override text encoder layerwise persistent_bins. When omitted, text encoder "
"layerwise offload uses --layerwise-persistent-bins."),
)
parser.add_argument(
"--device-map-balance",
"--device-map",
action="store_true",
default=False,
help="Enable automatic device map balancing model if multiple GPUs are available.",
)
# Vae tiling/slicing settings
parser.add_argument(
"--vae-tiling",
action="store_true",
default=False,
help="Enable VAE tiling for low memory device.",
)
parser.add_argument(
"--vae-slicing",
action="store_true",
default=False,
help="Enable VAE slicing for low memory device.",
)
# Compiling settings
parser.add_argument(
"--compile",
action="store_true",
default=False,
help="Enable compile for transformer, only compile the repeated blocks by default.",
)
parser.add_argument(
"--disable-compile-repeated-blocks",
"--disable-compile-blocks",
"--no-regional-compile",
"--no-rc",