Kotlin/Native inference produces deterministic nonsense across model families and runtime paths (JVM unaffected)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- kotlin
调研方向
Start by comparing token_embd.weight[0,:] on JVM and Kotlin/Native, as the issue suggests, to check whether Q8 dequantization diverges. If the weights match, inspect the shared RoPE, attention mask, and KV cache helpers used by both runtimes. Done means Kotlin/Native inference produces sensible output on the listed models and matches the JVM path.
由索引模型根据 Issue 内容生成。
描述
Kotlin/Native inference produces deterministic nonsense across model families and runtime paths (JVM unaffected)
Summary
On Kotlin/Native (verified on macosArm64 against SKaiNET-transformers develop @ commit 4cd1da9, SKaiNET 0.23.0), generating tokens via the kllama runtime — and via OptimizedLLMRuntime + QwenNetworkLoader — produces deterministic but meaningless token sequences. The same model files generate sensibly on the JVM target. Issue persists across:
- Both runtime paths: deprecated
LlamaRuntime+LlamaIngestion, and the newOptimizedLLMRuntime+QwenNetworkLoader.fromGguf(...).load(...). - Both load paths: sequential (
sourceProvider, slurps toByteArray) and streaming (randomAccessProvider, exercises the new POSIX-preadRandomAccessSourceshipped in 0.23.0 / #591). - Multiple model families:
Llama-3.2-1B-Instruct(Q8),TinyLlama-1.1B-Chat-v1.0(Q8, Llama-2 arch),Qwen2.5-0.5B-Instruct(Q8),Qwen3-1.7B-Q8_0(Q8). - Multiple compute backends: the SKaiNET CPU backend, and an external macOS-native execution backend wired in via
BackendRegistry.register(...). OnQwen2.5-0.5B, the two backends emit bit-for-bit identical output — same garbage, same tokens, same order, every run. That's the cleanest signal that the problem is upstream of the compute layer: two differentTensorOpsimplementations agree perfectly, which only happens if the bug is somewhere they share (weight load, dequantization, the runtime's forward orchestration, or some K/N stdlib / cinterop quirk).
Reproduction
The shortest repro uses SKaiNET-transformers' own native CLI binary (no third-party code involved):
./gradlew :llm-runtime:kllama:linkReleaseExecutableMacosArm64
./llm-runtime/kllama/build/bin/macosArm64/releaseExecutable/kllama.kexe \
/path/to/Llama-3.2-1B-Instruct-Q8_0.gguf \
"The capital of France is" 32 0.0
Output, deterministic on every restart:
Generating 32 tokens with temperature=0.0...
---
Bodies Bodies Bodies Bodies Bodies Bodies … reigning reigning reigning
Same kllama binary on tinyllama-1.1b-chat-v1.0.Q8_0.gguf:
witzwitzwitzwitzwitzwitzwitzwitzwitzwitzwitzwitz…
OptimizedLLMRuntime + QwenNetworkLoader on Qwen2.5-0.5B-Instruct-Q8_0.gguf (in a small consumer CLI we built to verify the streaming path works):
bynDRAM ASAP */čĊčĊčĊ appréci(animation mur Offline bénéfic coppia wrzeÅĽnia…
All deterministic at temperature 0.0; tokens are within vocab but semantically nonsense.
Cleanest single repro for triage
Two consumer CLI invocations, same prompt, same model, two different BackendProviders:
$ ./llama3-native-cli -m Qwen2.5-0.5B-Instruct-Q8_0.gguf --backend cpu --steps 32 --temperature 0.0 "What is 17 * 23?"
Backend: CPU (SIMD) (priority=0)
Tokenizer: BPE (model=gpt2)
Assistant: bynDRAM ASAP */čĊčĊčĊ appréci(animation mur Offline bénéfic coppia wrzeÅĽnia{i]';Ċodonå¡ijåįķä½įæĪĬ åŃĹéducationLUaniobihrÃł,GLæĭ¼éٳournemouth_endian)$_.AdapterView.nlmMurlu
$ ./llama3-native-cli -m Qwen2.5-0.5B-Instruct-Q8_0.gguf --backend platform-native --steps 32 --temperature 0.0 "What is 17 * 23?"
Backend: Platform-native (macOS) (priority=100)
Tokenizer: BPE (model=gpt2)
Assistant: bynDRAM ASAP */čĊčĊčĊ appréci(animation mur Offline bénéfic coppia wrzeÅĽnia{i]';Ċodonå¡ijåįķä½įæĪĬ åŃĹéducationLUaniobihrÃł,GLæĭ¼éٳournemouth_endian)$_.AdapterView.nlmMurlu
Bit-for-bit identical output across two completely different TensorOps implementations. Same prompt on the JVM target with the same loader stack produces sensible output.
What's been ruled out
- EOS resolution:
tokenizer.eosTokenId == 128009(<|eot_id|>) for Llama-3.2 — correct. Confirmed via diagnostic print beforeruntime.generate(...). - Backend correctness on small models: Qwen2.5-0.5B → bit-identical output on two different backends (proof above). Rules out compute layer for small / single-block-size cases.
- Tool calling / agent loop: gibberish reproduces with the raw
kllama.kexebaseline that does no tool calling at all —runtime.generate(...)straight afterLlamaIngestion.load(...). - GGUF reader path: same gibberish via the legacy
Source-based reader and via the new POSIX-preadStreamingGGUFReaderpath. Not a slurp-vs-stream issue. - JVM: same loaders + runtimes, exercised via the existing JUnit test suite (gated on
TINYLLAMA_MODEL_PATH), produce sensible output on the JVM target. K/N-specific. - 0.23.0 fixes: the K/N pread fix (#591) and the lazy zero-init API (#588) did not change the symptom.
Most likely places to look
Ordered by suspicion (the TensorOps-agnostic invariant pins this somewhere shared):
- GGUF Q8 dequantization on K/N.
QuantPolicy.DEQUANTIZE_TO_FP32is the only K/N-viable policy (MemSegWeightConverterisjvmMain-only). If the K/N Q8 dequant has a bug, every downstream tensor is silently corrupted; both backends consume the same corrupt tensors and produce the same nonsense — exactly what we see. A quick verification path: snapshot a known weight tensor (e.g.token_embd.weight[0,:]) on JVM and on K/N and compare element-wise; first divergence localises the bug. OptimizedLLMRuntime/LlamaRuntimeforward orchestration on K/N. Both runtimes are independent code paths and both fail identically — but they share helpers (RoPE position table, attention mask construction, KV cache layout). A K/N-specific bug in one of those helpers would surface in both.- K/N stdlib / cinterop edge case — less likely but possible. E.g.
FloatArrayof unusual size silently zeroing a tail, or a cinterop boundary on Accelerate calls passing wrong sizes.
(1) is by far the most likely; would suggest tackling first because it's the easiest to falsify with a one-page test.
Separate, related bug (filing separately, not this issue)
On larger models (Qwen3-1.7B-Q8_0, ~1.8 GiB) the CPU backend and platform-native backend diverge — produce different nonsense. That divergence is real backend-side disagreement and points at one or more compute ops the larger / GQA-using architecture exercises that the small Qwen2.5-0.5B doesn't. This is a backend issue, separate from the K/N inference bug above; mentioned only because it confirms (1)/(2) as different from (3).
Why this matters
K/N is the only target for consumers shipping single-binary CLIs or non-JVM mobile/desktop apps on top of SKaiNET-transformers. The JVM-only happy path is fine for backend services but rules out a large slice of intended consumers. The K/N native CLI in this repo (kllama.kexe) currently doesn't generate sensible output for any tested model — that's a strong "K/N is broken end-to-end" signal worth attending to even before any external consumer.
Triage helpers
- Same machine, same JDK toolchain (21), same model files. Only the Kotlin target differs.
- Tested against
release/0.23.0of SKaiNET (commite0b228c2plus the docs cleanup) anddevelopof SKaiNET-transformers @4cd1da9. - Happy to produce a JVM-vs-K/N logits diff (forward pass on a fixed input, position 0, first 16 logits) on request — that should localise where the K/N path diverges.
- 主要语言
- Kotlin
- 星标
- 8
- 派生
- 3
- 平均合并
- 1 天 16 小时
- 30 天内合并 PR
- 48
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
SKaiNET-developers/SKaiNET-transformers 的其他 Issue
-
documentation good first issue size:xs skill:docs sub-issue
难度 2/5 1-3 小时 新手友好度 78/100
SKaiNET-developers/SKaiNET-transformers#478 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement skill:kotlin-core
难度 4/5 3-5 天 新手友好度 48/100
SKaiNET-developers/SKaiNET-transformers#502 ·
维护者通常 1 天内回复
-
bug
难度 4/5 3-5 天 新手友好度 48/100
SKaiNET-developers/SKaiNET-transformers#483 ·
维护者通常 1 天内回复
-
coding good first issue size:s skill:kotlin-core sub-issue
难度 4/5 1-2 天 新手友好度 64/100
SKaiNET-developers/SKaiNET-transformers#477 · 1 条评论 ·
维护者通常 1 天内回复
-
coding good first issue size:s skill:numerics sub-issue
难度 4/5 3-5 天 新手友好度 55/100
SKaiNET-developers/SKaiNET-transformers#476 · 1 条评论 ·
维护者通常 1 天内回复
查看 SKaiNET-developers/SKaiNET-transformers 的全部 Issue
相似的 Issue
-
design good first issue help wanted
难度 2/5 1-3 小时 新手友好度 68/100
scribe-org/Scribe-Android#739 ·
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 76/100
xybrid-ai/xybrid#661 · 1 条评论 ·
维护者通常 1 天内回复
-
android bug kotlin vulkan
难度 2/5 1-3 小时 新手友好度 68/100
maplibre/maplibre-native-ffi#852 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 1/5 1 小时以内 新手友好度 86/100
维护者通常 1 天内回复