-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Dy2St][CINN] Dont access cpp flag FLAGS_use_cinn via os.getenv
#71817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Dy2St][CINN] Dont access cpp flag FLAGS_use_cinn via os.getenv
#71817
Conversation
|
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
FLAGS_use_cinn by os.getenvFLAGS_use_cinn via os.getenv
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