RowDequantSource in the engine + ops.gather row-dequant path#741
Merged
Conversation
…nt path Generalizes the per-row dequant trick out of the model layer (SKaiNET-transformers issue #184, hoist 1). Adds `RowDequantSource` (a `TensorData` marker: `dequantRow(rowIdx): FloatArray`) to skainet-lang-core, and teaches `DefaultCpuOps.gather` to use it: when the gathered table implements RowDequantSource, dequantise only the touched rows (each unique row once, cached) instead of the generic element path — which calls `get()`, unsupported on such tensors, and would otherwise force a full FP32 materialise of the table. A RowDequantSource table declares logical dtype FP32, so gather returns FP32 with no typing change. This lets a packed/oversized embedding (e.g. a Q-quantised token_embd) stay packed and be looked up via ops.gather directly — the basis for keeping Gemma's ~0.67 GB token_embd packed (#178's remaining board-fit item) and, later, whisper int8. Verified: new GatherRowDequantTest — gather over a fake RowDequantSource table whose get()/copyToFloatArray() throw returns the correct dequantised rows (so it provably went through dequantRow). backend-cpu compiles + the test passes. Next (separate, release-coordinated): SKaiNET-transformers re-points gemma's RowDequantSource to this engine interface (typealias) and routes token_embd through ops.gather; the GemmaQ5KPackedParityTest is the end-to-end gate. Co-Authored-By: Claude Opus 4.8 (1M context) <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. |
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.
Engine half of the quant-hoist (SKaiNET-developers/SKaiNET-transformers#184, hoist 1).
Generalizes the per-row dequant trick out of the model layer into the engine.
Change
RowDequantSource(aTensorDatamarker,dequantRow(rowIdx): FloatArray) added toskainet-lang-core(next toTensorData).DefaultCpuOps.gathernow checks for it: when the gathered table is aRowDequantSource, dequantonly the touched rows (each unique row once, cached) instead of the generic element path — which calls
get()(unsupported on such tensors) and would otherwise force a full FP32 materialise of the table.RowDequantSourcetable declares logical dtype FP32, sogatherreturns FP32 with no typingchange — a packed/oversized embedding can be looked up via
ops.gatherdirectly.Why
Lets a packed quant
token_embdstay packed through the embedding lookup. Closes the remaining board-fititem from SKaiNET-transformers#178 (the ~0.67 GB FP32 main embedding) once transformers re-points gemma to
this interface, and is the same path that later gives whisper int8 on-device.
Test
GatherRowDequantTest— gather over a fakeRowDequantSourcetable whoseget()/copyToFloatArray()throw returns the correct dequantised rows, so it provably went through
dequantRow. backend-cpucompiles + the test passes.
Follow-up (separate, transformers repo)
SKaiNET-transformers re-points gemma's
RowDequantSourceto this engine interface (typealias) and routestoken_embdthroughops.gather;GemmaQ5KPackedParityTestis the end-to-end gate. Coordinate the releasepin as usual (engine first).