Repository navigation
perf(lang-core): bulk copyToFloatArray for MmapFloatTensorData - #1362
Merged
Merged
Conversation
MmapFloatTensorData inherited TensorData.copyToFloatArray, which walks every element through get(*indices) — an IntArray copy for the spread plus a boxed Float each. RMSNormalization.eagerFusedRmsNorm copies its (mmap'd) gain every forward, so in a BitNet 2B4T JVM decode this was ~10 GB of allocation per 45 s. Override with one bulk FloatBuffer read (duplicate, so the shared view's position is untouched; statements kept separate for Android's pre-Java-9 nio). Refs #1357 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
📖 Documentation Preview The documentation has been built successfully for this PR. Generated Files:
Artifacts:
This comment will be updated automatically when the PR is updated. |
michalharakal
added a commit
that referenced
this pull request
Oct 21, 2026
CHANGELOG [0.62.0] - 2026-10-21 with the parity headline over #1363, #1364, #1368, #1369, #1426, #1427, #1428 and #1430, plus entries for the operator coverage matrix (#1370), the BitNet decode allocation and threading fixes (#1359, #1360, #1361, #1362), the ClassificationSupport extraction (#1429) and the toolchain bumps (Kotlin 2.4.21, kotest 6.2.6, Gradle 9.8.1). VERSION_NAME, CITATION, Antora version, README bom coordinate, What's New and contributors, Android tutorial coordinates; regenerated operator and kernel-support matrices; SKEEP-007 rollout step 3 marked shipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MmapFloatTensorDatadidn't overridecopyToFloatArray(), so it used theTensorDatadefault. That walks every element throughget(*indices): anIntArraycopy for the vararg spread plus a boxedFloatper element.RMSNormalization.eagerFusedRmsNormcopies its gain tensor on every forward, and with MAPPED weights the gains areMmapFloatTensorData. In a BitNet b1.58 2B4T JVM decode profile, this was the top allocation site once the Vector API fallback was fixed (#1360): about 10 GB in a 45 s window. It also showed up in CPU samples asMmapFloatTensorData.calcFlatIndex.Change
An override that does one bulk read:
It copies exactly
shape.volumefloats in row-major order, which is the same contract as the default.apiCheckpasses.Tests
New
MmapFloatTensorDataCopyTest(lang-corejvmTest, 3 tests):getorder for a rank-3 tensor;volumefloats are copied from a larger buffer;MmapTensorSourceslices) copies correctly, the sharedfloatBuffer.position()stays 0, and the copy is repeatable.:skainet-lang:skainet-lang-core:jvmTestpasses 1046/1046.Measured
Arduino Ventuno Q, 4× Cortex-A78C, JVM, BitNet 2B4T I2_S, 128 greedy tokens, backported onto 0.61.0:
TensorData.copyToFloatArray←MmapFloatTensorData←eagerFusedRmsNormelement-wise site disappears from JFR.MmapFloatTensorData.copyToFloatArrayremains only as one bulk array per call (~3.8 % of allocation);52f57d1d…);Possible follow-up: cache the gain in
RMSNormalizationso even the bulk copy happens once.Refs #1357
🤖 Generated with Claude Code