Unified Model Pipeline with Decoupled Tool Calling
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
Hướng nghiên cứu
Read the Phase 1 audit linked in the issue comment and the pending W2 stack (#296 → #297 → #299) to establish what remains; Phase 1 is reported done, while Phases 2–4 are open. For a scoped starting point, inspect llm-core/.../OptimizedLLMRuntime.kt, llm-core/.../dsl/TransformerDsl.kt, and llm-core/.../weights/LLMWeightNameResolvers.kt; the issue calls for DSL networks across model families and a unified runner, but does not define a single completion criterion for those phases.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Context
Currently SKaiNET-transformers has:
- 5+ hand-coded runtimes (LlamaRuntime, Qwen35Runtime, Gemma3nRuntime, ApertusRuntime, VoxtralRuntimes) — each reimplements the forward pass, weight loading, and layer execution
- Tool calling tightly coupled to kllama — the AgentLoop, ToolCallingDemo, and chat modes only exist in the kllama runner. Other models (Gemma, Apertus) cannot use tool calling without duplicating code
- Two execution paths — legacy hand-coded runtimes AND the newer
OptimizedLLMRuntimewith DSL/compute-graph/AOT. LlamaRuntime and ApertusRuntime are already marked deprecated
The goal: converge on one unified pipeline where model definition, weight loading, tokenization, and tool calling are cleanly separated pipeline stages.
Architecture Overview
GGUF/SafeTensors File
|
WeightLoader (parse metadata + tensors)
|
DSL Network Definition (model-specific, declarative)
|
ComputeGraph (DAG)
|
Optimization Pipeline (TransposeElim -> WeightDedup -> LLMFusion -> DCE)
|
ComputeGraphExecutor (fused kernels)
|
InferenceRuntime (unified: forward + generate)
|
TokenizationPipeline (encode/decode, special tokens, byte-level BPE)
|
ChatPipeline (template formatting, tool calling, agent loop)
Status
- Phase 1: DONE (pending merge of the W2 stack #296 → #297 → #299) —
generateUntilStop/GenerateResultpromoted tollm-core(#296),ChatSessionshipped earlier (f42617a), demo/agent CLI + tools extracted from kllama intollm-agent(#296); kllamaMain.ktdispatch is now ~25 thin lines over shared classes. Audit details: https://github.com/SKaiNET-developers/SKaiNET-transformers/issues/49#issuecomment-5255175760 - Phases 2-4: open (out of W2 scope). Note the unified
skainet-cliseed exists but thellm-appsmodules currently fail dependency resolution on develop (empty engine version) — needs a small separate fix.
Phase 1: Decouple Tool Calling from kllama (immediate value)
Problem: Tool calling lives in llm-agent (good) but is wired only through kllama CLI. Other runners can't use it.
Changes:
-
Move AgentLoop's generation into
InferenceRuntimeinterface (llm-core)generateUntilStop()is currently an extension function inllm-agent— promote it or add agenerate()method with stop-token support to the interface- File:
llm-core/.../InferenceRuntime.kt
-
Create
ChatSessionabstraction (llm-agent)- Bundles:
InferenceRuntime+Tokenizer+ChatTemplate+ToolRegistry - Any runner creates a
ChatSessionto get chat/agent/demo modes for free - File: new
llm-agent/.../ChatSession.kt
- Bundles:
-
Extract CLI chat/agent/demo dispatch from kllama Main.kt into shared module
- Currently lines 532-551 of
Main.ktdispatch toToolCallingDemo/AgentCli - This logic should work for any runner that provides
InferenceRuntime+Tokenizer
- Currently lines 532-551 of
Critical files:
llm-core/.../InferenceRuntime.kt— extend interfacellm-agent/.../AgentLoop.kt— already well-abstracted, keep as-isllm-runtime/kllama/.../Main.kt— extract dispatch logicllm-runtime/kllama/.../ToolCallingDemo.kt— move tollm-agentorllm-appsshared module
Phase 2: Unified DSL-Based Model Definition (converge on OptimizedLLMRuntime)
Problem: Each model has a hand-coded runtime. OptimizedLLMRuntime already supports DSL -> graph -> optimized execution, but only some models use it.
Changes:
-
Define DSL networks for all model families:
llamaNetwork(config)— LLaMA/Mistral/Qwen2/3 (standard transformer)qwen35Network(config)— Qwen3.5 (hybrid DeltaNet + full attention)gemmaNetwork(config)— Gemma (GELU, MatFormer FFN, sliding window)apertusNetwork(config)— Apertus (xIELU, ungated MLP, QK-norm)- Each is a pure function returning a
Network<T>from the DSL
-
Unified model loading flow:
detectArchitecture(ggufMetadata) -> ModelFamily ModelFamily.createNetwork(config) -> Network<T> WeightLoader.loadAndMap(file, network) -> weights OptimizedLLMRuntime(network, weights, mode=HYBRID) -> InferenceRuntime -
Remove deprecated hand-coded runtimes once DSL equivalents are validated:
LlamaRuntime->llamaNetwork()+OptimizedLLMRuntimeApertusRuntime->apertusNetwork()+OptimizedLLMRuntime
Critical files:
llm-core/.../OptimizedLLMRuntime.kt— already exists, extendllm-core/.../dsl/TransformerDsl.kt— already has embedding, MHA, SwiGLU, RMSNormllm-core/.../weights/LLMWeightNameResolvers.kt— already maps DSL paths -> GGUF names- New: per-model DSL network definitions
Phase 3: Tokenization as Pipeline Stage
Problem: Tokenization is split between GGUFTokenizer (kllama module), QwenByteLevelBPETokenizer (llm-core), and model-specific code. The byte-level BPE fix we just made shows the fragility.
Changes:
-
Enhance
Tokenizerinterface (llm-core):interface Tokenizer { fun encode(text: String): IntArray fun decode(token: Int): String fun decode(tokens: IntArray): String val eosTokenId: Int val bosTokenId: Int val vocabSize: Int val specialTokens: Set<String> } -
Unified tokenizer factory:
TokenizerFactory.fromGGUF(source)— auto-detects BPE/SentencePiece/WordPieceTokenizerFactory.fromTokenizerJson(json)— HuggingFace format- Returns the correct implementation (byte-level BPE for GPT-2/Qwen, SentencePiece for LLaMA, etc.)
-
Move
GGUFTokenizertollm-coreso all runners can use it without depending on kllama
Phase 4: Unified Runner (single CLI entry point)
Problem: 6 separate CLI apps with duplicated argument parsing, model loading, and dispatch logic.
Changes:
-
Single
skainetCLI that auto-detects model architecture from GGUF metadata:skainet -m model.gguf "prompt" # auto-detect, generate skainet -m model.gguf --chat # auto-detect, chat mode skainet -m model.gguf --demo "What is 2+2?" # auto-detect, tool calling -
Architecture registry:
ModelRegistry.register("llama", ::llamaNetwork) ModelRegistry.register("qwen3", ::qwenNetwork) ModelRegistry.register("gemma", ::gemmaNetwork) -
Auto-detection from GGUF metadata (already exists in
peekGgufMetadata())
Verification
- All existing unit tests pass (
llm-agent,llm-runtime:kllama,llm-core) - Smoke test suite passes (generation + tool calling)
- Basic generation produces identical output for all model families
- Tool calling works for any model that supports ChatML/Qwen/Llama3 templates
OptimizedLLMRuntimein HYBRID mode matches hand-coded runtime output
- Ngôn ngữ chính
- Kotlin
- Star
- 8
- Fork
- 3
- Merge trung bình
- 1 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 48
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SKaiNET-developers/SKaiNET-transformers
-
documentation good first issue size:xs skill:docs sub-issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
SKaiNET-developers/SKaiNET-transformers#478 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement skill:kotlin-core
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
SKaiNET-developers/SKaiNET-transformers#502 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
SKaiNET-developers/SKaiNET-transformers#483 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
coding good first issue size:s skill:kotlin-core sub-issue
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 64/100
SKaiNET-developers/SKaiNET-transformers#477 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
coding good first issue size:s skill:numerics sub-issue
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
SKaiNET-developers/SKaiNET-transformers#476 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của SKaiNET-developers/SKaiNET-transformers
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Droid-Deck/DroidDeck#1098 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Blank screen in Download tab after searching with no results and switching tabsCó thể đã có người làm @mangod12 đã nhận hôm nay. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
kiwix/kiwix-android#5211 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
deniscerri/ytdlnis#1430 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Lock owned by another client (e.g. Text app) cannot be unlocked from the appCó thể đã có người làm @falkloewert đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Minor documentation improvementsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100