Skip to content

TensorDump forward hook + TensorCompare CLI: localise numeric divergence between two runs #1280

Description

@michalharakal

Context

The most expensive part of bringing a large model to a phone is not the port, it is finding where numerics diverge between two executions of the same model: FP32 reference vs a quantized or FP16 backend, desktop vs device, eager vs compiled. The downstream Whisper-on-LiteRT case study needed ad-hoc per-block probes to localise an FP16 LayerNorm overflow to block 31 of 32 and an INT8 projection error to the block-0 K projection — all built by hand, twice, in Python and in Kotlin.

SKaiNET has the hooks (ForwardHooks, ExecutionObserver, TraceSink) but no standard artifact that two runs can exchange, and no standard comparison.

Scope

  • TensorDump: a forward hook that writes named intermediate tensors (by module path and op index) to one compact binary file — header with name, shape, dtype/encoding, then payload — appendable, streaming, no heap copy of the whole run. Works on JVM, Android and Kotlin/Native.
  • TensorCompare: a library function + CLI (skainet-plan-style) taking two dumps and reporting per tensor: cosine, RMSE, max abs diff, index of first divergence above a tolerance, and a summary that names the first tensor that crosses the tolerance (the localisation answer).
  • Filters: dump only tensors matching a module-path glob, every N-th op, or a shape predicate, so a 32-layer encoder does not produce gigabytes.
  • Documented recipe in the how-to section: "compare a device run against a desktop reference" with the two commands.
  • Used in-tree at least once: the .vmfb parity acceptance (.vmfb parity acceptance run (eager vs compiled) #1148) or the JNI parity tests read/write this format instead of bespoke arrays.

Acceptance

  • A dump from an Android androidTest run and a dump from a JVM test of the same model compare in one command and point at the first divergent tensor.
  • Format documented and versioned; readable from Python with a short reference reader in ground-truth tooling.

Related

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

    enhancementNew feature or requestskill:kotlin-coreKotlin implementation in commonMainskill:numericsPyTorch/NumPy/math background, no Kotlin required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions