Traduzione automatica · Originale inglese
Chat Qwen3.5 (On-Device LLM)
Qwen3.5-0.8B è un ibrido DeltaNet (attenzione lineare) + GatedAttention modello con 24 strati (18 DeltaNet + 6 GatedAttention), quantizzato a INT4 per MLX (Metal GPU) e INT8 per CoreML (Neural Engine). Corre su Mac via via via via MLX o su iPhone e Mac via via via via CoreML con generazione di token di streaming. Progettato per le tubazioni vocali dove un on-device LLM fornisce il "brain" tra ASR e TTS.
Qwen3.5 Chat si integra con la SpeechCore VoicePipeline come componente LLM in ASR → LLM, → catene TTS: l'architettura ibrida DeltaNet fornisce un'attenzione efficiente a tempo lineare per lunghi contesti.
Avvio rapido
import Qwen3Chat
let chat = try await Qwen35MLXChat.fromPretrained()
// Single response
let response = try chat.generate(messages: [
ChatMessage(role: .system, content: "Answer briefly."),
ChatMessage(role: .user, content: "What is Swift?")
])
print(response)
// Streaming tokens
let stream = chat.generateStream(messages: [
ChatMessage(role: .system, content: "Be funny."),
ChatMessage(role: .user, content: "Tell me a joke")
])
for try await token in stream {
print(token, terminator: "")
}
Architettura
Qwen3.5-0.8B è un modello ibrido con 24 strati: 18 strati DeltaNet (attenzione lineare con recidiva delta gated e RMSNormGated) e 6 GatedAttention strati (attenzione standard del prodotto del punto). MLX backend corre l'inferenza sul Metal GPU con pesi safetensors. CoreML backend utilizza un'architettura dual-model (prefill + decode) ottimizzata per il Neural Engine. Entrambi supportano la cache KV con la cache rapida e il campionamento configurabile (temperatura, top-k, top-p, penalità di ripetizione).
Modello I/O
| Direzione | Nome | Forma | Designazione |
|---|---|---|---|
| Input | input_ids | [1, seq_len] | ID gettoni (Int32) |
| Input | attention_mask | [1, seq_len] | Maschera di attenzione (Int32) |
| Input | kv_cache | per strato | Stato della cache di valore chiave |
| Produzione | logits | [1, 1, 151936] | Tronchi successivi (Float16) |
| Produzione | kv_cache_out | per strato | Aggiornamento della cache KV |
Varianti di modello
| Variante | Quantificazione | Dimensione | Competenze | HuggingFace |
|---|---|---|---|---|
| Chat Qwen3.5-0.8B | INT4 | 418 MB | Metal GPU (MLX) | aufklarer/Qwen3.5-0.8B-Chat-MLX |
| Chat Qwen3.5-0.8B | INT8 | 981 MB | Neural Engine (CoreML) | aufklarer/Qwen3.5-0.8B-Chat-CoreML |
Configurazione di campionamento
let config = ChatSamplingConfig(
temperature: 0.7,
topK: 40,
topP: 0.9,
maxTokens: 128,
repetitionPenalty: 1.1
)
let response = try chat.generate(
messages: [ChatMessage(role: .user, content: "Explain gravity")],
sampling: config
)
| Parametro | Predefinito | Designazione |
|---|---|---|
temperature | 0.6 | Randomness (0 = avido, 1 = creativo) |
topK | 50 | Tenere i migliori candidati K |
topP | 0.95 | Soglia di campionamento Nucleo |
maxTokens | 512 | Max token di risposta |
repetitionPenalty | 1.1 | Penalize token ripetuti |
disableThinking | falso | Salta la modalità di pensiero |
maxThinkingTokens | 100 | Cap token di pensiero |
Conversazione multi-turn
let chat = try await Qwen35MLXChat.fromPretrained()
let history = [
ChatMessage(role: .system, content: "Remember the user's name."),
ChatMessage(role: .user, content: "My name is Alex"),
ChatMessage(role: .assistant, content: "Nice to meet you, Alex!"),
ChatMessage(role: .user, content: "What's my name?")
]
let response = try chat.generate(messages: history)
print(response) // "Your name is Alex!"
chat.resetState() // Clear inference state for a new conversation
Gestione della memoria
// 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()
Su iPhone, scaricare il LLM prima di TTS inferenza libera ~418 MB (B)INT4 MLX) o981 MB (B)INT8 CoreML), prevenire la terminazione del getto quando si esegue a pieno ASR → LLM → TTS tubazioni.
Prestazioni
| Dispositivo | Precaricare | Denominazione | Tokens/sec |
|---|---|---|---|
| M2 Max | - 50ms | ~65ms/tok | ~ 15 tok/s |
| iPhone 16 Pro | - 1,5. | ~450ms/tok | ~2.2 tok/s |
Conversione
I pesi MLX vengono convertiti dal checkpoint originale Qwen3.5-0.8B utilizzando lo script di conversione MLX . I modelli CoreML utilizzano uno script di conversione separato per l'implementazione Neural Engine, mentre i pesi preconvertiti sono disponibili su HuggingFace aufklarer/Qwen3.5-0.8B-Chat-MLX (INT4: 418 MB) e aufklarer/Qwen3.5-0.8B-Chat-CoreML (INT8: 981 MB).