Skip to content

refactor(gemma): SafeTensors loading collapses onto the engine's ShardedSafeTensorsParametersLoader (SKaiNET#1246) - #398

Merged
michalharakal merged 4 commits into
developfrom
feat/1246-gemma-sharded-loader
Sep 2, 2026
Merged

michalharakal merged 4 commits into
developfrom
feat/1246-gemma-sharded-loader

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Phase 2 of SKaiNET#1246 (engine side shipped in SKaiNET 0.53.0 via SKaiNET-developers/SKaiNET#1252). Includes the 0.53.0 catalog bump from #397 so it resolves standalone.

GemmaSafeTensorsLoader no longer hand-rolls per-tensor materialization. It is now one ShardedSafeTensorsParametersLoader.withPolicy(indexPath, dtypePolicy, tensorFilter = …) run into a map by HF name, followed by the existing (now table-driven) HF → GGUF renaming:

  • deleted loadAndConvertTensor, transposeRowMajor (dead — every call site passed transpose = false), loadFirstExistingIfFits, and the DequantOps / StreamingShardedSafeTensorsReader imports — no io.gguf import remains in this file (the module dependency stays for the GGUF lane)
  • tensorFilter = the family allowlist plus the PLE-table size guard, so unmapped vision/audio tensors never materialize and are exempt from the engine's fail-fast pre-scan; PLE auto-disable semantics and GemmaSafeTensorsMappedPle.kt are unchanged
  • new dtypePolicy: DTypePolicy = Any constructor parameter (existing call sites source-compatible); GemmaNetworkLoader's SafeTensors lane now validates against {BF16, FP16} keep-native and forwards the policy, so Require(BF16) reaches the engine instead of being rejected

Testing: new GemmaSafeTensorsLoaderFixtureTest — a synthetic 2-shard checkpoint written with the engine's SafeTensorsWriter (BF16 projections/embeddings, F32 norms, hand-written index + minimal config.json): all 23 GGUF slots present and nothing extra, tied output/embedding, exact value round-trip, an unmapped INT64 vision-tower decoy neither delivered nor rejected, and Require(BF16) yielding Bf16DenseTensorData for projections with dense FP32 norms. :llm-inference:gemma:jvmTest 16 suites / 47 tests green against the published 0.53.0.

Follow-up: the sibling hand-rolled loaders (apertus, gemma3n, voxtral, llama DecoderSafeTensorsLoaderLlama, llm-core DecoderSafeTensorsLoader) take the same recipe; single-file (non-indexed) consumers use SafeTensorsParametersLoader.

michalharakal and others added 4 commits September 2, 2026 13:14
…dedSafeTensorsParametersLoader (SKaiNET#1246)

GemmaSafeTensorsLoader hand-rolled the per-tensor materialization the
engine's single-file loader already owned — BF16/F16 widening via the GGUF
module's DequantOps (a wrong dependency edge), a row-major transpose no
call site ever enabled, and a PLE size guard — because the engine had no
sharded ParametersLoader. SKaiNET 0.53.0 ships one (SKaiNET#1252).

The loader now expresses only family policy: the HF allowlist and PLE size
guard as the engine loader's tensorFilter, and the HF -> GGUF slot renaming
(table-driven per layer). Every dtype decision is the engine's, driven by a
DTypePolicy forwarded through ShardedSafeTensorsParametersLoader.withPolicy;
GemmaNetworkLoader's SafeTensors lane validates against the same keep-native
set as the GGUF lane instead of rejecting every Require(). transposeRowMajor
and the DequantOps import are gone; GemmaSafeTensorsMappedPle and the PLE
auto-disable semantics are unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ked loader (SKaiNET#1246)

A 2-shard checkpoint written with the engine's SafeTensorsWriter (BF16
projections, F32 norms, hand-written index, minimal config.json): every
GGUF-named slot is populated after renaming, values round-trip exactly on
bf16-representable fixtures, an unmapped INT64 vision-tower tensor is
neither delivered nor allowed to trip the engine's fail-fast pre-scan, and
Require(BF16) reaches the engine (native bf16 storage for projections,
dense FP32 for the norms).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Brings the engine's billion-parameter export fixes (SKaiNET#1247) and the
sharded SafeTensors ParametersLoader (SKaiNET#1246) into the resolved
artifact set; the gemma family's loader collapse onto it follows.

Co-Authored-By: Claude Fable 5.1 <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