Skip to content

Commit d9a2641

Browse files
committed
flow_shift update: no override unless value provided
Signed-off-by: Olivia Stoner <245287810+o-stoner@users.noreply.github.com>
1 parent 3bb0565 commit d9a2641

2 files changed

Lines changed: 25 additions & 44 deletions

File tree

tensorrt_llm/_torch/visual_gen/models/wan/pipeline_wan.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,6 @@ def infer(self, req):
381381
flow_shift=req.params.flow_shift,
382382
)
383383

384-
def _default_flow_shift(self, height: int, width: int) -> float:
385-
"""Recommended flow_shift for the active Wan variant + resolution."""
386-
387-
if self.is_wan22_14b:
388-
return 12.0 # Wan2.2 T2V A14B
389-
if self.is_wan22_5b:
390-
return 5.0 # Wan2.2 TI2V 5B
391-
return 5.0 if max(height, width) >= 1280 else 3.0 # Wan2.1 T2V (720P vs 480P)
392-
393384
@nvtx_range("WanPipeline.forward")
394385
@torch.no_grad()
395386
def forward(
@@ -495,21 +486,20 @@ def forward(
495486
latents = self._prepare_latents(batch_size, height, width, num_frames, generator)
496487
logger.debug(f"Latents shape: {latents.shape}")
497488

498-
# Resolve flow_shift: user override wins, else the per-variant recommended default.
499-
resolved_flow_shift = (
500-
flow_shift if flow_shift is not None else self._default_flow_shift(height, width)
501-
)
502-
503-
sched_cfg = self.scheduler.config
504-
shift_key = (
505-
"shift" if "shift" in sched_cfg else "flow_shift" if "flow_shift" in sched_cfg else None
506-
)
507-
if shift_key is not None and sched_cfg[shift_key] != resolved_flow_shift:
508-
logger.info(
509-
f"flow_shift: {sched_cfg[shift_key]} -> {resolved_flow_shift} "
510-
f"({'user' if flow_shift is not None else 'variant default'})"
489+
# Apply an explicit user flow_shift override; otherwise keep the checkpoint
490+
# scheduler default so output matches the reference HuggingFace pipeline.
491+
if flow_shift is not None:
492+
sched_cfg = self.scheduler.config
493+
shift_key = (
494+
"shift"
495+
if "shift" in sched_cfg
496+
else "flow_shift"
497+
if "flow_shift" in sched_cfg
498+
else None
511499
)
512-
self.scheduler.register_to_config(**{shift_key: resolved_flow_shift})
500+
if shift_key is not None and sched_cfg[shift_key] != flow_shift:
501+
logger.info(f"flow_shift: {sched_cfg[shift_key]} -> {flow_shift} (user)")
502+
self.scheduler.register_to_config(**{shift_key: flow_shift})
513503

514504
self.scheduler.set_timesteps(num_inference_steps, device=self.device)
515505

tensorrt_llm/_torch/visual_gen/models/wan/pipeline_wan_i2v.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,6 @@ def infer(self, req):
415415
flow_shift=req.params.flow_shift,
416416
)
417417

418-
def _default_flow_shift(self, height: int, width: int) -> float:
419-
"""Recommended flow_shift for the active Wan I2V variant + resolution."""
420-
421-
if self.is_wan22_14b:
422-
return 5.0 # Wan2.2 I2V A14B
423-
return 5.0 if max(height, width) >= 1280 else 3.0 # Wan2.1 I2V (720P vs 480P)
424-
425418
@torch.no_grad()
426419
def forward(
427420
self,
@@ -546,21 +539,19 @@ def forward(
546539
batch_size, image, height, width, num_frames, generator, last_image
547540
)
548541

549-
# Resolve flow_shift: user override wins, else the per-variant default.
550-
resolved_flow_shift = (
551-
flow_shift if flow_shift is not None else self._default_flow_shift(height, width)
552-
)
553-
554-
sched_cfg = self.scheduler.config
555-
shift_key = (
556-
"shift" if "shift" in sched_cfg else "flow_shift" if "flow_shift" in sched_cfg else None
557-
)
558-
if shift_key is not None and sched_cfg[shift_key] != resolved_flow_shift:
559-
logger.info(
560-
f"flow_shift: {sched_cfg[shift_key]} -> {resolved_flow_shift} "
561-
f"({'user' if flow_shift is not None else 'variant default'})"
542+
# Apply an explicit user flow_shift override; otherwise keep the checkpoint scheduler default.
543+
if flow_shift is not None:
544+
sched_cfg = self.scheduler.config
545+
shift_key = (
546+
"shift"
547+
if "shift" in sched_cfg
548+
else "flow_shift"
549+
if "flow_shift" in sched_cfg
550+
else None
562551
)
563-
self.scheduler.register_to_config(**{shift_key: resolved_flow_shift})
552+
if shift_key is not None and sched_cfg[shift_key] != flow_shift:
553+
logger.info(f"flow_shift: {sched_cfg[shift_key]} -> {flow_shift} (user)")
554+
self.scheduler.register_to_config(**{shift_key: flow_shift})
564555

565556
self.scheduler.set_timesteps(num_inference_steps, device=self.device)
566557

0 commit comments

Comments
 (0)