高效架构 道练习题
23 道题 · 0 已解决
随着序列增长,标准 attention 的开销会变得非常昂贵;随着模型变宽,dense models 的开销也会随之增加。高效架构通过共享工作、跳过工作或仅在需要时进行工作来降低这些成本。例如,mixture of experts 就像一家医院,它将每位患者送往合适的专家那里,而不是让每位医生看所有的病人。这些题目涵盖了当前 LLMs 中使用的主要技巧。你将对比 multi-head, grouped-query 和 latent attention 的 KV cache 大小;在 grouped-query attention 中共享 keys 和 values;将 attention 限制在 sliding window 内并使用 ring-buffer KV cache 进行解码;编写带有 running state 的 causal linear attention;计算 MoE 层中的 total 和 active parameters;将 tokens 路由到其前两个 experts;执行 expert capacity 限制;计算 Switch load-balancing loss;使用 Mixture-of-Depths 路由 tokens;以及合并相似的 tokens。从关于 KV cache 大小和 parameter counts 的 Easy 题目开始。然后进行 grouped-query attention 和 expert routing,最后完成 ring buffer, load balancing 和 token merging。这些设计决定了生产环境中的推理成本,面试官也经常会问到它们。
简单 9
- Limit attention to a sliding window of recent tokens
- Compare KV cache size for multi-head, grouped-query and latent attention
- Count total and active parameters of an MoE layer
- Compute model FLOPs utilization (MFU) for a training run
- Estimate KV cache memory with cross-layer KV sharing
- Choose which positions stay in an attention-sink streaming cache
- Build a local plus global attention mask
- Prune weights to 2:4 structured sparsity
- Compute savings from confidence-based early exit
中等 8
- Share keys and values across heads with grouped-query attentionPro
- Route each token to its top 2 experts in a mixture of expertsPro
- Causal linear attention with a running statePro
- Route tokens with expert capacity and drop the overflowPro
- Route tokens with Mixture-of-DepthsPro
- Implement top-k sparse attention per queryPro
- Evict KV cache entries while keeping heavy hitters and recent tokensPro
- Pick the rank that keeps a target energy in a low-rank factorizationPro
困难 6
- Compute the Switch Transformer load-balancing lossPro
- Decode with a sliding-window KV cache stored as a ring bufferPro
- Merge similar tokens with bipartite matchingPro
- Select key blocks by compressed scores, then attend inside themPro
- Compute multi-head latent attention scores from the latent cachePro
- Run the gated delta rule for linear attentionPro