开启 FLAGS_cudnn_deterministic 时同步启用 Torch 确定算法 - #724
Merged
Merged
Conversation
accuracy_compatible 流水线增加 FLAGS_cudnn_deterministic; paddle_to_torch 在该 flag 打开时调用 torch.use_deterministic_algorithms(True)。
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.
背景
accuracy_compatible流水线需要在 Paddle 开启FLAGS_cudnn_deterministic时,与 Torch 对照侧同步走确定算法。原先 YAML 只打开了FLAGS_use_accuracy_compatible_kernel,Torch 对照仍使用默认非确定实现,index_select等存在重复 index 的反向 scatter-add 在 atol/rtol=0 下无法对齐。修改内容
test_pipeline/generic_configs/run_accuracy_compatible.yaml:增加FLAGS_cudnn_deterministic: "1"。tester/paddle_to_torch/rules.py:BaseRule.build_result()的 preprocess 在该 flag 为真时调用torch.use_deterministic_algorithms(True)。flag 关闭时不改变 Torch 行为。验证
python -m py_compile tester/paddle_to_torch/rules.pyruff check tester/paddle_to_torch/rules.py与ruff format --check tester/paddle_to_torch/rules.pypython tools/check_comment_ratio.py(staged diff 评论比例 20%)git diff --checkpaddle.index_select、atol=0、rtol=0、FLAGS_use_accuracy_compatible_kernel=1实测:FLAGS_cudnn_deterministic=1:4/4 passpaddle_accuracy(反向约 35% 元素差 1 ulp)未执行:仓库
pre-commit run --files ...因首次拉取 hook 环境超时未跑完;等价的 yaml 解析、ruff、py_compile、comment-ratio 检查已通过。