memory(GiB) 在 Ascend 多卡/模型并行场景统计为多卡累计值,是否应明确口径或改为逐卡展示?
Checklist / 检查清单
- [x] I have searched existing issues, and this is a new question or discussion topic. / 我已经搜索过现有的 issues,确认这是一个新的问题与讨论。
Question Description / 问题描述
问题描述
在 Ascend NPU 上进行多卡训练时,训练日志中的 memory(GiB) 会显示超过单张卡物理显存容量的数值。例如,单卡显存为 64 GiB,但日志中显示:'memory(GiB)': 91.97
训练过程正常完成,未发生 OOM。 这容易让用户误以为单张 NPU 的显存使用超过了硬件容量,进而怀疑显存统计或运行状态异常。
使用的是 megatron 分支还是 transformers 分支
hello hello !!俺最近在读源码学习分布式训练,关注到了这个 issue。我看了一下当前实现的逻辑:get_max_reserved_memory() 在 is_mp() 为真时会遍历可见设备,分别读取每张卡的 max_memory_reserved() 并求和,随后 add_train_message() 仍将结果记录为 memory(GiB)。所以该值实际表示多设备历史峰值的累计值,字段名却容易被理解为单卡显存峰值;另外,各设备峰值不一定发生在同一时刻。
我有一个初步的想法,如果可以的话我愿意接手处理这个 Issue:
- 先确认 Transformers 和 Megatron 两条训练路径是否都使用这套统计逻辑;
- 在不影响训练行为的前提下明确指标口径,兼容现有日志字段,并补充类似
memory_total(GiB)和memory_max_per_device(GiB)的明确统计; - 增加单卡和多卡场景的 CPU mock 单元测试,验证聚合结果及日志字段。
为避免影响现有日志解析,想先确认一下维护者更倾向于保留现有 memory(GiB) 并新增明确字段,还是直接调整现有字段名称。如果方向没有问题,我可以继续实现并提交 PR。
I agree this metric can be confusing. Perhaps we could change it to report the per-device maximum instead
https://github.com/modelscope/ms-swift/blob/main/swift/utils/torch_utils.py#L413-L419
def get_max_reserved_memory() -> float:
devices = list(range(get_device_count())) if is_mp() else [None]
try:
mems = [get_torch_device().max_memory_reserved(device=device) for device in devices]
except AttributeError:
return 0 # fix mps
- return sum(mems) / 1024**3
+ return max(mems) / 1024**3
@tastelikefeet issue 对应的应该是 Transformers 的 MP/device-map 路径,get_max_reserved_memory() 会对可见设备的峰值显存求和。Megatron 路径使用 MAX all-reduce,不会进行多卡累加。
@hjh0119 Thanks, this makes sense. Reporting the per-device maximum also aligns get_max_reserved_memory() with its name and with the Megatron logging semantics. I’ll implement this change and add CPU mock tests covering the single-device and MP multi-device cases, then submit a PR.
使用的是 megatron 分支还是 transformers 分支
Transformers,我们跑的是deepspeed
@hjh0119 Implemented the agreed per-device maximum change with CPU mock coverage in #9825.