Nanoflow

efeslab更新放缓

面向吞吐量优化的高性能 LLM 服务框架,通过 CUDA 加速提升大模型推理的并发处理能力。

A throughput-oriented high-performance serving framework for LLMs

暂无版本976star55fork同步于 2026-11-07 07:31 UTC

怎么上手

由 README 提炼,执行前请确认
docker run --gpus all --net=host --privileged -v /dev/shm:/dev/shm --name nanoflow -v ~/framework-test:/code -it nvcr.io/nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04
cd pybind && mkdir -p build && cd build && cmake .. && make -j 256
硬件要求按 README 说明

README 的评测基于 A100 80GB SXM(8 卡跑 Llama2-70B),实现面向 NVIDIA GPU;未说明 CPU 运行或其他 GPU 厂商支持情况。

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

面向吞吐优化的 LLM 高性能服务框架,通过单设备内并行重叠计算、访存与网络操作

面向吞吐量优化的高性能 LLM 服务框架,通过 CUDA 加速提升大模型推理的并发处理能力。

核心能力

  • 用 nano-batching 按算子粒度切分请求以打破串行依赖
  • 按执行单元调度做设备级流水,重叠计算、访存、网络操作
  • 异步 CPU 调度,提前为下一轮迭代做批处理与 KV-cache 分配
  • 将完成请求的 KV-cache 逐层卸载到 SSD 以复用多轮对话缓存
  • 集成 CUTLASS、FlashInfer、MSCCL++ 等算子与通信库

容易踩的坑

