Skip to content

Export harnesses cast external parameters to BufferHandle.Owned and crash on SKaiNET 0.53.0 (BufferHandle.Floats) #420

Description

@michalharakal

Symptom

FunctionGemmaExportDumpTest.exportAll_emitsContractShapesAndManifest and FunctionGemmaVmfbParityTest.vmfbTwoGraphKvLoopMatchesOracle fail on develop:

java.lang.ClassCastException: class sk.ainet.lang.tensor.storage.BufferHandle$Floats cannot be cast to class sk.ainet.lang.tensor.storage.BufferHandle$Owned
    at sk.ainet.models.functiongemma.FunctionGemmaExportHarness.writeSafetensors(FunctionGemmaExportHarness.kt:471)

Cause

Since SKaiNET 0.53.0 (SKaiNET#1247) the engine's ConstantMaterialization hands external parameters over as whatever BufferHandle the source data has — BufferHandle.Floats for FloatArray-backed constants, Owned for byte-backed ones — and provides DefaultBufferResolver / BufferAccessor.readAllBytes() to read any of them. Gemma3nExportHarness was updated to the resolver; these still hard-cast to BufferHandle.Owned:

  • llm-inference/functiongemma/.../FunctionGemmaExportHarness.kt (writeSafetensors, writeSafetensorsInt8)
  • llm-inference/smollm2/.../SmolLm2ExportHarness.kt
  • llm-inference/whisper/src/jvmTest/.../WhisperExportHarness.kt (bytesOf, irpa storage segment — Owned/Borrowed only)
  • llm-inference/gemma/src/jvmTest/.../RealGemmaBakeIrpaTest.kt, llm-inference/llama/src/jvmTest/.../RealSmolLm2BakeIrpaTest.kt

Fix

Read every external parameter through DefaultBufferResolver().resolve(handle).use { it.readAllBytes() } (little-endian f32 bytes regardless of handle kind) at all five sites. No behaviour change for Owned handles; the bf16 / int8 conversions keep their exact arithmetic.

Also on develop: the API dumps of bert, gemma, gemma3n, gemma-iree and kgemma have drifted from the code (apiCheck red); refreshed in the same PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions