Generalized Tensor Parallelism(GTP)是什么?
它和 TP、ZeRO-3 差在哪,all-gather 怎么藏?

英文问法What is Generalized Tensor Parallelism in Megatron Core? · How does GTP_remat differ from TP, and from ZeRO-3 on the data-parallel axis? · How does GTP hide the weight all-gather behind compute, and what happens to the weight gradient?

考过推断,非面经。没有任何面经问过 GTP · 依据是团队自己的 GTP 文档(main 分支 2026-11 的版本,开头标着 experimental,要求 TransformerEngine ≥ 2.19)和 core 0.20.0 release notes · 下面的引文和限制都是这一版文档的说法

先弄清楚:每个概念是什么

GTP_remat
把 TP 切完的那片 weight 再切一次,每卡平时只存一小片。GEMM 之前用 all-gather 拼回完整的 TP slice,算完就释放。remat 来自 rematerialize。
Prefetch chain
weight 按 forward 的顺序连成一条链。算当前层时,提前把下一层的 all-gather 发出去。
Deferred finalize
weight gradient 的 reduce-scatter 的结果推迟一步才并进 main_grad。这里的一步是 backward 往前走一层,不是一个 training step。

看图:all-gather 和上一层的 GEMM 同时跑

forward:第 i 层的 all-gather 藏在第 i − 1 层的 GEMM 后面 计算 stream 通信 stream 等 GEMM 1 GEMM 2 GEMM 3 … AG(W1) AG(W2) AG(W3) AG(W4) → GEMM 1 → GEMM 2 → GEMM 3 → GEMM 4 链头,露在外面 其余 L − 1 次被上一层的 GEMM 盖住 时间
图 1:宽度是示意。AG(Wi) 是第 i 层 weight 的 all-gather,箭头后面是用它的 GEMM。3.1 节的说法是 communication 只在 "the very first layer of each direction (cold start)" 和几个强制串行点挡住计算。

30 秒回答

GTP equals TP times GTP_remat. TP keeps each weight split through the GEMM. GTP_remat splits the TP slice again: each rank keeps one shard, rebuilds the full slice with an async all-gather right before the GEMM, and frees it afterwards. The doc calls it an implementation of ZeRO-3 that shards along a model-parallel axis, not the data-parallel one, and materializes one weight at a time, not a bucket. Each layer's all-gather is prefetched during the previous layer's GEMM, so all but the first are hidden. Weight gradients return through an async reduce-scatter whose finalize is deferred one step. It's still experimental.

TP、GTP_remat、DP 轴上的 ZeRO-3 差在哪

TPGTP_rematDP 轴上的 ZeRO-3
沿哪个轴切model-parallelmodel-paralleldata-parallel
每卡平时存weight 的 1/TPTP slice 的 1/GTP_rematweight 的 1/N
GEMM 时"stays sharded through the GEMM"先 all-gather,"the GEMM sees the full TP slice",算完释放all-gather 出完整 weight,算完释放
通信传什么activation(见 TP communication)weight 的 all-gather;weight gradient 的 reduce-scatter同左
粒度不涉及一次一个 weight一个 bucket

文档说 "GTP_remat is an implementation of ZeRO-3"(ZeRO-3 见 DP、ZeRO、FSDP),区别是表里“沿哪个轴切”和“粒度”两行,所以每个 weight 可以单独 prefetch。“TP 切计算、传 activation,GTP_remat 只切存储、传 weight”是按这张表推断的。TP 本身怎么切见 TP Linear。

手算一遍。h = 8192 的方阵 weight 用 bf16 存是 128 MiB。TP = 4 后每卡 32 MiB。再开 GTP_remat = 8,每卡平时只存 4 MiB,GEMM 前 all-gather 回 32 MiB。合起来是 1/32,对应文档的 "32× weight-memory reduction"。同一句里的 "128× wire-bandwidth reduction" 文档没有给推导,面试里只引 32×。

all-gather 和 weight gradient 怎么藏在计算后面

  1. Forward:文档 1.1 节写 "Layer i's AG overlaps with layer i−1's GEMM.",3.1 节写成 \(\text{AG}(W_{i+1}) \parallel \text{GEMM}(W_i)\)。两处下标错开一位,说的是同一件事
  2. 链头:第一层前面没有 GEMM,所以 "For an L-layer model, L−1 all-gathers are fully hidden behind compute."
  3. Cold start:"every weight's very first AG is synchronous",prefetch chain 从第二次 forward 才开始
  4. Backward:反着走,第 i − 1 层的 all-gather 和第 i 层的 dgrad 重叠
  5. Weight gradient:reduce-scatter 异步发出,"Finalization is deferred one step",所以第 i 层的 reduce-scatter 能和第 i − 1 层的 backward GEMM 重叠。链头用同步的 reduce-scatter,"since nothing follows it"

Overlap 的一般做法和 exposed communication 怎么算见 overlap。

必答点

追问

GTP_remat 里的各个 rank 算的是同一份数据吗?

不是。文档写默认 "all GTP_remat ranks distribute independent samples",开了 sequence sharding 后各 rank 算同一个 microbatch 的不同 sequence 分段。

为什么不直接把 FSDP 的 bucket 缩到一个 weight?

文档的说法是 "FSDP's overlap is bucket-grained by design",bucket 是为了 "avoid paying NCCL launch latency on tiny params"。GTP_remat 不切小 tensor,文档写 LayerNorm、bias、MoE router 这些 "always stay full"。

all-gather 出了 NVLink domain 还藏得住吗?

文档写 "One GEMM of runway covers a gather that stays inside the NVLink domain, but not one that leaves it"。MoE 的 routed-expert weight 属于后一种,文档给它们单独的 one-block-ahead chain。

怎么打开,有什么限制,规模到多大?

--tensor-parallel-num-weight-shards 决定 GTP_remat 的大小,等于 1 时 GTP 不生效。文档写它 "composes orthogonally with TP / SP / EP / DDP / CUDA Graphs",目前要求 num_distributed_optimizer_instances == 1。文档的例子是约 280B 的 hybrid Mamba-MoE proxy 在 GB200 NVL72 上用 GTP64,到 3072 GPU 时 scaling efficiency 仍 "≥93 %"。

来源GTP 文档(开头的 overview 和对照表;1.1 节 prefetch chain、cold start、deferred RS finalize;1.3 节 low precision 的表;1.7 节 scaling;3.1 节 overlap design summary)· core 0.20.0 release notes(GTP 加了 "configurable batch/sequence partitioning, opt-in latent-projection sharding, and MTP support")· 题库条目在 ml-八股 06 的“零、团队最近在做什么”