[Dy2St][CINN] Dont access cpp flag FLAGS_use_cinn
via os.getenv
#71817
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