需要自行申请并配置 Gurobi 许可证(gurobi.lic),否则流水线参数搜索无法运行;需先执行 sysctl 开启 io_uring 并设置 hugepages;需登录 HuggingFace 并下载模型权重,端到端测试用 -load_hf_weight=True 触发。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Nanoflow

    NanoFlow is a throughput-oriented high-performance serving framework for LLMs. NanoFlow consistently delivers superior throughput compared to vLLM, Deepspeed-FastGen, and TensorRT-LLM. NanoFlow achieves up to 1.91x throughput boost compared to TensorRT-LLM. The key features of NanoFlow include:

    • Intra-device parallelism: Maximizes hardware utilization by exploiting nano-batching and execution unit scheduling to overlap different resource demands inside a single device.
    • Asynchronous CPU scheduling: Achieves highly efficient CPU scheduling by adopting asynchronous control flow for GPU execution, CPU batch formation and KV-cache management.

    News

    • [2024/09] 🚀 Nanoflow now supports Llama2 70B, Llama3 70B, Llama3.1 70B, Llama3 8B, Llama3.1 8B and Qwen2 72B models. We also released experiment scripts to reproduce the evaluation results.

    Introduction

    The key insight behinds NanoFlow is that traditional pipeline design of existing frameworks under-utilizes hardware resources due to the sequential execution of operations. Therefore, NanoFlow proposes intra-device parallelism (as shown in the following gif), which use nano-batches to schedule the compute-, memory-, network-bound operations for simultaneous execution. Such overlapping leaves compute-bound operations on the critical path and boost the resource utilization.

    With highly utilized GPU, the overhead of CPU, which consists of KV-cache management, batch formation, and retired requests selection, takes significant part ($>10$%) of inference time. Therefore, NanoFlow adopts an asyncronous control flow as shown in the following figure. At any iteration $i$, NanoFlow makes batching decisions and allocates the KV-cache entries for the next iteration before the end of the current iteration. NanoFlow directly launches iteration $i + 1$ without detecting the end-of-sequence (EOS) tokens generated in iteration $i$ and retires completed requests at iteration $i+2$.

    To avoid recomputation and reuse the KV-cache from multi-round conversations, NanoFlow eagerly offloads the KV-cache of finished requests to SSDs. In one iteration, NanoFlow selects the KV-cache of the retired requests and copies them to the host in parallel to the on-the-fly inference operations, via a layer-by-layer manner. Our calculation shows that only 5GB/s are needed for the offloading bandwidth of serving LLaMA2-70B, while a single SSD can reach 3GB/s.

    With all mentioned techniques implemented, we now open-source NanoFlow of a Cpp-based backend and a Python-based demo frontend in ~4K lines. NanoFlow integrates state-of-the-art kernel libraries including CUTLASS for GEMM, FlashInfer for Attention, and MSCCL++ for Network. This codebase also contains necessary scripts for environment setup and experiment reproduction.

    Benchmarks

    We list some of the primary benchmarks. Please check our paper for more details. We evaluate on A100 80GB SXM and choose vLLM v0.5.3, Deepspeed-FastGen v0.2.3, and TensorRT-LLM v0.8.0 as baselines. Note that all frameworks turn off specific optimizations like quantization, speculative decoding, prefix cache, etc..

    Offline throughput: Llama2-70B on 8xA100 (80GB)

    We conduct offline througput in two settings: practical workloads from collected traces (Splitwise, LMSYS-Chat-1M, ShareGPT), and constant input/output length. NanoFlow consistently surpasses all the baselines.

    Online latency: Llama2-70B on 8xA100 (80GB)

    We test the normalized latency (which is the end-to-end request latency divided by number of output tokens) with the three real-world traces and set different request rate (incoming requests per second). NanoFlow is able to sustain a higher request rate with low latency compared to baselines among all the datasets.

    Feasibility: offline throughput on different models

    We ported NanoFlow to 5 representative models to showcase its flexibility. We evaluate the offline throughput of NanoFlow (tokens per second per GPU) on these LLMs with constant length of input 1024 and output 512.

    Codebase

    Abstract

    The increasing usage of Large Language Models (LLMs) has resulted in a surging demand for planet-scale serving systems, where tens of thousands of GPUs continuously serve hundreds of millions of users. Consequently, throughput (under reasonable latency constraints) has emerged as a key metric that determines serving systems’ performance. To boost throughput, various methods of inter-device parallelism (e.g., data, tensor, pipeline) have been explored. However, existing methods do not consider overlapping the utilization of different resources within a single device, leading to underutilization and sub-optimal performance.

    We propose NanoFlow, a novel serving framework that exploits intra-device parallelism, which overlaps the usage of resources including compute, memory, and network within a single device through operation co-scheduling. To exploit intra-device parallelism, NanoFlow introduces two key innovations: First, NanoFlow proposes nano-batching to split requests at the granularity of operations, which breaks the dependency of sequential operations in LLM inference and enables overlapping them; then, to get benefit from overlapping, NanoFlow uses a device-level pipeline with execution unit scheduling, which partitions the device’s functional units and simultaneously executes different operations in each unit. NanoFlow automates the pipeline setup using a parameter search algorithm, which enables easily porting NanoFlow to work with different models. We implement NanoFlow on NVIDIA GPUs and evaluate end-to-end serving throughput on several popular models such as LLaMA-2-70B, Mixtral 8×7B, LLaMA-3-8B, etc. We show that NanoFlow achieves 68.5% of optimal throughput. With practical workloads, NanoFlow provides 1.91× throughput boost compared to state-of-the-art serving systems achieving 59% to 72% of optimal throughput across ported models.

    Installation

    Docker setup

    mkdir -p ~/framework-test
    docker run --gpus all --net=host --privileged -v /dev/shm:/dev/shm --name nanoflow -v ~/framework-test:/code -it nvcr.io/nvidia/cuda:12.8.1-cudnn-devel-ubuntu22.04
    
    apt update
    apt install pybind11-dev
    apt install liburing-dev
    apt install libopenmpi-dev
    sysctl -w kernel.io_uring_disabled=0
    sysctl -w vm.nr_hugepages=65536
    

    Gurobi License Setup (for Docker)

    Follow these steps to obtain a Gurobi license and configure it so your Docker container can use it.

    1. Request a Gurobi License
    1. Go to the Gurobi website and create an account (https://www.gurobi.com/).
    2. After logging in, navigate to My Gurobi → Get License.
    3. Choose the "WLS Academic" license type and fill out any required fields.
    4. Gurobi will email you a license file named gurobi.lic (or provide you with a license key string).
    2. Place the License on Your Host Machine
    mkdir -p ~/gurobi/license
    mv /path/to/downloaded/gurobi.lic ~/gurobi/license/
    ls ~/gurobi/license
    echo "export GRB_LICENSE_FILE=$(pwd)/gurobi.lic" >> ~/.bashrc
    

    Install Dependencies

    git clone [email protected]:efeslab/Nanoflow.git
    cd Nanoflow
    chmod +x ./installAnaconda.sh
    ./installAnaconda.sh
    # restart the terminal
    source ~/.bashrc
    
    # login to huggingface
    mkdir -p hf
    echo "export HF_HOME=$(pwd)/hf" >> ~/.bashrc
    source ~/.bashrc
    
    huggingface-cli login
    
    # set up the environment
    cd Nanoflow-python
    yes | bash setup.sh
    

    Build

    cd pybind
    mkdir -p build
    cmake ..
    make -j 256
    

    End-to-end Test

    cd entry
    python run_llama3.py -load_hf_weight=True
    

    Citation

    If you use NanoFlow for your research, please cite our paper:

    @misc{zhu2024nanoflowoptimallargelanguage,
          title={NanoFlow: Towards Optimal Large Language Model Serving Throughput}, 
          author={Kan Zhu and Yilong Zhao and Liangyu Zhao and Gefei Zuo and Yile Gu and Dedong Xie and Yufei Gao and Qinyu Xu and Tian Tang and Zihao Ye and Keisuke Kamahori and Chien-Yu Lin and Stephanie Wang and Arvind Krishnamurthy and Baris Kasikci},
          year={2024},
          eprint={2408.12757},
          archivePrefix={arXiv},
          primaryClass={cs.DC},
          url={https://arxiv.org/abs/2408.12757}, 
    }
    

    Acknowledgement

    NanoFlow is inspired by and reuses code from the following projects: CUTLASS, FlashInfer, MSCCL++, and Punica. Development of NanoFlow is made easier thanks to these tools: GoogleTest, NVBench, and spdlog. We thank Siqin Chen for her help in the design of NanoFlow logo.