Skip to content

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Mar 20, 2025

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
  • guard 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
  • guard python/paddle/utils/environments.py::EnvironmentVariableGuard

Copy link

paddle-bot bot commented Mar 20, 2025

你的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.

@SigureMo SigureMo requested review from Copilot and removed request for zhiqiu, Xreki, qili93 and XiaoguangHu01 March 20, 2025 16:53
Copy link
Contributor

@Copilot Copilot AI left a 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.

@SigureMo 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.getenv Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants