Skip to content

fix: video frame validation to enable automatic clipping in inference pipeline#197

Merged
aryamancodes merged 1 commit into
nvidia-cosmos:mainfrom
jeanachoi:fix/update_temporal_assert
Sep 2, 2025
Merged

fix: video frame validation to enable automatic clipping in inference pipeline#197
aryamancodes merged 1 commit into
nvidia-cosmos:mainfrom
jeanachoi:fix/update_temporal_assert

Conversation

@jeanachoi

@jeanachoi jeanachoi commented Aug 29, 2025

Copy link
Copy Markdown
Contributor

Issues

  1. The error message does not clearly mention that the input must have at least 121 (self.pixel_chunk_duration, this is a set value) frames.
  2. Validation occurs too early in the pipeline, stopping videos from reaching the clipping logic that handles partial chunks. Currently, get_pixel_num_frames and get_latent_num_frames raise errors if the frame count isn't divisible by 121. This prevents inputs with more than 121 frames that aren't multiples of 121 from proceeding, even though autoclipping logic exists further down the pipeline before tensor reshaping.

Fix
Validation is already enforced where tensor reshaping happens.

def transform_encode_state_shape(self, state: torch.Tensor) -> torch.Tensor:
"""
Rearranges the input state tensor to the required shape for encoding video data. Mainly for chunk based encoding
"""
B, C, T, H, W = state.shape
assert (
T % self.pixel_chunk_duration == 0
), f"Temporal dimension {T} is not divisible by chunk_length {self.pixel_chunk_duration}"
return rearrange(state, "b c (n t) h w -> (b n) c t h w", t=self.pixel_chunk_duration)
def transform_decode_state_shape(self, latent: torch.Tensor) -> torch.Tensor:
B, _, T, _, _ = latent.shape
assert (
T % self.latent_chunk_duration == 0
), f"Temporal dimension {T} is not divisible by chunk_length {self.latent_chunk_duration}"
return rearrange(latent, "b c (n t) h w -> (b n) c t h w", t=self.latent_chunk_duration)

Because of this, we can relax these asserts to only check for inputs that don't meet the minimum frame requirement. The error message is updated to clearly indicate the issue.

Signed-off-by: Jeana Choi <jeanachoi@jeanachoi-mlt.client.nvidia.com>
@jeanachoi
jeanachoi marked this pull request as ready for review August 29, 2025 20:47
@pjannaty

Copy link
Copy Markdown
Contributor

APPROVED_FOR_CI_RUN

@pjannaty

Copy link
Copy Markdown
Contributor

pipelines/34098563

@aryamancodes aryamancodes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@aryamancodes
aryamancodes merged commit 1e3066a into nvidia-cosmos:main Sep 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants