【训练营】小模型训练支持 - #228
Open
linglingsansan0907 wants to merge 5 commits into
Open
【训练营】小模型训练支持#228linglingsansan0907 wants to merge 5 commits into
linglingsansan0907 wants to merge 5 commits into
Conversation
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.
概述
为 InfiniTrain 补齐小模型(CNN)训练能力:新增 Conv2d / ReLU 算子(CPU + CUDA 前向与反向),基于 MNIST 完成端到端 CNN 手写数字识别 Demo,与 PyTorch 参考实现完成数值对齐,并进一步支持 DDP 多卡分布式训练(单进程多线程 + NCCL AllReduce)。
功能清单
autograd::Conv2d节点:前向 + input / weight / bias 三路反向nn::Conv2d模块:KaimingUniform(a=√5) 初始化,与 PyTorch 对齐example/mnist:MNISTCNN(Conv2d(1,16,3)→ReLU→Conv2d(16,32,3)→ReLU→Flatten→Linear),支持单卡与 DDP 多卡训练example/mnist既有问题修复:模块 shared_ptr 管理(bad_weak_ptr)、Dataset operator[] 的 float32 字节数test_autograd_conv2d.cc、test_autograd_relu.cc,共 14 个测试全部通过数值对齐(PyTorch)
固定初始权重与输入,与 PyTorch 参考实现逐张量比对(22 个张量,含 forward logits、loss、参数梯度、单步 optimizer 更新):
端到端训练结果(MNIST,3 epochs)
说明:DDP 实现为单进程多线程(gpt2 示例风格),梯度经 NCCL AllReduce(kAvg)聚合。训练批数需能被卡数整除,故 4 卡使用 bs=60(1000 % 4 = 0)。DDP2/4 与单卡曲线不逐位一致,原因是全局等效 batch 变大且各 rank 数据分片不同,数值正确性由 DDP1 与单卡逐位一致证明。
框架级问题说明
构建说明
DDP 需要 NCCL。根
CMakeLists.txt修复了 NCCL include/link 传播问题(原逻辑 find 到 NCCL 但未向 CUDA kernels 与主框架目标传递 include 路径与库)。无 sudo 环境下可用pip install nvidia-nccl-cu12抽取到本地前缀后通过NCCL_ROOT指定,详见示例文档。