已关闭
[Bug] 修复 DeepSeek PD ratio 编译路径中的 FX 动态 shape 拓扑错误 #412
lutean创建于  10 天前关闭于  2 天前
lutean成员
10 天前 创建

Problem

test_deepseek_model_pd_ratio_with_output_validation can fail during compilation with
BackendCompilerFailed. The immediate symptom is that generated FX code evaluates
view_default_1 using pow_2 before pow_2 is defined.

The failure is unrelated to whether PeepHolePass is enabled. This Issue is scoped to
the general FX graph-ordering invariant required by the compiler rewrite pipeline.

Reproduction

  1. Run the regression case:

    python -m pytest -m nightly tests/regression/cli/test_throughput_optimizer.py::TestThroughputOptimizer::test_deepseek_model_pd_ratio_with_output_validation -vv -s
    
  2. On an affected revision, compilation may raise:

    torch._dynamo.exc.BackendCompilerFailed
    ...
    UnboundLocalError: cannot access local variable 'pow_2' where it is not associated with a value
    

Expected

Compiler graph rewrite passes preserve FX topological order: symbolic shape-expression
nodes must be emitted before any view or reshape node that consumes them. The
DeepSeek PD-ratio output-validation regression should compile successfully.

Actual

AOT Autograd can produce a graph whose symbolic shape calculation appears after a
view consuming it. Subsequent rewrite passes can retain or rebuild this invalid order.
Generated code then references the symbolic expression before assignment, causing
BackendCompilerFailed.

Root Cause

  • CompilerBackend.compile() entered rewrite passes without normalizing the AOT FX graph.
  • LiftCombineQuantPass can rebuild view nodes, then runs dead-code elimination; the
    graph needs to be topologically restored and linted before that boundary.

Proposed Fix

  1. Call stable_topo_sort(gm) and gm.graph.lint() before compiler graph rewrites.
  2. After LiftCombineQuantPass rebuilds views, call stable_topo_sort(gm) and lint
    before dead-code elimination.
  3. Add a focused unit regression with view(..., [-1, operator.pow(x, 2)]), asserting
    pow precedes view and graph lint passes before and after the pass.

Acceptance Criteria

Evidence

  • PR 802 contains the focused compiler and regression-test changes.
  • The PR diff after synchronizing with master is limited to 3 files and +59/-2.
  • Previous local verification recorded for the PR: targeted topology tests (2 passed),
    related rewrite tests (24 passed), and the DeepSeek PD-ratio regression passed.
likedislike
Llutean成员
10 天前 添加了label:Bug
kai1949
kai1949成员
10 天前 评论:

/label add triaged
👋 您好,欢迎向 MindStudio-Modeling 提交 Issue!
我们已收到您的反馈,感谢你对开源社区的支持。🎉

📅处理时效: 维护团队将在8小时内 查看并回复您的问题(工作日)。
🔍自助查询: 在等待期间,建议您先查阅以下资料,可能已有解决方案:

📖 MindStudio-Modeling官方文档
📝 贡献者指南

请确保 Issue 描述清晰,包含复现步骤和日志,这将帮助我们更快定位问题。谢谢!

likedislike
ascend-robotascend-robot成员
10 天前 添加了label:bug
ascend-robotascend-robot成员
10 天前 添加了label:triaged
Llutean成员
10 天前 关联了pull request:fix(tensor-cast): restore dynamic shape graph ordering
jia_ya_nan成员
10 天前 评论:

/label add resolved

likedislike
ascend-robotascend-robot成员
10 天前 添加了label:resolved
ascend-robot
ascend-robot成员
3 天前 评论:

您好,当前Issue标记为resolved且有一段时间未进一步更新,因此我们将其标记为'stale'(闲置)状态。若您认为这是误操作,可通过添加任意评论来去除'stale'标签。标记为stale的Issue在4天内无更新活动将自动关闭。

likedislike
ascend-robotascend-robot成员
3 天前 添加了label:stale
lutean成员
2 天前 评论:

/label add resolved

likedislike
Llutean成员
2 天前 issue状态由 TODO 改变为 DONE
Llutean成员
2 天前 关闭了 issue