大模型推理引擎vLLM(10): vLLM 分布式推理源码结构解析

文章目录

  • [1 why distributed inference](#1 why distributed inference)
  • [2 DP EP PP TP](#2 DP EP PP TP)
    • [2.1 TP](#2.1 TP)
      • [2.1.1 工程层面怎么通信](#2.1.1 工程层面怎么通信)
      • [2.1.2 算法层面](#2.1.2 算法层面)
    • [2.2 PP](#2.2 PP)
    • [2.3 EP](#2.3 EP)
    • [2.4 DP](#2.4 DP)
  • 参考文献

这篇博客是在看[EP02][精剪版]分布式推理优化,vllm源码解读这个学习视频时做的简单笔记,感兴趣的可以直接去看原视频。

1 why distributed inference

其实就是因为一张卡跑大模型跑不开了,还有其他原因就是分布式推理能够加快模型的推理优化。

2 DP EP PP TP

2.1 TP

vllm/vllm/distributed/parallel_state.py这个文件里面有为传统的parallel提供的一系列接口,

下面的这个数据结构就是用来分布式通信的

python 复制代码
    # message queue broadcaster is only used in tensor model parallel group
    _TP = init_model_parallel_group(group_ranks,
                                    get_world_group().local_rank,
                                    backend,
                                    use_message_queue_broadcaster=True,
                                    group_name="tp")

然后实际上用的是这个类class GroupCoordinator:

下面的参数是他的属性

python 复制代码
# available attributes:
    rank: int  # global rank
    ranks: list[int]  # global ranks in the group
    world_size: int  # size of the group
    # difference between `local_rank` and `rank_in_group`:
    # if we have a group of size 4 across two nodes:
    # Process | Node | Rank | Local Rank | Rank in Group
    #   0     |   0  |  0   |     0      |       0
    #   1     |   0  |  1   |     1      |       1
    #   2     |   1  |  2   |     0      |       2
    #   3     |   1  |  3   |     1      |       3
    local_rank: int  # local rank used to assign devices
    rank_in_group: int  # rank inside the group
    cpu_group: ProcessGroup  # group for CPU communication
    device_group: ProcessGroup  # group for device communication
    use_device_communicator: bool  # whether to use device communicator
    device_communicator: DeviceCommunicatorBase  # device communicator
    mq_broadcaster: Optional[Any]  # shared memory broadcaster

2.1.1 工程层面怎么通信

2.1.2 算法层面

vllm/vllm/distributed/device_communicators这个目录里面是通信相关的代码,
还可以看一下vllm/vllm/model_executor/models/llama.py这里面的管宇TP PP的代码,初学者学代码先用llama要比用deepseek更好,
deepseek模型结构更复杂

2.2 PP

2.3 EP

2.4 DP

参考文献

[EP02][精剪版]分布式推理优化,vllm源码解读

相关推荐
问道飞鱼10 小时前
【分布式技术】RustFS 非 Docker 部署完整指南:从单机到生产集群
分布式·docker·容器·rustfs
DJ斯特拉10 小时前
Redisson分布式锁
分布式
deephub13 小时前
从零构建 Mini-vLLM:KV-Cache、动态批处理与分布式推理全流程
人工智能·python·深度学习·大语言模型·vllm
heimeiyingwang13 小时前
【架构实战】分布式ID生成方案(雪花/Leaf/美团)
分布式·架构
yxy___21 小时前
达梦分布式集群DPC_重做副本-操作指南(DEM)_yxy
运维·分布式
里欧跑得慢1 天前
Flutter 三方库 ethereum 鸿蒙分布式区块链数字资产上链钱包适配突破:接通 JSON-RPC 加密管线深入打通智能合约闭环实现高价值数字加密交互-适配鸿蒙 HarmonyOS ohos
分布式·flutter·harmonyos
2501_933329551 天前
技术深度拆解:Infoseek舆情系统的全链路架构与核心实现
开发语言·人工智能·分布式·架构
西西弗Sisyphus1 天前
大模型运行的 enforce_eager 参数
langchain·prompt·transformer·vllm·enforce_eager
辣机小司1 天前
【生产级 Kafka (KRaft) 双中心容灾演练:MirrorMaker 2.0 (MM2) 核心参数配置与回切踩坑指南】
分布式·kafka·集群同步·kafka双集群
softshow10261 天前
SpringCloud Redis与分布式
redis·分布式·spring cloud