Skip to content

RowDequantSource in the engine + ops.gather row-dequant path#741

Merged
michalharakal merged 1 commit into
developfrom
feature/rowdequant-gather
Jun 17, 2026
Merged

RowDequantSource in the engine + ops.gather row-dequant path#741
michalharakal merged 1 commit into
developfrom
feature/rowdequant-gather

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

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 (a TensorData marker, dequantRow(rowIdx): FloatArray) added to
    skainet-lang-core (next to TensorData).
  • DefaultCpuOps.gather now checks for it: when the gathered table is a RowDequantSource, dequant
    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 — a packed/oversized embedding can be looked up via ops.gather directly.

Why

Lets a packed quant token_embd stay packed through the embedding lookup. Closes the remaining board-fit
item 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 fake RowDequantSource table whose get()/copyToFloatArray()
throw returns the correct dequantised rows, so it provably went through dequantRow. backend-cpu
compiles + the test passes.

Follow-up (separate, transformers repo)

SKaiNET-transformers re-points gemma's RowDequantSource to this engine interface (typealias) and routes
token_embd through ops.gather; GemmaQ5KPackedParityTest is the end-to-end gate. Coordinate the release
pin as usual (engine first).

…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>
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-741 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

@michalharakal michalharakal merged commit 8ee0c5f into develop Jun 17, 2026
10 of 11 checks passed
@michalharakal michalharakal deleted the feature/rowdequant-gather branch June 17, 2026 21:34
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