-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathquiz.json
More file actions
78 lines (78 loc) · 3.63 KB
/
Copy pathquiz.json
File metadata and controls
78 lines (78 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
"lesson": "48-distributed-fsdp-ddp",
"title": "顶点课 48 —— 从零实现分布式数据并行与 FSDP",
"questions": [
{
"stage": "pre",
"question": "从零实现 DDP wrapper 的核心是哪两个 collective op?",
"options": [
"send 和 recv。",
"构造时 broadcast 让每个 rank 从相同参数起步,backward 后 all_reduce 让每个 rank 拿到平均梯度。",
"仅 reduce_scatter。",
"barrier 和 barrier。"
],
"correct": 1,
"explanation": "初始化时 broadcast 保证 step 0 各 rank 同步。之后每步 backward 后 all_reduce 保持同步。"
},
{
"stage": "pre",
"question": "为什么这节课不需要 CUDA 就能在 CPU 上跑?",
"options": [
"它只是个 stub。",
"torch.distributed 自带 gloo 后端,通过普通 socket 跑 collective,所以 CPU 上的 torch.multiprocessing worker 就能组成真正的 process group;在 GPU 机器上只需换设备标签。",
"它用的是模拟 tensor。",
"它根本没用 torch.distributed。"
],
"correct": 1,
"explanation": "Gloo 是 CPU collective 后端。同样的调用在 GPU 上用 nccl,API 表面完全一样。"
},
{
"stage": "check",
"question": "manual_all_reduce_matches_single_process 测试证明了什么?",
"options": [
"什么都没证明。",
"把各 rank 梯度求和再除以 world_size,能在浮点噪声内恢复出单进程在拼接输入上计算的梯度。",
"优化器收敛了。",
"CUDA 不是必需的。"
],
"correct": 1,
"explanation": "全 batch 上的 cross entropy mean reduction 等于各 rank mean 的平均。Sum-and-divide 是正确操作;这个测试把它可视化了。"
},
{
"stage": "check",
"question": "这节课的 FSDP 草案在每次前向传播时对每个参数做了什么?",
"options": [
"什么都没做。",
"把扁平参数 pad 到 world_size 的整数倍、切片、在每个 rank 上 all_gather 切片、去掉 pad、并验证重建结果与原始一致。",
"重新初始化参数。",
"计算哈希。"
],
"correct": 1,
"explanation": "每个 rank 持有每个参数的 1/world_size。Gather 重建完整 tensor 用于计算;生产级 FSDP 会把 gather 和前一层的计算做 overlap。"
},
{
"stage": "check",
"question": "为什么 gloo 的 all_gather 需要 world_size 个等大小的 shard,即使参数长度不能被 world_size 整除?",
"options": [
"Gloo 的 all_gather 要求每个 rank 的输出 tensor 大小相同,所以扁平参数会右 pad 到 world_size 的整数倍再切片,gather 后再裁掉 padding。",
"这是个 bug。",
"加快网络速度。",
"随意选择。"
],
"correct": 0,
"explanation": "Gloo(和 nccl)的 all_gather 要求等大小输出。Padding 是最低成本的修复;草案在 gather 后把结果裁回原始长度。"
},
{
"stage": "post",
"question": "看 demo 输出,各 rank 间 param_sum_spread 接近零说明了什么?",
"options": [
"Loss 很低。",
"每个 rank 在 run 结束时参数值相同,说明构造时的 broadcast 和每步 backward 后的 all-reduce 都正常工作了;如果任一环节出错,spread 会随步数增长。",
"网络很快。",
"没有意义。"
],
"correct": 1,
"explanation": "DDP 的不变量是各 rank 参数一致。Spread 就是审计指标;demo 断言它保持在 1e-3 以下。"
}
]
}