Step 3 · Models · Models · Text Models and Quantization PT
Local AI Cluster · Visual Course

Text Models and Quantization

Compare Qwen3.6-35B-A3B, DeepSeek-V4-Flash and Gemma 4; understand how quantization decides what fits in 128 GB.

Lesson objectives
  • Compare Qwen3.6-35B-A3B, DeepSeek-V4-Flash and Gemma 4.
  • Interpret quantization formats: Q4_K_M, UD-IQ3_XXS, 8-bit.
  • Choose the right model for text, code and long context.
Read first (primary source)
Hugging Face — mlx-community

Coleção de modelos convertidos para MLX; usada para escolher tamanhos e quantizações que cabem no M5 Max.

Read the simple version, or open the technical layer in any section.
1

The big idea


Modelos de IA são enormes. Para caber no Mac, usamos quantização: representar cada peso com menos bits. Quanto menos bits, menor e mais rápido, mas com leve perda de qualidade. O segredo é escolher a quantização certa para cada tarefa.

Pense em compressão de música: MP3 de 128 kbps é pequeno e "bom o suficiente"; FLAC é enorme e fiel. Para ouvir no carro, MP3 vale a pena; para masterização, você quer FLAC.

Under the hood

Quantization reduces weight precision (and optionally KV-cache precision). On the M5 Max 128 GB, Q4_K_M or 4bit is the sweet spot: perplexity degradation is typically only 1–3% versus FP16. Q3 visibly drops on long reasoning and code; Q2/IQ2 are only worthwhile for giant-context workloads where window size matters more than fidelity. Q8_0/8-bit is used when maximum quality is critical and the model still fits.

Q8_0 / 8-bit alta fidelidade Q4_K_M / 4-bit ponto ideal UD-IQ3_XXS ~3 bits IQ2_XXS ~2 bits FP16 Menos bits → menor, mais rápido, mas com mais perda de qualidade
Espectro de quantização: escolha pelo trade-off tamanho vs qualidade.
2

Os modelos de texto


For text/code/RAG, Qwen3.6-35B-A3B is the main recommendation: ~80 tok/s in 8-bit on the M5 Max 128 GB, 256K context, strong in Portuguese and a leader in code benchmarks. For extreme 1M-token context, DeepSeek-V4-Flash fits tightly in 3-bit (~103 GB). Gemma 4 also handles text, but shines in multimodal tasks.

Under the hood

Qwen3.6-35B-A3B is MoE (~35B total, ~3B active per token), measured at ~80–110 tok/s on the M5 Max 128 GB with 256K context. Detailed quality benchmarks (SWE-Verified, MMLU) are proxies based on the Qwen3.5-35B-A3B architecture; use it as the speed/memory balance engine. DeepSeek-V4-Flash is MoE 284B/~13B active, Arena ELO 1431, up to 1M context. Gemma-4-31B is dense, Arena ELO 1441–1452, MMLU-Pro 85.2%, 256K context, native multimodal. Qwen3.5-122B-A10B delivers ELO 1418 and 262K context; GLM-5.2 reaches ELO 1465.

Cross-model benchmarks (July 2026)

ModelLocal speed*LLMCheckSWE-VerifiedMMLUArena ELOContextQuantizationMultilingual
Qwen3.6-35B-A3B~80–110 tok/s~70%*~86%*~1396*256K8bit ~22–28 GB / 4bit ~14 GBStrong PT/EN
DeepSeek-V4-Flash~34 tok/s (IQ2/UD-IQ3)14311MUD-IQ3_XXS ~103 GB
Gemma 4 31BMMLU-Pro 85.2%1441–1452256K4bit ~20 GBMMMLU 88.4%
Gemma 4 26B-A4B~50 tok/s256K4bit ~18 GB
Qwen3.5-122B-A10B1418262K4bit ~70 GBMMMLU 86.7%
GLM-5.21465varies

*Speeds measured on an M5 Max 128 GB with MLX; tok/s depend on prompt and system load. SWE-Verified, MMLU and Arena ELO values for Qwen3.6-35B-A3B are proxies based on Qwen3.5-35B-A3B and community reports.

Qwen3.6-35B-A3B ~22–28 GB · 256K ctx DeepSeek-V4-Flash ~103 GB · 1M ctx Gemma-4-31B ~20 GB · 256K ctx Llama-4 Scout ~60 GB · 10M theoretical Approximate memory use at recommended quantizations 128 GB fits Qwen + Gemma together, or DeepSeek alone tightly
Memory and context comparison for the main text models.
3

Inference optimization


Além de quantizar pesos, você pode quantizar a KV cache (memória de contexto), ativar Flash Attention e usar speculative decoding (um modelo pequeno sugere tokens que o grande confirma). Essas técnicas multiplicam a janela de contexto e a velocidade.

Under the hood

KV cache quantization reduz memória de estados chave/valor em 1,3–6,4×. Flash Attention diminui acessos à HBM. Speculative decoding usa um draft model para gerar candidatos. No MLX: --kv-bits 8 e --max-kv-size 65536; no Ollama: OLLAMA_KV_CACHE_TYPE=q8_0.

KV cache quant menos memória de contexto Flash Attention atenção eficiente Speculative decoding draft + verificação
Três alavancas para contexto longo e velocidade.
Terminal · otimização
# KV cache quantization on MLX
python -m mlx_lm.server --model mlx-community/Qwen3.6-35B-A3B-8bit   --kv-bits 8 --max-kv-size 65536

# Ollama com KV cache q8_0
export OLLAMA_KV_CACHE_TYPE=q8_0
ollama serve

# Speculative decoding com draft model
python -m mlx_lm.generate --model large_model   --draft-model small_draft_model --num-draft-tokens 4
4

Try it


Test what you learned with quick exercises.

Qual quantização é o ponto ideal no M5 Max 128 GB para modelos até ~70B?
b está correta. Q4_K_M oferece o melhor equilíbrio qualidade/tamanho. Q8_0 é para fidelidade crítica; IQ2_XXS é para modelos muito grandes com perda perceptível.
Guided exercise
1
Read the model size: Qwen3.6-35B-A3B-8bit ≈ 22–28 GB.
2
Check free space: 128 GB − 25 GB ≈ 103 GB for KV cache and system.
3
If you also want to run Gemma-4-26B-A4B-4bit (~18 GB), add: 25 + 18 = 43 GB — fits comfortably.
4
Now you: DeepSeek-V4-Flash UD-IQ3_XXS ≈ 103 GB. It fits alone, but not together with Qwen 8-bit.
Recall
Qual modelo usar para contexto de 1M tokens localmente?
Click to flip
DeepSeek-V4-Flash em GGUF UD-IQ3_XXS (~103 GB) via llama.cpp, Ollama ou ds4. Cabe apertado em 128 GB.
Recall
O que é speculative decoding?
Click to flip
Um modelo pequeno gera tokens candidatos rapidamente; o modelo grande verifica vários de uma só vez, acelerando a geração.
Questions? Ask your teacher/agent before moving to the next lesson.