Conversation
- add a shared PipelineLayout model for uniform partitions, uneven layer partitions, and explicit chunk-to-stage ownership - construct GPT-2 and LLaMA models, checkpoint loaders, and pipeline schedules from the resolved layout while preserving default behavior and legacy API compatibility - handle logical input/output stages, local chunk chains, and cyclic owner mappings without changing legacy schedule ordering - add parser, layout, loader, wrapper, and scheduler regression tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
总结
本 PR 为 Pipeline Parallel(流水线并行)增加统一的布局描述与解析能力,使 GPT-2 和 LLaMA 3 可以在同一套模型构建、权重加载和调度流程中使用以下三种布局:
未设置新参数时,程序继续使用原有的均匀分层与交错分配规则,默认行为保持不变。
设计方案
1. 统一布局总结
LayerRange[begin, end)PipelineChunkSpecstage_id和层数PipelineChunkLayoutPipelineStageLayoutPipelineLayoutPipelineLayout提供三种构建接口:BuildUniformLayout()BuildCustomLayout()BuildChunkLayout()主要查询接口包括
GetStage()、GetChunk()、GetStageForLayer()、GetLocalLayerIndex()、GetInputStage()、GetOutputStage()和GetMaxLocalChunks()。2. 参数解析与布局创建
新增两个互斥参数:
--pipeline_layer_partition--pipeline_chunk_layoutstage_id:layer_countParsePipelineLayoutRequest()负责格式与维度检查;取得真实模型层数后,ResolvePipelineLayout()调用对应布局工厂。随机初始化和 checkpoint 加载两条入口最终都向模型、Loader、Pipeline 包装器和调度器传递同一个布局对象。3. 模型构建与权重加载
TransformerModel通过ConvertLayoutToStageInfo()复用现有模型构建逻辑,不维护第二套 Transformer 实现;4. Pipeline 包装、调度与通信
5. 兼容性设计
GetStageInfo()和旧构造函数作为兼容入口;使用示例
PP=2、每个 Stage 一个 Chunk,按
7,5自定义分层:PP=2、最大每个 Stage 两个 Chunk,同时自定义分层与归属:
第二个示例生成四个逻辑 Chunk,层数为
4,3,3,2,owner 为0,0,1,1。Embedding 位于 Stage 0,Final Norm 和 LM Head 位于 Stage 1。测试结果
1. 构建与单元测试
单元测试覆盖布局构建与非法输入、参数解析、特殊模块归属、GPT-2/LLaMA Loader、默认调度兼容、任意 owner、本地 Chunk 链、循环通信推进和输入维度检查。
2. 双卡端到端正确性
1e-6严格 FP32 比较使用
atol=1e-5, rtol=0。候选 D(4,3,3,2 / 0011)还与默认 vPP 布局进行了单独复核:两次训练最终 loss 均为5.356190,254/254 个模块输出与输出梯度全部通过。3. 性能与 Pipeline 负载
测试固定 GPT-2 124M、FP32、PP=2、vPP=2、训练批次大小 4、序列长度 128、4 个 microbatch 和每步 2048 个 token。每组独立运行 4 次、每次 100 步,丢弃前 20 步预热数据,全部样本均保留。
3,3,3,3 / 01013,3,3,3 / 00114,3,3,2 / 01014,3,3,2 / 0011流水线空泡表示 Stage 没有执行非 NCCL 模型计算的时间比例,不等同于 GPU 完全空闲。接收等待归因是根据任务语义和 NCCL 调用顺序得到的保守下界。性能结果仅适用于当前机器、模型、参数和四个候选,不表示全局最优。