Skip to content

Conversation

@xander1421
Copy link

Summary

  • Clamp codebook indices to valid range [0, codebook_size-1] before passing to ResidualVQ.get_output_from_indices()
  • Prevents CUDA device-side assertion failures with newer versions of vector-quantize-pytorch

Problem

When using vector-quantize-pytorch >= 1.20 with PyTorch 2.10+ and Python 3.14, the codebook indices from HeartMuLa can occasionally exceed the valid codebook range, causing:

torch.AcceleratorError: CUDA error: device-side assert triggered

The error occurs in einx.get_at() when indexing into the codebook with out-of-bounds values.

Solution

Added bounds checking to clamp indices before the VQ lookup:

indices_input = codes_bestrq_emb.transpose(1, 2)
codebook_size = getattr(self.vq_embed, 'codebook_size', 8192)
indices_input = indices_input.clamp(0, codebook_size - 1)

Test Environment

  • Python 3.14
  • PyTorch 2.10.0+cu128
  • vector-quantize-pytorch 1.27.15
  • CUDA 12.8
  • RTX 4000 series GPU

Test plan

  • Verified fix resolves CUDA errors
  • Generated audio output quality unchanged
  • Tested with 30-second music generation

🤖 Generated with Claude Code

When using vector-quantize-pytorch >= 1.20 with PyTorch 2.10+ and
Python 3.14, the codebook indices from HeartMuLa can occasionally
exceed the valid range [0, codebook_size-1], causing CUDA device-side
assertion failures in the einx.get_at indexing operation.

This fix clamps the indices to the valid codebook range before passing
them to ResidualVQ.get_output_from_indices(), preventing the CUDA errors
while preserving the generated audio quality.

Tested with:
- Python 3.14
- PyTorch 2.10.0+cu128
- vector-quantize-pytorch 1.27.15
- CUDA 12.8

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant