Skip to content

max_batch being ignored with Anima #42

Description

@slashedstar

The max_batch setting was being ignored with anima previews, had a LLM debug and it fix it, it spat out this:

Bug: max_batch ignored for video model latent formats when video_max_frames is -1

Description

The max_batch setting in betterTaesdPreviews (or previews) is ignored when using a video model latent format (e.g., wan21), even when doing batch image generation (not video). The preview always shows all batch items regardless of max_batch.

Root Cause

In py/better_previews/previewer.py:calculate_indexes(), when is_video=True (5D latent tensor), the code uses SETTINGS.btp_video_max_frames as the limit instead of self.max_batch_preview:

def calculate_indexes(self, batch_size: int, *, is_video=False) -> range:
    max_batch = (
        SETTINGS.btp_video_max_frames if is_video else self.max_batch_preview
    )
    if max_batch < 0:
        return range(batch_size)  # ← video_max_frames=-1 returns ALL items
    ...

When video_max_frames is -1 (default = unlimited), the condition max_batch < 0 is True, so range(batch_size) is returned — showing all batch items regardless of max_batch.

Steps to Reproduce

  1. Use any video model latent format (e.g., WAN21, HunyuanVideo, etc.) — the latent is 5D [batch, channels, frames, H, W]
  2. Set max_batch: 4 (or 2) in blehconfig.yaml
  3. Leave video_max_frames: -1 (the default, unlimited)
  4. Set batch_size: 5 in the KSampler
  5. Observe: the live preview shows 5 items in the grid, ignoring max_batch

Expected Behavior

When video_max_frames is -1 (unlimited), the batch limit should fall back to max_batch_preview. That is, calculate_indexes should use max_batch_preview to limit batch items when video_max_frames doesn't provide a limit.

Proposed Fix

In calculate_indexes, when max_batch < 0 and is_video=True, fall back to self.max_batch_preview instead of returning all items:

def calculate_indexes(self, batch_size: int, *, is_video=False) -> range:
    max_batch = (
        SETTINGS.btp_video_max_frames if is_video else self.max_batch_preview
    )
    if max_batch < 0:
        if is_video:
            max_batch = self.max_batch_preview  # fall back to batch limit
        else:
            return range(batch_size)
    if not self.maxed_batch_step_mode:
        return range(min(max_batch, batch_size))
    return range(
        0,
        batch_size,
        math.ceil(batch_size / max_batch),
    )[:max_batch]

Workaround

Set video_max_frames to a specific value (e.g., video_max_frames: 4) instead of -1. This forces a limit on the frame/batch dimension for video models. However, this conflates frame limiting with batch limiting, which may not be desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions