大模型推理引擎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 小时前
【CS336】lecture7 多卡|通信架构|集合通信|NCCL|通信原语|torch.distributed
分布式·架构·nccl·多机多卡·集合通信
智码看视界10 小时前
开源大模型追踪:Qwen3-VL-30B-A3B :30B 总参单卡到底能不能跑?
多模态·视觉语言模型·本地部署·vllm·moe·开源大模型·qwen3-vl
小易老师AI实战11 小时前
多模型融合实战:大模型+轻量小模型混合部署
vllm·大模型部署·模型路由·多模型融合·llm工程化·ai降本增效
程序员梅雨12 小时前
ZooKeeper面经总结
java·大数据·linux·分布式·后端·zookeeper·中间件
我是人✓12 小时前
Git入门:从零开始掌握分布式版本控制
分布式·git
chenxy0213 小时前
提高大模型推理性能的思路
vllm
guo_wen_qiang16 小时前
redis持久化
数据库·redis·分布式
buligbulig16 小时前
Hadoop正在失败?不,它正在壮大
大数据·hadoop·分布式
十年Java程序媛16 小时前
Redis 分布式锁 + GZIP 压缩缓存踩坑|高并发缓存真实线上复盘
java·开发语言·spring boot·redis·分布式·缓存·面试
啦啦啦啦啦zzzz17 小时前
分布式存储----缓存组
linux·服务器·c++·分布式·缓存