Skip to content

Conversation

SigureMo
Copy link
Member

@SigureMo SigureMo commented Mar 21, 2025

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

确保在 PIR 下,使用 backend="CINN" 能与 FLAGS_use_cinn=1 FLAGS_prim_all=true FLAGS_prim_enable_dynamic=true 有相同的效果

新增 ENABLE_CINN_IN_DY2ST 用于控制是否开启编译器,ENABLE_CINN_IN_DY2ST=0 的话即便设置 backend="CINN" 也不会生效

数据的一致性很重要,如 #71817 所述,能用 C++ flag 获取值的统一用 C++ flag 了(FLAGS_prim_enable_dynamicFLAGS_prim_skip_dynamicFLAGS_use_cinn),用个 flag_guard 就能确保内部能感知了,维护起来非常方便

分阶段暴露问题,本 PR 修复 bug,完善机制,下个 PR 只修改默认值,暴露切默认所带来的问题

Related links

CINN 切默认系列 PR

Copy link

paddle-bot bot commented Mar 21, 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 zrr1999 and gouzil as code owners March 21, 2025 19:33
@SigureMo SigureMo requested review from Copilot and removed request for zrr1999 and gouzil March 21, 2025 19:33
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 fixes a bug in the Execute Infrastructure by auto-enabling prim, CINN flags, and recompute logic when the backend is CINN. Key changes include replacing string backend comparisons with a new Backend enum, refactoring guard context managers and related functions, and updating tests to align with the new backend API.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/paddle/jit/dy2static/utils.py Introduces environment variables and a new Backend enum with helper methods to differentiate CINN and PHI backends
test/deprecated/prim/prim/flags/test_prim_flags_case_deprecated.py Removes the redundant use_cinn flag in tests and simplifies to use backend=None
python/paddle/jit/api.py Updates to use the new Backend API and removes deprecated backend checks
python/paddle/jit/dy2static/program_translator.py Refactors CINN enabling logic to use Backend.is_cinn() and updates backend_guard usage; removes deprecated string-based checks
python/paddle/jit/dy2static/pir_partial_program.py Updates imports and usage to leverage the new Backend enum
test/dygraph_to_static/test_partial_program_hook.py Passes an explicit Backend value to PirPrimHooker and removes use_cinn flags from test calls
python/paddle/jit/dy2static/partial_program.py Replaces backend string comparisons with Backend.is_cinn() for improved correctness

Comment on lines 1519 to 1521
print(core._is_fwd_prim_enabled())
with backend_guard(self.backend):
print(core._is_fwd_prim_enabled())
Copy link
Preview

Copilot AI Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements appear to be left in production code; please remove or replace them with proper logging.

Suggested change
print(core._is_fwd_prim_enabled())
with backend_guard(self.backend):
print(core._is_fwd_prim_enabled())
logging_utils.info(core._is_fwd_prim_enabled())
with backend_guard(self.backend):
logging_utils.info(core._is_fwd_prim_enabled())

Copilot uses AI. Check for mistakes.

@SigureMo SigureMo requested a review from Copilot March 21, 2025 19:43
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 fixes a bug in the CINN backend integration for dynamic-to-static conversion by auto-enabling prim/CINN flags, refactoring backend handling, and updating related tests.

  • Introduces a Backend Enum with helper methods and updated guard context managers.
  • Refactors CINN flag checking and deprecates legacy build_strategy flags in favor of the new backend parameter.
  • Updates test cases and related utility functions to remove the old use_cinn parameter.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
python/paddle/jit/dy2static/utils.py Adds Backend enum; refactors CINN flag logic and updates warning messages.
test/deprecated/prim/prim/flags/test_prim_flags_case_deprecated.py Removes legacy use_cinn argument in test cases.
python/paddle/base/core.py Updates flag enabling functions using get_flags.
python/paddle/jit/api.py Removes deprecated backend checking and converts backend parameter using Backend enum.
python/paddle/jit/dy2static/pir_partial_program.py Updates backend handling and guard context usage; refactors variable naming for full-graph passes.
python/paddle/jit/dy2static/partial_program.py Updates backend comparison to use Backend enum.
test/dygraph_to_static/test_partial_program_hook.py Revises hook instantiation with a defined Backend instead of None.
Comments suppressed due to low confidence (1)

python/paddle/jit/dy2static/pir_partial_program.py:1084

  • The variable name 'fused_bn_add_act_pass' was changed to 'full_graph_pre_process_pass' later in the diff; please update the comment or the naming in this context for consistency.
fused_bn_add_act_pass = FullGraphPreProcessPass(

if build_strategy is not None and build_strategy.build_cinn_pass:
if build_strategy.build_cinn_pass:
warnings.warn(
"Use `build_strategy.build_cinn_pass = True` to enable CINN is deprecated, please use `backend = 'CINN'` instead."
Copy link
Preview

Copilot AI Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the deprecation warning message to reflect that the backend parameter now uses a Backend enum, for example: "please use backend = Backend.CINN instead."

Suggested change
"Use `build_strategy.build_cinn_pass = True` to enable CINN is deprecated, please use `backend = 'CINN'` instead."
"Use `build_strategy.build_cinn_pass = True` to enable CINN is deprecated, please use `backend = Backend.CINN` instead."

Copilot uses AI. Check for mistakes.

Copy link
Member Author

@SigureMo SigureMo Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backend.CINN 不暴露给用户,用户仍然用 "CINN"NoneBackend.CINNBackend.PHI 是内部类型安全的数据封装

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

老 IR 单测,上次挂了这次又挂了,这里我觉得没必要测 CINN + 老 IR 的 prim 开启状态了,本来 build_strategy 这种设置方式也弃用了,这部分删掉,backend 测试相关逻辑会由 test_jit_backend 单测来承担

@SigureMo SigureMo merged commit b061908 into PaddlePaddle:develop Mar 25, 2025
30 checks passed
@SigureMo SigureMo deleted the dy2st/auto-enable-prim-cinn-recompute-when-backend-is-cinn branch March 25, 2025 02:36
YqGe585 pushed a commit to YqGe585/Paddle that referenced this pull request May 7, 2025
…s CINN (PaddlePaddle#71834)

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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