[Dy2St][CINN] Dont access cpp flag FLAGS_use_cinn via os.getenv#71817
Merged
SigureMo merged 4 commits intoMar 21, 2025
Merged
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that all accesses to the FLAGS_use_cinn flag use a unified C++ flag interface rather than relying on environment variables. Key changes include:
- Adding a flag_guard context manager in framework.py for temporary flag setting.
- Updating in_cinn_mode and related API calls to use paddle.get_flags instead of os.getenv.
- Removing a redundant flag_guard from the tests and standardizing flag naming in test files.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/paddle/base/framework.py | Added flag_guard context manager and updated in_cinn_mode to use paddle.get_flags. |
| python/paddle/jit/dy2static/utils.py | Replaced os.getenv check with a call to in_cinn_mode. |
| test/ir/pir/test_cse_pass.py | Removed duplicate flag_guard implementation and updated flag naming to CINN_FLAG_NAME. |
FLAGS_use_cinn by os.getenvFLAGS_use_cinn by os.getenv
zyfncg
approved these changes
Mar 21, 2025
FLAGS_use_cinn by os.getenvFLAGS_use_cinn via os.getenv
This was referenced Mar 21, 2025
YqGe585
pushed a commit
to YqGe585/Paddle
that referenced
this pull request
May 7, 2025
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.
PR Category
Execute Infrastructure
PR Types
Devs
Description
确保所有
FLAGS_use_cinn的设置与获取都使用单一数据来源,即 C++ 的 flag 状态,这个状态是 Python/C++ 统一的,不应该在import paddle之后设置和访问对应的环境变量,这往往会导致数据不同步,难以维护,局部修改注意使用 guard 避免 side effect 意外扩散到后续操作C++ flag(即在
flags.cc声明的,FLAGS_开头的大多数是),此类主要用于需要 C++ 代码直接感知,应该统一使用以下 API(数据会存在 C++ 侧,不应该存在其他地方)flags.ccpaddle.set_flagspaddle.get_flagspaddle.base.framework.flag_guard而非 C++ flag,此类主要用于纯 Python 代码感知,应该使用以下 API(数据会存在环境变量中,不应该存在其他地方)
python/paddle/utils/environments.py::EnvironmentVariable实例ENV_xxx(如环境变量AAA_BBB_CCC应该对应ENV_AAA_BBB_CCC实例)ENV_xxx.setENV_xxx.getpython/paddle/utils/environments.py::EnvironmentVariableGuard