Skip to content

Commit 540df5e

Browse files
committed
debug added to export video
1 parent a00b8d9 commit 540df5e

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/maxdiffusion/pipelines/wan/wan_pipeline_i2v_2p1.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,7 @@ def __call__(
237237
if self.config.expand_timesteps:
238238
latents = (1 - first_frame_mask) * condition + first_frame_mask * latents
239239
latents_bcthw = jnp.transpose(latents, (0, 4, 1, 2, 3))
240-
max_logging.log(f"[DEBUG CALL] latents shape before denorm: {latents_bcthw.shape}")
241-
242240
latents_denorm_bcthw = self._denormalize_latents(latents_bcthw)
243-
max_logging.log(f"[DEBUG CALL] latents shape after denorm: {latents_denorm_bcthw.shape}")
244241

245242

246243
if output_type == "latent":

src/maxdiffusion/utils/export_utils.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def export_to_video(
165165
"""
166166
# TODO: Dhruv. Remove by Diffusers release 0.33.0
167167
# Added to prevent breaking existing code
168+
if not video_frames:
169+
logger.warning("export_to_video: video_frames list is empty.")
170+
return ""
168171
if not is_imageio_available():
169172
logger.warning(
170173
(
@@ -194,7 +197,45 @@ def export_to_video(
194197
output_video_path = tempfile.NamedTemporaryFile(suffix=".mp4").name
195198

196199
if isinstance(video_frames[0], np.ndarray):
197-
video_frames = [(frame * 255).astype(np.uint8) for frame in video_frames]
200+
logger.info("Processing np.ndarray frames for video export.")
201+
processed_frames = []
202+
for i, frame in enumerate(video_frames):
203+
if frame.dtype != np.float32:
204+
frame = frame.astype(np.float32) # Ensure float32 for checks
205+
206+
# --- Check for non-finite values ---
207+
is_finite = np.isfinite(frame)
208+
if not np.all(is_finite):
209+
nan_count = np.isnan(frame).sum()
210+
inf_count = np.isinf(frame).sum()
211+
logger.warning(f"[EXPORT WARN] Frame {i}: Non-finite values detected! "
212+
f"NaNs: {nan_count}, Infs: {inf_count}")
213+
# Sanitize: Replace NaNs with 0, Infs with 0 or 1
214+
frame = np.nan_to_num(frame, nan=0.0, posinf=1.0, neginf=0.0)
215+
logger.info(f"[EXPORT INFO] Frame {i}: Non-finite values replaced.")
216+
217+
# --- Check for out-of-range values [0.0, 1.0] ---
218+
min_val = np.min(frame)
219+
max_val = np.max(frame)
220+
if min_val < 0.0 or max_val > 1.0:
221+
logger.warning(f"[EXPORT WARN] Frame {i}: Values out of [0.0, 1.0] range. "
222+
f"Min={min_val:.4f}, Max={max_val:.4f}")
223+
# Clip values to the valid range
224+
frame = np.clip(frame, 0.0, 1.0)
225+
logger.info(f"[EXPORT INFO] Frame {i}: Values clipped to [0.0, 1.0].")
226+
227+
# --- Convert to uint8 ---
228+
try:
229+
frame_uint8 = (frame * 255.0).astype(np.uint8)
230+
processed_frames.append(frame_uint8)
231+
except Exception as e:
232+
logger.error(f"[EXPORT ERROR] Frame {i}: Failed to convert to uint8: {e}")
233+
# Fallback: append a black frame
234+
if len(video_frames) > 0 and isinstance(video_frames[0], np.ndarray):
235+
processed_frames.append(np.zeros(video_frames[0].shape, dtype=np.uint8))
236+
237+
video_frames = processed_frames # Use the sanitized and converted frames
238+
198239

199240
elif isinstance(video_frames[0], PIL.Image.Image):
200241
video_frames = [np.array(frame) for frame in video_frames]

0 commit comments

Comments
 (0)