Skip to content

fix(dispatch): ternary kernel packs join the self-healing SPI (#1240) - #1241

Merged
michalharakal merged 1 commit into
developfrom
feat/ternary-selfheal-spi
Aug 31, 2026
Merged

michalharakal merged 1 commit into
developfrom
feat/ternary-selfheal-spi

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Closes #1240. Part of the ternary track #1136.

What

The 0.52.0 self-healing dispatch (KernelDispatch.ensureInstalled() over the ViewKernelPack ServiceLoader SPI) discovered the Q-series row-major packs but not the ternary ones — a consumer loading BITNET_B1_58 / BITNET_PLANES weights silently got the int8-requantize or decoding-reference path (~120× slower per the #1141 bench: 51.8 vs 0.43 GOPS) unless it called NativeTernaryF32GemvKernel.install() / NativeTernaryLmheadKernel.install() explicitly. That is exactly the failure mode the self-healing release exists to eliminate, and why SKaiNET-transformers' CLI still carries explicit install lines (skainet-cli/Main.kt:249-250 there — droppable once this ships in a consumed BOM, tracked in SKaiNET-transformers#360).

  • FfmTernaryKernelPackFactory (jvm jar) and JniTernaryKernelPackFactory (Android AAR), listed in the two META-INF/services/sk.ainet.backend.api.kernel.ViewKernelPack files. They install the exact FP32×BITNET_B1_58 LUT gemv and the fused BITNET_PLANES lm_head; both delegate to the packs' install(native?), which registers nothing when the bundled native library is missing — same contract as the row-major factories.
  • Kotlin/Native has no ServiceLoader: NativeKnTernaryF32Gemv / NativeKnTernaryLmhead stay explicit — now stated in ViewKernelPack.other.kt and in the ternary tutorial's install table (automatic vs explicit per target).
  • CHANGELOG entry under Unreleased.

Verification

KernelDispatchSelfHealTest.cold_dispatch_discovers_the_ternary_packs: a cold dispatcher — clearForTesting() then ensureInstalled(), no bootstrap of any kind — must register ternary_f32_gemv/ffm + ternary_planes_matmul/ffm and resolve matmul(FP32 × BITNET_B1_58) via TernaryF32GemvKernel.keyFor(). Skips cleanly where the native library is absent. Observed on macosArm64:

SELFHEAL n=19 ... kernels=[..., ternary_f32_gemv/ffm, ternary_planes_matmul/ffm]

Full skainet-backend-native-cpu jvmTest suite and the Android compileReleaseKotlin are green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YKeDSK4JF295y53Uvez954

The 0.52.0 self-healing dispatch discovered the Q-series row-major packs
but not the ternary ones: a consumer loading BITNET_B1_58 / BITNET_PLANES
weights silently fell to the int8-requantize or decoding-reference path
(~120x slower per the #1141 bench) unless it called the two installs
explicitly — exactly the failure mode ensureInstalled() exists to
eliminate, and why SKaiNET-transformers' CLI still carries explicit
NativeTernaryF32GemvKernel.install() lines.

- FfmTernaryKernelPackFactory (jvm jar) and JniTernaryKernelPackFactory
  (Android AAR), listed in the ViewKernelPack service files: install the
  exact FP32xB1.58 LUT gemv and the fused BITNET_PLANES lm_head; both
  degrade to a no-op lookup when the bundled native library is missing.
- Kotlin/Native note: no ServiceLoader there — NativeKnTernaryF32Gemv /
  NativeKnTernaryLmhead stay explicit, now said in ViewKernelPack.other.kt
  and the ternary tutorial's install table (automatic vs explicit).
- KernelDispatchSelfHealTest: cold dispatch must resolve
  matmul(FP32 x BITNET_B1_58) to the LUT kernel with zero explicit
  installs (skips cleanly where the native library is absent).

Closes #1240.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YKeDSK4JF295y53Uvez954
@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-1241 artifact to view the complete documentation locally.

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

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.

Ternary kernel packs are missing from the self-healing dispatch SPI — consumers silently get the int8 fallback

1 participant