You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.
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.
SigureMo
changed the title
[Dy2St][CINN] Dont get cpp flag FLAGS_use_cinn by os.getenv
[Dy2St][CINN] Dont access cpp flag FLAGS_use_cinn by os.getenvMar 20, 2025
SigureMo
changed the title
[Dy2St][CINN] Dont access cpp flag FLAGS_use_cinn by os.getenv
[Dy2St][CINN] Dont access cpp flag FLAGS_use_cinn via os.getenvMar 21, 2025
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.cc
paddle.set_flags
paddle.get_flags
paddle.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.set
ENV_xxx.get
python/paddle/utils/environments.py::EnvironmentVariableGuard