Skip to content

Commit a2bc0c9

Browse files
review: rename FLUX2_DUAL_GPU env var to DIFFSYNTH_DUAL_GPU
Per @gemini-code-assist review on modelscope#1436: model-neutral env var name so a single signal controls dual-GPU mode for both FLUX.2 and Wan paths. This change: - FLUX2_DUAL_GPU -> DIFFSYNTH_DUAL_GPU - FLUX2_DUAL_GPU_SPLIT_AT -> DIFFSYNTH_DUAL_GPU_SPLIT_AT Function names (enable_flux2_dual_gpu) and the helper module name (flux2_dual_gpu_diffsynth.py) keep the model-specific naming since they're the entry points users explicitly import for FLUX.2 training. Coordinated with PR modelscope#1436 which adopts the same DIFFSYNTH_DUAL_GPU gate on the Wan side. Once both merge, one env var enables dual-GPU for either model family; runner.py recognizes the gate regardless of which family the training script targets.
1 parent df7b01c commit a2bc0c9

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

diffsynth/diffusion/runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def launch_training_task(
2929
dataloader = torch.utils.data.DataLoader(dataset, shuffle=True, collate_fn=lambda x: x[0], num_workers=num_workers)
3030
# Dual-GPU model-parallel: skip the device move that would undo our
3131
# manual split, and tell accelerate not to touch the model's device.
32-
_flux2_dual_gpu = os.environ.get("FLUX2_DUAL_GPU", "false").lower() == "true"
33-
if not _flux2_dual_gpu:
32+
_diffsynth_dual_gpu = os.environ.get("DIFFSYNTH_DUAL_GPU", "false").lower() == "true"
33+
if not _diffsynth_dual_gpu:
3434
model.to(device=accelerator.device)
3535
model, optimizer, dataloader, scheduler = accelerator.prepare(model, optimizer, dataloader, scheduler)
3636
else:

examples/flux2/model_training/flux2_dual_gpu_diffsynth.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
point and at ``norm_out`` (the boundary back to cuda:0).
2727
2828
Env vars:
29-
FLUX2_DUAL_GPU=true enable dual-GPU path
30-
FLUX2_DUAL_GPU_SPLIT_AT=24 override split index
29+
DIFFSYNTH_DUAL_GPU=true enable dual-GPU path
30+
DIFFSYNTH_DUAL_GPU_SPLIT_AT=24 override split index
3131
(default: num_single // 2)
3232
3333
Usage in DiffSynth-Studio's training script
@@ -38,7 +38,7 @@
3838
# ...build pipeline / training module normally...
3939
training_module = Flux2ImageTrainingModule(...)
4040
41-
# Activate the split (env-gated; no-op when FLUX2_DUAL_GPU is unset).
41+
# Activate the split (env-gated; no-op when DIFFSYNTH_DUAL_GPU is unset).
4242
# Call AFTER LoRA injection (switch_pipe_to_training_mode) so PEFT
4343
# has wrapped target modules. The split places the wrapped modules
4444
# and PEFT LoRA params follow the base layer's device automatically.
@@ -63,13 +63,13 @@
6363
# ─── Env-gated public surface ───────────────────────────────────────────────
6464

6565
def is_dual_gpu_enabled() -> bool:
66-
"""True iff ``FLUX2_DUAL_GPU=true`` in the environment."""
67-
return os.getenv("FLUX2_DUAL_GPU", "false").lower() == "true"
66+
"""True iff ``DIFFSYNTH_DUAL_GPU=true`` in the environment."""
67+
return os.getenv("DIFFSYNTH_DUAL_GPU", "false").lower() == "true"
6868

6969

7070
def get_split_at(num_single_blocks: int) -> int:
71-
"""Single-blocks split index. Override via ``FLUX2_DUAL_GPU_SPLIT_AT``."""
72-
override = os.getenv("FLUX2_DUAL_GPU_SPLIT_AT")
71+
"""Single-blocks split index. Override via ``DIFFSYNTH_DUAL_GPU_SPLIT_AT``."""
72+
override = os.getenv("DIFFSYNTH_DUAL_GPU_SPLIT_AT")
7373
if override is not None:
7474
return int(override)
7575
return num_single_blocks // 2
@@ -78,7 +78,7 @@ def get_split_at(num_single_blocks: int) -> int:
7878
def enable_flux2_dual_gpu(dit: nn.Module) -> nn.Module:
7979
"""Distribute the DiffSynth Flux2DiT across cuda:0 and cuda:1.
8080
81-
When ``FLUX2_DUAL_GPU`` is unset this is a no-op pass-through.
81+
When ``DIFFSYNTH_DUAL_GPU`` is unset this is a no-op pass-through.
8282
8383
Call after the Flux2DiT (typically ``training_module.pipe.dit``) is
8484
loaded and after any PEFT LoRA injection has run. PEFT places LoRA
@@ -92,15 +92,15 @@ def enable_flux2_dual_gpu(dit: nn.Module) -> nn.Module:
9292

9393
if torch.cuda.device_count() < 2:
9494
raise RuntimeError(
95-
f"FLUX2_DUAL_GPU=true requires ≥2 CUDA devices, found "
95+
f"DIFFSYNTH_DUAL_GPU=true requires ≥2 CUDA devices, found "
9696
f"{torch.cuda.device_count()}."
9797
)
9898

9999
num_single = len(dit.single_transformer_blocks)
100100
split_at = get_split_at(num_single)
101101
if not 0 < split_at < num_single:
102102
raise RuntimeError(
103-
f"FLUX2_DUAL_GPU_SPLIT_AT={split_at} out of range "
103+
f"DIFFSYNTH_DUAL_GPU_SPLIT_AT={split_at} out of range "
104104
f"(dit has {num_single} single blocks)."
105105
)
106106

examples/flux2/model_training/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def flux2_parser():
138138
# pre-allocate on cuda:0 before we get a chance to split it.
139139
device="cpu" if (args.initialize_model_on_cpu or is_dual_gpu_enabled()) else accelerator.device,
140140
)
141-
# Dual-GPU split: gated on FLUX2_DUAL_GPU env var. Distributes
141+
# Dual-GPU split: gated on DIFFSYNTH_DUAL_GPU env var. Distributes
142142
# pipe.dit across cuda:0 and cuda:1 at the single_transformer_blocks
143143
# midpoint. Called AFTER LoRA injection (which happened inside
144144
# Flux2ImageTrainingModule.__init__) so PEFT LoRA params follow

0 commit comments

Comments
 (0)