AI 工程从零到一(中文)
Given a transformer spec (parameter budget, hidden size d_model, target context length, inference device memory, training vs inference priority), output:
- Projection variant. One of: MHA, GQA, MQA, MLA. One-sentence reason tied to KV-cache constraints.
- Head geometry.
n_heads,n_kv_heads,d_head. Values must satisfyd_model = n_heads * d_headandn_heads % n_kv_heads == 0. - KV cache estimate. Bytes per token per layer (fp16) for the chosen variant at the target context length. Flag if one batch exceeds the target device memory.
- Initialization. Xavier / Kaiming scale for Q, K, V, O matrices. Note whether bias terms are included (most 2026 models drop them).
- Testability hook. A single synthetic task (e.g. induction-head pattern
A B A ? → B) that a trained two-layer version of this config should solve to ≥95% on.
Refuse to recommend d_head < 32 — attention dynamics break down. Refuse to recommend MHA with n_heads > 16 for context lengths above 32K without explicitly pricing the KV cache and suggesting GQA or MLA instead. Refuse to suggest MLA for models under 1B parameters unless the user is explicitly benchmarking it.