Skip to content

Fix StreamingTensorInfo.nBytes Int overflow for tensors > 2 GB#459

Merged
michalharakal merged 1 commit intodevelopfrom
fix/int-overflow-gguf
Apr 8, 2026
Merged

Fix StreamingTensorInfo.nBytes Int overflow for tensors > 2 GB#459
michalharakal merged 1 commit intodevelopfrom
fix/int-overflow-gguf

Conversation

@michalharakal
Copy link
Copy Markdown
Contributor

Change nBytes from Int to Long to prevent silent overflow when computing byte sizes for large tensors (e.g., Gemma 4 E4B per_layer_token_embd.weight).

Root cause: (numBlocks * typeSize).toInt() silently truncated a Long result exceeding Int.MAX_VALUE, producing negative byte counts that caused IllegalArgumentException: Length must be non-negative in JvmRandomAccessSource.readAt().

Changes:

  • StreamingTensorInfo.nBytes: Int → Long
  • StreamingGGUFReader: keep nBytes computation in Long, no .toInt()
  • StreamingGGUFReader.loadTensorData: explicit check with clear error message for tensors > 2 GB (use loadTensorStorageMapped instead)
  • GGUFReader (legacy): add overflow guard with actionable error message
  • Update all test comparisons for Long nBytes

Fixes #452

Change nBytes from Int to Long to prevent silent overflow when computing
byte sizes for large tensors (e.g., Gemma 4 E4B per_layer_token_embd.weight).

Root cause: `(numBlocks * typeSize).toInt()` silently truncated a Long
result exceeding Int.MAX_VALUE, producing negative byte counts that
caused `IllegalArgumentException: Length must be non-negative` in
JvmRandomAccessSource.readAt().

Changes:
- StreamingTensorInfo.nBytes: Int → Long
- StreamingGGUFReader: keep nBytes computation in Long, no .toInt()
- StreamingGGUFReader.loadTensorData: explicit check with clear error
  message for tensors > 2 GB (use loadTensorStorageMapped instead)
- GGUFReader (legacy): add overflow guard with actionable error message
- Update all test comparisons for Long nBytes

Fixes #452

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@michalharakal michalharakal merged commit e61290a into develop Apr 8, 2026
4 checks passed
@michalharakal michalharakal deleted the fix/int-overflow-gguf branch April 8, 2026 12:36
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.

Implement TurboQuant KV-cache support

1 participant