CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Dy2St][CINN] Auto enable prim / cinn flag / recompute when backend is CINN #71834
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] Auto enable prim / cinn flag / recompute when backend is CINN #71834
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 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 |
print(core._is_fwd_prim_enabled()) | ||
with backend_guard(self.backend): | ||
print(core._is_fwd_prim_enabled()) |
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.
Debug print statements appear to be left in production code; please remove or replace them with proper logging.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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 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." |
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.
Update the deprecation warning message to reflect that the backend parameter now uses a Backend enum, for example: "please use backend = Backend.CINN instead."
"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.
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.
Backend.CINN
不暴露给用户,用户仍然用 "CINN"
和 None
,Backend.CINN
和 Backend.PHI
是内部类型安全的数据封装
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.
老 IR 单测,上次挂了这次又挂了,这里我觉得没必要测 CINN + 老 IR 的 prim 开启状态了,本来 build_strategy
这种设置方式也弃用了,这部分删掉,backend 测试相关逻辑会由 test_jit_backend
单测来承担
…n-backend-is-cinn
…s CINN (PaddlePaddle#71834) --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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_dynamic
、FLAGS_prim_skip_dynamic
、FLAGS_use_cinn
),用个flag_guard
就能确保内部能感知了,维护起来非常方便分阶段暴露问题,本 PR 修复 bug,完善机制,下个 PR 只修改默认值,暴露切默认所带来的问题
Related links
CINN 切默认系列 PR
build_strategy.build_cinn_pass
and replace it withbackend
option #71815FLAGS_use_cinn
viaos.getenv
#71817