<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    
    <title>王帅俭的博客</title>
    
    
    <description>This website is a virtual proof that I&apos;m awesome</description>
    
    <link>https://jianzi123.github.io/</link>
    <atom:link href="https://jianzi123.github.io/feed.xml" rel="self" type="application/rss+xml" />
    
    
      <item>
        <title>NCCL代码分析</title>
        
        <dc:creator><![CDATA[ 王帅俭 ]]></dc:creator>
        
        <description>
          深入理解NCCL的底层实现与架构 - 
          NCCL背景 PS-Worker/AllReduce变化 pserver模式下，每个worker将数据发送到param-server算平均梯度并同步，因此param-server通讯量是3w，随着训练规模的扩大，param-server会成为瓶颈。 通过allreduce这种形式，每个节点只需向其他节点发送(n-1)次数据，每次发送w/n数据，重要的是每个节点发送的数据量相同。有了pserver到ring的allreduce，可以看到的变化是，从所有节点都向一个节点通讯，变成所有节点向其他节点发送等量的数据，结束了性能瓶颈。但是随着GPU数量的增多，环会变得很长，延迟会变高，从而影响带宽，然后有人提出了double-tree，从数据结构上来说是把list变成tree，将延迟从N变成lgN，将影响延迟的因素从环的长度变成树的高度。 训练切分方式 一切为了加速训练 batch size大小会影响模型最终的准确性和训练过程的性能，而数据的batch size大小受到GPU内存限制，于是有人提出梯度累计，就是一次没法训练太多的数据，将多步的训练结果合成一步。然后后来随着模型的增大，GA也解决不了，出现了将完整的模型放到不同的GPU上，每个GPU训练的数据不同，这个就是数据并行；后来模型结构越来越大，导致一个GPU放不下完整的模型，就出现了TP/PP，一个是切分tensor，一个是切分layer。这里就出现了另外的问题，将tensor和layer切分之后，很多操作需要完整的模型，所以这里涉及到了通讯问题。具体怎么处理，torch的处理方式是给每个切分方式设置一个process-group，nccl的处理方式是将不同的切分方式单独做成一个communicator，在这个comm中该种切分方式不同rank之间通讯。 PP切分方式 megatron/pytorch/nccl相关对象整体对应关系 Rank概念以及rank如何确定 Rank的定义 rank一开始是在MPI中引入的，表示的是一个进程，这里表示给一组进程中的每个进程编号，现在的训练中由于一个训练进程运行在一张GPU上，所以一个rank也代表着一张GPU卡。 Rank如何确定 详细信息可以参考 nccl_rank选择。 切分以及rank分组例子 其中分到一组的rank会进行通讯，真实通讯的时候是按照rank编号来的，跟GPU号等其他的不直接相关。 拿TP来说，TP2表示将tensor分成两份，也就是说每两个GPU可以组成完整的tensor，对应8个rank的具体分组上，[0,1], [2,3], [4,5], [6,7] 四组。 NCCL目标 NCCL的是nvidia collective communications Library的缩写，是一个通讯库，目标是能完全利用设备带宽，提高设备之间的吞吐。 如下图所示，两个节点Node0/Node1，每个节点四张GPU两张网卡，当从Node0和Node1进行通讯的时候，如果把两张网卡都用起来并发发送数据那么目标就达到了，为了做到这一点，nccl将完全独立的物理设备建立数据通讯链路，具体做法是在通讯之前会先把数据发送的通道找出来，然后建立通讯，当进行数据通讯的时候，通过这些链路收发数据。 NCCL解析 Bootstrap组网信息构建 这个是类似于服务注册发现的过程。 其中这里的uniQueId其实就是master的连接地址。 topo构建和grap搜索 获取Topo 获取xml 这一步是将物理拓扑转换成一个树状结构。 左边的是物理结构，右边是将物理结构转换成树状结构，一个node下面有subs变量表示子节点，parent表示父节点，由此串联成树状结构。 struct ncclXmlNode { char name[MAX_STR_LEN+1]; struct { char key[MAX_STR_LEN+1]; char value[MAX_STR_LEN+1];...
        </description>
        <pubDate>Fri, 24 Apr 2026 06:00:00 -0400</pubDate>
        <link>https://jianzi123.github.io/2026-04-24-nccl-code-analysis/</link>
        <guid isPermaLink="true">https://jianzi123.github.io/2026-04-24-nccl-code-analysis/</guid>
      </item>
    
      <item>
        <title>Sample blog post to learn markdown tips</title>
        
        <dc:creator><![CDATA[ Bill Smith ]]></dc:creator>
        
        <description>
          There&apos;s lots to learn! - 
          This is a demo post to show you how to write blog posts with markdown. I strongly encourage you to take 5 minutes to learn how to write in markdown - it’ll teach you how to transform regular text into bold/italics/tables/etc.I also encourage you to look at the code that...
        </description>
        <pubDate>Fri, 28 Feb 2020 00:00:00 -0500</pubDate>
        <link>https://jianzi123.github.io/2020-02-28-sample-markdown/</link>
        <guid isPermaLink="true">https://jianzi123.github.io/2020-02-28-sample-markdown/</guid>
      </item>
    
      <item>
        <title>Flake it till you make it</title>
        
        <dc:creator><![CDATA[ Sharon Smith and Barry Simpson ]]></dc:creator>
        
        <description>
          Excerpt from Soulshaping by Jeff Brown - 
          Under what circumstances should we step off a path? When is it essential that we finish what we start? If I bought a bag of peanuts and had an allergic reaction, no one would fault me if I threw it out. If I ended a relationship with a woman who...
        </description>
        <pubDate>Wed, 26 Feb 2020 00:00:00 -0500</pubDate>
        <link>https://jianzi123.github.io/2020-02-26-flake-it-till-you-make-it/</link>
        <guid isPermaLink="true">https://jianzi123.github.io/2020-02-26-flake-it-till-you-make-it/</guid>
      </item>
    
  </channel>
</rss>
