测试基建:⚡ 优化 GPU Mode 显存治理#684
Open
cangtianhuang wants to merge 6 commits into
Open
Conversation
|
Thanks for your contribution! |
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.
🧭 背景
PaddleAPITest 的
gpu_mode通过 GPU 上的 tensor 生成、比较和缓存复用提升 accuracy 测试效率,但在长时间运行、单卡多 worker 以及大 shape case 场景下,旧实现容易把临时 tensor、allocator cache 和调度压力叠加到同一张卡上,最终放大 OOM 风险。🔎 问题定位
旧逻辑里,gpu mode 仍沿用固定的
required_memory思路,默认预算过小,且与真实 GPU 总显存、worker 数和 case 规模脱节。对 B 卡 268G 这类场景来说,单卡单进程的可用预算应接近整卡安全比例,而不是被旧模型压成 10GB 级别。与此同时,gpu mode 在 torch 阶段保留了较多 live tensor 和 allocator cache,Paddle 阶段又需要继续申请显存,导致单 case 在输入生成、输出保留和 cache 积压的叠加下更容易触顶。fp8/fp16/bf16 的大 tensor 生成还会先制造更大的临时峰值,进一步放大风险。
🔧 主要变更
1. gpu mode 显存预算改为按卡容量和 worker 数计算
GpuModeConfig改为显式携带 GPU 总显存、worker 数、预算和 cleanup 阈值,engine 在启动 case 时注入当前 GPU 的总显存和 worker 数,再由 runtime config 计算当前 worker 的memory_budget。--num_workers_per_gpu=-1时默认按每卡 1 worker 处理,更符合大 case 的保守默认。2. 统一 torch cache 清理和 outputs/grads spill 决策
tester/base.py将 gpu mode 的显存策略收敛到一个入口里:普通阶段根据 budget、reserved、allocated 和 idle reserved 判断是否empty_cache(),accuracy 阶段则复用同一逻辑决定 torch outputs/grads 是否需要迁 CPU,并在必要时同步清理 cache 给 Paddle 让位。3. 降低 fp8 / bf16 / fp16 大 tensor 生成峰值
tester/api_config/config_analyzer.py改成先分配目标 tensor,再用小 pattern 分块填充,保留 torch/Paddle 共同源输入语义的同时,避免大 shape 先生成整块随机临时 tensor。fp8 路径仍通过支持的中间 dtype 生成有限值后再 cast,因为当前 torch 不能直接随机生成 fp8 tensor。4. 删除旧参数和脚本入口
required_memory从run.py、engine 参数流、schema、示例脚本和 V2/V4/CINN 文档中全部移除,旧固定预算模型不再保留兼容入口。这样可以避免调用链继续依赖已失效的 10GB 配置。📁 改动文件
engineV2.py、engineV4.pyrequired_memory逻辑tester/runtime_config.py、tester/base.py、tester/accuracy.py、tester/api_config/config_analyzer.pyrun.pyrequired_memoryCLI 和 engine overridetest_pipeline/run_config.schema.json、run-example.sh、run-v4.sh、test_pipeline/V2/*、test_pipeline/V4/*、test_pipeline/CINN/*engineV2-README.md