Qwen3.5 Chat (ऑन-डिवाइस LLM)

Qwen3.5-0.8B एक हाइब्रिड DeltaNet (linear attention) + GatedAttention मॉडल है जिसमें 24 layers (18 DeltaNet + 6 GatedAttention) हैं, MLX (Metal GPU) के लिए INT4 और CoreML (Neural Engine) के लिए INT8 में क्वांटाइज़ किया गया। Mac पर MLX के माध्यम से या iPhone और Mac पर CoreML के माध्यम से streaming token generation के साथ चलता है। वॉयस पाइपलाइन के लिए डिज़ाइन किया गया जहाँ एक ऑन-डिवाइस LLM ASR और TTS के बीच "ब्रेन" प्रदान करता है।

वॉयस पाइपलाइन तैयार

Qwen3.5 Chat ASR → LLM → TTS चेन में LLM कॉम्पोनेंट के रूप में SpeechCore VoicePipeline के साथ इंटीग्रेट होता है। हाइब्रिड DeltaNet आर्किटेक्चर लंबे संदर्भों के लिए कुशल linear-time attention प्रदान करता है।

त्वरित प्रारंभ

import Qwen3Chat

let chat = try await Qwen35MLXChat.fromPretrained()

// Single response
let response = try chat.generate("What is Swift?", systemPrompt: "Answer briefly.")
print(response)

// Streaming tokens
let stream = chat.chatStream("Tell me a joke", systemPrompt: "Be funny.")
for try await token in stream {
    print(token, terminator: "")
}

आर्किटेक्चर

Qwen3.5-0.8B 24 layers वाला एक हाइब्रिड मॉडल है: 18 DeltaNet layers (gated delta rule recurrence और RMSNormGated के साथ linear attention) और 6 GatedAttention layers (standard scaled dot-product attention)। MLX बैकएंड safetensors weights के साथ Metal GPU पर इन्फ़रेंस चलाता है। CoreML बैकएंड Neural Engine के लिए ऑप्टिमाइज़ किए गए dual-model आर्किटेक्चर (prefill + decode) का उपयोग करता है। दोनों prompt caching और कॉन्फ़िगर करने योग्य sampling (temperature, top-k, top-p, repetition penalty) के साथ KV cache का समर्थन करते हैं।

मॉडल I/O

दिशानामआकारविवरण
इनपुटinput_ids[1, seq_len]Token IDs (Int32)
इनपुटattention_mask[1, seq_len]Attention mask (Int32)
इनपुटkv_cacheper-layerKey-value cache state
आउटपुटlogits[1, 1, 151936]Next-token logits (Float16)
आउटपुटkv_cache_outper-layerUpdated KV cache

मॉडल वेरिएंट

वेरिएंटक्वांटिज़ेशनआकारकंप्यूटHuggingFace
Qwen3.5-0.8B ChatINT4418 MBMetal GPU (MLX)aufklarer/Qwen3.5-0.8B-Chat-MLX
Qwen3.5-0.8B ChatINT8981 MBNeural Engine (CoreML)aufklarer/Qwen3.5-0.8B-Chat-CoreML

Sampling कॉन्फ़िगरेशन

let config = ChatSamplingConfig(
    temperature: 0.7,
    topK: 40,
    topP: 0.9,
    maxTokens: 128,
    repetitionPenalty: 1.1,
    disableThinking: false,
    maxThinkingTokens: 50
)
let response = try chat.generate("Explain gravity", sampling: config)
पैरामीटरडिफ़ॉल्टविवरण
temperature0.6Randomness (0 = greedy, 1 = creative)
topK50टॉप K candidates रखें
topP0.95Nucleus sampling threshold
maxTokens512अधिकतम response tokens
repetitionPenalty1.1दोहराए गए tokens को दंडित करें
disableThinkingfalseThinking mode छोड़ें
maxThinkingTokens100Thinking tokens सीमा

Multi-turn Conversation

let chat = try await Qwen35MLXChat.fromPretrained()

let r1 = try chat.generate("My name is Alex", systemPrompt: "Remember the user's name.")
print(r1)  // "Nice to meet you, Alex!"

let r2 = try chat.generate("What's my name?")
print(r2)  // "Your name is Alex!"

chat.resetConversation()  // Clear history and KV cache

मेमोरी प्रबंधन

// Check memory state
print(chat.isLoaded)        // true
print(chat.memoryFootprint) // 438304768 (~418 MB)

// Free memory under pressure
chat.unload()
print(chat.isLoaded)        // false

// Reload when needed
let chat = try await Qwen35MLXChat.fromPretrained()
iOS मेमोरी टिप

iPhone पर, TTS इन्फ़रेंस से पहले LLM को अनलोड करने से ~418 MB (INT4 MLX) या ~981 MB (INT8 CoreML) फ़्री हो जाते हैं, जो पूर्ण ASR → LLM → TTS पाइपलाइन चलाते समय jetsam termination को रोकते हैं।

परफ़ॉर्मेंस

डिवाइसPrefillDecodeTokens/sec
M2 Max~50ms~65ms/tok~15 tok/s
iPhone 16 Pro~1.5s~450ms/tok~2.2 tok/s

कन्वर्ज़न

MLX weights MLX कन्वर्ज़न स्क्रिप्ट का उपयोग करके मूल Qwen3.5-0.8B checkpoint से कन्वर्ट किए जाते हैं। CoreML मॉडल Neural Engine डिप्लॉयमेंट के लिए एक अलग कन्वर्ज़न स्क्रिप्ट का उपयोग करते हैं। पूर्व-कन्वर्ट किए गए weights HuggingFace पर aufklarer/Qwen3.5-0.8B-Chat-MLX (INT4: 418 MB) और aufklarer/Qwen3.5-0.8B-Chat-CoreML (INT8: 981 MB) पर उपलब्ध हैं।