Skip to content

Commit dcbd89e

Browse files
committed
Disable CFG cache on wan 2.1 when batch size is indivisible by data shards
1 parent 3a8f9e9 commit dcbd89e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/maxdiffusion/pipelines/wan/wan_pipeline_2_1.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ def run_inference_2_1(
226226
do_cfg = guidance_scale > 1.0
227227
bsz = latents.shape[0]
228228

229+
data_shards = 1
230+
try:
231+
if hasattr(latents, "sharding") and hasattr(latents.sharding, "mesh"):
232+
data_shards = latents.sharding.mesh.shape["data"] * latents.sharding.mesh.shape.get("fsdp", 1)
233+
except Exception:
234+
pass
235+
236+
if use_cfg_cache and do_cfg and bsz % data_shards != 0:
237+
from maxdiffusion.max_logging import MaxLogging
238+
max_logging = MaxLogging()
239+
max_logging.log(f"Warning: Disabling CFG cache because batch size {bsz} is not divisible by data shards {data_shards}. This often happens with data_parallelism > 1 and per_device_batch_size = 1.")
240+
use_cfg_cache = False
229241
# Resolution-dependent CFG cache config (FasterCache / MixCache guidance)
230242
if height >= 720:
231243
# 720p: conservative — protect last 40%, interval=5

0 commit comments

Comments
 (0)