You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problematic line out = out[:, :, -torch.sum(extra["attention_mask"]).item():]
Cause
The slice expression is using: torch.sum(extra["attention_mask"]).item()
directly as a Python slice index. If this resolves to a non-integer numeric value, Python raises: TypeError: slice indices must be integers or None or have an __index__ method
Local patch
Replace the single slice line with:
if "attention_mask" in extra and extra["attention_mask"] is not None:
valid_tokens = int(torch.sum(extra["attention_mask"]).item())
valid_tokens = max(0, valid_tokens)
if valid_tokens > 0:
out = out[:, :, -valid_tokens:]
else:
out = out[:, :, :0]
Placement
Inside: def encode_token_weights(self, token_weight_pairs):
insert the patch immediately below: out, pooled, extra = self.gemma3_12b.encode_token_weights(token_weight_pairs)
and above: out_device = out.device
Minimal interpretation
The fix is simply to make the slice index integer-safe before applying it.
This may help anyone debugging this exact traceback in the LTX text encoder path.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Documenting a local fix for an error I encountered while running the LTX-2.3 image-to-video workflow in ComfyUI.
Error
TypeError: slice indices must be integers or None or have an __index__ methodTrace location
Relevant file location
Problematic line
out = out[:, :, -torch.sum(extra["attention_mask"]).item():]Cause
The slice expression is using:
torch.sum(extra["attention_mask"]).item()directly as a Python slice index. If this resolves to a non-integer numeric value, Python raises:
TypeError: slice indices must be integers or None or have an __index__ methodLocal patch
Replace the single slice line with:
Placement
Inside:
def encode_token_weights(self, token_weight_pairs):insert the patch immediately below:
out, pooled, extra = self.gemma3_12b.encode_token_weights(token_weight_pairs)and above:
out_device = out.deviceMinimal interpretation
The fix is simply to make the slice index integer-safe before applying it.
This may help anyone debugging this exact traceback in the LTX text encoder path.
All reactions