Building an LLM Inference Engine from ScratchFront Page / Table of Contents
教程首页

从零构建 LLM 推理引擎

本教程以 xinfer 为对象,说明如何用 Rust、DirectML 与 D3D12 实现一个可运行 Qwen2.5 的 LLM 推理引擎,并覆盖 GPU kernel、KV cache、采样、性能优化与 Xbox GDK 部署。

Part 0 — Tutorial Orientation

Part I — Foundations: Large Language Models

Part II — Foundations: GPU Compute & Shaders

Part III — The Concrete Candidates

  • Module 7
    Qwen2 / Qwen2.5 模型

    读取 config.json、safetensors 与 dtype 信息,建立 Qwen2/Qwen2.5 的模型尺寸和显存估算方法。

  • Module 8
    DirectML 与 Direct3D 12 Backend

    讨论 DirectML operator 生命周期、HLSL kernel、RDNA4 GEMM device removed 问题,以及 PC/Xbox device creation。

Part IV — Implementation: Building xinfer

Part V — Performance Engineering

  • Module 15
    先测量,再优化

    建立 benchmark、prefill/decode tok/s、memory reporting、bottleneck 分类与 regression gate。

  • Module 16
    六层优化案例

    分析 batching、f16 权重、coalesced GEMV、single-pass attention、cooperative RMSNorm 与 GPU argmax。

  • Module 17
    高级优化方向

    概述量化、tiled GEMM、fused epilogues、GPU sampling、speculative decoding 与 paged KV。

Part VI — Portability & Deployment

  • Module 18
    Xbox GDK 部署路径

    说明 Rust C ABI staticlib、C++ GDK host、device injection、ctypes 验证与 GDK desktop 流程。

  • Module 19
    Productionizing

    整理 logging/tracing、GenerateStats、memory reporting、CLI、reproducibility 与 README 要求。

Appendices