17 Commits
Author SHA1 Message Date
stonexxx 95c7e46542 fix(inductor): 适配 NPU selector 的 best_config_future 参数
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!47604 merge select_fix into master

fix(inductor): 适配 NPU selector 的 best_config_future 参数

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

Fixes https://gitcode.com/Ascend/pytorch/issues/5312

# 【修改方案】

1. 在 `torch_npu/_inductor/select_algorithm.py` 的 NPU `AlgorithmSelectorCache.__call__` 补丁中对齐上游可选参数,支持 `best_config_future`,避免 GEMM lowering 传入该关键字时发生参数不兼容。
2. 等待并复用 future 返回的配置,筛选匹配候选,将筛选后的 choices 用于 cache lookup 和反馈。
3. 移除“首个 choice 不在 timings 即回退”的判断,从有效 timings 中选择最快候选,正确处理 future 筛掉首个候选的场景。
4. 保留已有 timeout、多模板及 defer 行为。`is_collective`、`min_speedup_threshold` 和 `benchmark_with_cudagraphs` 本次仅兼容签名,并标注 `Not supported on NPU`。

# 【资料变更】

不涉及。

# 【接口变更】

内部跨仓兼容适配:NPU selector 补丁签名与上游 PyTorch Inductor 的可选参数对齐。现有参数默认值不变,对外公开 API 无新增。

# 【功能验证】

提交:`73479a8a7dc7075c8828b57dc211b1554aabe70f`。

通过历史回归脚本(`c47dc0180e`)临时隔离加载当前 selector,验证签名及默认值、future 候选筛选、首个候选无 timing 时的最优选择,3 项测试全部通过。本分支未新增测试文件。

实际执行命令:

```bash
python3 /tmp/select-fix-pr-9gxtvfj4/validate_selector.py
python3 -m py_compile torch_npu/_inductor/select_algorithm.py
lintrunner -a torch_npu/_inductor/select_algorithm.py
git diff --check refs/remotes/mainline/master...select_fix
git merge-tree --write-tree refs/remotes/mainline/master select_fix
```

语法、lint 和 diff 检查通过,与目标 master 合并无冲突。验证范围为 Python 逻辑;本机缺少 `torch_npu._C`,NPU 真机验证、远端 CI 及自验证截图尚未提供。

# 【CheckList】

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!47604
2026-10-09 17:45:09 +08:00
stonexxx 3257810d43 fix: remove config.simt_default_warp_stacksize
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!46884 merge sync-pr46494-mainline-master into master

fix: remove config.simt_default_warp_stacksize

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

Fixes https://gitcode.com/Ascend/pytorch/issues/5045

同步来源:https://gitcode.com/Ascend/pytorch/merge_requests/46494

# 【修改方案】

1. 删除 `torch_npu/_inductor/config.py` 中固定为 8192 字节的 `simt_default_warp_stacksize` 配置。
2. 删除 `NPUCachingAutotuner._make_ttir_module_from_cfg` 和 `NPUCachingAutotuner._precompile_config` 在 `SIMT_ONLY` 模式下自动注入 `simt_stack_limit` 的逻辑,由 Triton 编译器或后端使用默认栈大小策略。

# 【资料变更】

不涉及。

# 【接口变更】

不涉及跨代码仓或客户可见接口变更。

# 【功能验证】

- `python3 -m py_compile torch_npu/_inductor/config.py torch_npu/_inductor/runtime/triton_heuristics.py`:通过。
- `git diff --check mainline/master...HEAD`:通过。
- 迁移提交与源提交的稳定 patch-id 均为 `495e5401e7d86ac029a774bf2a108054f2db9d5e`。
- NPU 功能验证与 CI 结果以 PR 流水线为准。

# 【CheckList】

- [x] 代码注释完备,正确记录错误日志(本次仅删除配置和选项注入逻辑,无新增注释或日志)
- [ ] 代码实现进行了返回值、空指针等校验(本次不涉及返回值或空指针处理)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常

See merge request: Ascend/pytorch!46884
2026-09-23 16:51:46 +08:00
stonexxx 37343f3710 [Inductor] combine FlexAttention bounded workspace and runtime dispatch
Co-authored-by: stonexxx<sheny1xuan@163.com>
Co-authored-by: Xuan Peng<pengxuan9@huawei.com>



# message auto-generated for no-merge-commit merge:
!46451 merge codex/combine-pr46393-pr46408-master into master

[Inductor] combine FlexAttention bounded workspace and runtime dispatch

Created-by: stonexxx
Commit-by: Stonexx;stonexxx;Xuan Peng
Merged-by: ascend-robot
Description: ## 变更说明

基于最新 `mainline/master` 组合迁移以下修改:

- !46393:为 FlexAttention forward compact mask 提供有界 workspace,并增加 workspace/scan 测试。
- !46408:引入 FlexAttention runtime DispatchPlan,统一 forward、dQ、dK/dV 派发,并专用化 backward mask-out 模板。

## 冲突处理

组合迁移在以下位置发生内容冲突:

- `torch_npu/_inductor/config.py`:同时保留 `fwd_mask_workspace_bytes` 和 `flexattention_dispatch_strategy` 配置及环境变量读取。
- `torch_npu/_inductor/kernel/flex_attention.py`:同时导入 workspace 模板与 all-sparse dispatch 模板。

迁移后静态检查发现配置块缺少闭合括号,已在独立修复提交中解决:

- `929db0224b fix(inductor): resolve FlexAttention config integration conflict`

## 验证

- `python -m compileall -q torch_npu/_inductor`:通过。
- `test_flex_attention_fwd_workspace_source.py`:7/7 通过。
- `test_flex_attention_fwd_workspace.py`:5/5 策略测试通过,其余 NPU/慢测按条件跳过。
- a5-37 / torch213 环境验证通过,TorchNPU overlay 命中组合分支。
- Mojo `run.bash`:135/135 个预期 case 通过。脚本内 134 个有效命令完成;原第 67 行缺失 `]`,修正后补跑通过。
- 原串行回归中 1 次参考端 `aclnnNonzero` 异常在干净环境复跑通过。
- 多卡尝试确认容器仅暴露 7 张 NPU 且 cgroup 内存上限为 96 GiB;高并发编译造成的 `SIGKILL(-9)` 均在降低并发后通过,不计为代码失败。

验证日志:`/home/s00835054/codex_work/c6ef4842-5f58-431f-985a-6dc49f982974/`

关联 Issue:#4873


See merge request: Ascend/pytorch!46451
2026-09-22 14:49:23 +08:00
stonexxx 1655908202 fix(inductor): disable multi-template for mutating kernels
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!46129 merge fix/disable-multitemplate-for-mutated-inputs into master

fix(inductor): disable multi-template for mutating kernels

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [x] 重构优化
- [ ] 资料更新

# 【修改方案】

https://gitcode.com/Ascend/pytorch/issues/4722

1. 当 AlgorithmSelector 的候选 kernel 带有 `mutated_inputs` 时,`MultiTemplateBuffer` 无法保留模板的 mutation 输出。开启 max-autotune 后,FlexAttention backward 可能通过 multi-template 路径完成选择,造成 query gradient 变为 NaN。
2. 在计算 deferred epilogue 条件前过滤空 choice,并检查候选 kernel 是否包含 `mutated_inputs`。
3. 对带 mutation 的候选禁用 deferred multi-template,强制按普通 template buffer 完成选择并保留 mutation 输出;不改变无 mutation 候选的调度行为。

# 【资料变更】

不涉及。

# 【接口变更】

不涉及客户可见或跨仓接口变更。

# 【功能验证】

1. Ascend 950、torch_npu 2.13 环境,清理 Inductor/Triton/ACL cache 后执行:
   `TORCHINDUCTOR_MAX_AUTOTUNE=1 python -m pytest testcase_score_mask_combos_npu.py::test_score_mod_mask_mod_combo[identity-x-noop] -v -s`
2. 修改前:`1 failed, 95 warnings`,失败原因为编译后的 query gradient 全为 NaN。
3. 修改后:`1 passed, 95 warnings in 159.48s`。
4. `python3 -m py_compile torch_npu/_inductor/select_algorithm.py`、flake8 和 `git diff --check`:通过。

# 【CheckList】

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!46129
2026-09-10 17:09:17 +08:00
stonexxx d179f5e3a7 fix(inductor): validate deferred epilogue compilation
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!46091 merge fix/deferred-epilogue-compile-check-pr into master

fix(inductor): validate deferred epilogue compilation

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

Fixes https://gitcode.com/Ascend/pytorch/issues/4708

# 【修改方案】

1. 问题发生在 FlexAttention template 带 `_npu_deferred_epilogue_compile_only=True`、与 pointwise epilogue 进入 speculative fusion 检查、`AsyncCompile` 进程池仍处于冷启动且 fused kernel 存在编译错误时。此时 fused `attention + cos` kernel 因 UB 需求超过硬件容量而无法编译。
2. 定位探针确认 lowering 与 scheduler 获取的是同一个 `TritonTemplateBuffer`,deferred 标记在 scheduler 中仍为 `True`,`speedup_by_fusion` 也正确返回 deferred callback,排除了 `_to_copy` 包装或模板替换导致标记丢失的可能。
3. 出错时的关键调用栈如下:

   ```text
   test_epilogue_fused_npu
     -> run_and_get_code / torch.compile
     -> GraphLowering.compile_to_module
     -> Scheduler.fuse_nodes
     -> torch_npu Scheduler.fuse_nodes_once
     -> Scheduler.speedup_by_fusion
     -> compile_kernel(node_list_fused)
     -> AsyncCompile.use_process_pool() == False
     -> PyCodeCache.load(fused benchmark source), future = None
     -> compile_when_ready() returns True
     -> fuse attention template with cos epilogue
     -> final generated module: async_compile.wait
     -> NPUCachingAutotuner.precompile
     -> triton.compile
     -> BiShengIR buildFinalHIVMPipelines
     -> hivm-plan-memory-regbase
     -> ub overflow
   ```

4. 根因是 `AsyncCompile.use_process_pool()` 首次调用提交 ready task 后立即返回 `ready_future.done()`;进程池未 ready 时结果为 `False`。原 deferred callback 仅在 future 非空时调用 `future.result()`,对 `future=None` 未执行同步编译却直接返回成功,导致 fused kernel 被错误接受。
5. 回退上一版自定义方案:删除 `_compile_triton_for_fusion()` 和为其引入的 `CodeCacheFuture` 类型扩展,恢复社区 `compile_kernel()` 的 `(future, mod)` 返回协议及原有 process-pool 判断。
6. 与社区 PyTorch 的 `future=None` 处理保持一致:
   - multi-template deferred epilogue 路径中,future 非空时调用 `future.result()`;future 为 `None` 时调用 `mod_fused.triton_.precompile()`。
   - single-template deferred epilogue 路径中,future 非空时调用 `future_and_mod_fused[0].result()`;future 为 `None` 时调用 `future_and_mod_fused[1].triton_.precompile()`。
   - 两条路径的同步或异步编译异常均由现有异常处理捕获并返回 `False`,触发 unfused fallback。
7. 最终相对 master 仅修改 `torch_npu/_inductor/scheduler.py`,不新增测试文件,不改变普通 fusion benchmark 行为。

# 【资料变更】

不涉及。

# 【接口变更】

不涉及客户可见或跨仓接口变更。仅修正 TorchNPU Inductor 内部 deferred epilogue speculative compile 行为。

# 【功能验证】

1. 强制同步路径:

   `TORCHINDUCTOR_COMPILE_THREADS=1 pytest test_flex_attention213.py::TestFlexAttentionPRIVATEUSE1::test_epilogue_fused_npu -q`

   - 环境:`torch_npu: 2.13.0`,`NPU: Ascend 950`,使用空 Inductor cache。
   - 结果:`1 passed, 14 warnings`,pytest 退出码为 0。
   - 验证 `future=None` 时 `mod_fused.triton_.precompile()` 能捕获 UB overflow 并回退。
2. 默认冷启动路径:

   `pytest test_flex_attention213.py::TestFlexAttentionPRIVATEUSE1::test_epilogue_fused_npu -q`

   - 使用默认编译线程和空 Inductor cache。
   - 结果:`1 passed, 14 warnings`,pytest 退出码为 0。
3. `python3 -m py_compile torch_npu/_inductor/scheduler.py`:通过。
4. `flake8 torch_npu/_inductor/scheduler.py`:通过。
5. `git diff --check mainline/master...HEAD`:通过。

# 【CheckList】

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!46091
2026-09-09 21:16:13 +08:00
stonexxx b05032cde5 fix(inductor): summarize NPU autotune error logs
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!46117 merge fix/concise-autotune-error-logging into master

fix(inductor): summarize NPU autotune error logs

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

Fixes https://gitcode.com/Ascend/pytorch/issues/4714

# 【修改方案】

1. 问题发生在 NPU autotune 候选的 precompile future、当前进程 `NPUCompileError` 或可忽略 `RuntimeError` 携带完整编译器诊断时。原 ERROR 日志直接记录完整异常字符串,导致 MLIR、内存规划 IR 和大量 `hivm.hir` 指令进入默认日志。
2. 新增 `_summarize_autotune_error()`,过滤空行并仅保留诊断末尾 8 行;诊断被截断时增加明确的 suppression 标记,空异常按异常类型或 `empty error` 输出。
3. 新增 `_log_autotune_error()`,在 ERROR 级别统一输出错误类别、包含配置的 choice 标签、是否忽略该候选以及精简摘要;仅在 DEBUG 级别输出完整编译诊断。
4. 将并发 precompile future 异常、当前进程 `NPUCompileError` 和可忽略 `RuntimeError` 三个入口接入统一日志函数。候选 timing、失败忽略和 autotune 选择控制流保持不变。

# 【资料变更】

不涉及。

# 【接口变更】

不涉及客户可见或跨仓接口变更。仅调整 TorchNPU Inductor 内部 autotune 错误日志的详细程度。

# 【功能验证】

1. 清空 Inductor、Triton 和 pytest cache 后执行:

   `TORCHINDUCTOR_MAX_AUTOTUNE=1 pytest test_flex_attention_base_case2.py -v -s`

   - 环境:`torch_npu: 2.13.0`,`NPU: Ascend 950`。
   - 结果:`36 passed, 15 warnings`,pytest 退出码为 0。
   - 命中 10 次截断摘要,其中 precompile 失败 5 次、runtime 失败 5 次。
   - ERROR 日志中 `IR Dump After`、`module attributes`、`hivm.hir.anchor` 和 `func.func` 均为 0 次。
   - 完整日志为 458 行、约 131 KiB;剩余主要内容是 max-autotune 正常候选性能表。
2. 定向 helper 行为验证覆盖:长诊断末尾 8 行、suppression 标记、空异常回退、choice 配置标签、ignored 后缀以及 DEBUG 完整诊断,结果通过。
3. `python3 -m py_compile torch_npu/_inductor/select_algorithm.py`:通过。
4. `flake8 torch_npu/_inductor/select_algorithm.py`:通过。
5. `git diff --check mainline/master...HEAD`:通过。

# 【CheckList】

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!46117
2026-09-09 20:07:30 +08:00
stonexxx 0a99256333 fix(inductor): default FlexAttention backward kernel options
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!46010 merge issue100 into master

fix(inductor): default FlexAttention backward kernel options

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

Fixes https://gitcode.com/Ascend/pytorch/issues/4683

# 【修改方案】
FlexAttention 的公开 API 会通过 `_apply_kernel_options` 补齐 backward kernel options,但直接调用 `torch.ops.higher_order.flex_attention_backward` 时可能传入空字典,从而绕过该处理。

NPU mask-out backward lowering 在 Jinja 模板渲染阶段会读取 `PRESCALE_QK`。此时 Triton constexpr 参数尚未物化,缺失该选项会触发 `jinja2.exceptions.UndefinedError`。同时,公开 API 中定义的 `WRITE_DQ` 默认值也未在该 lowering 中补齐。

本修改:

1. 在 NPU FlexAttention backward lowering 进入模板路由前补齐:
   - `PRESCALE_QK=False`
   - `WRITE_DQ=True`
2. 使用 `setdefault` 保留调用方显式传入的配置。
3. 增加回归测试,验证注册的 backward lowering 能为缺失选项补齐默认值。

# 【资料变更】
不涉及。

# 【接口变更】
不涉及公开接口变更,仅补齐内部 lowering 的默认参数。调用方显式设置的 kernel options 仍具有优先级。

# 【功能验证】
本地测试:

```bash
python3 -m pytest -q \
  test/_inductor/test_flex_attention_dynamic_mask_out.py \
  test/_inductor/test_flex_attention_dynamic_mask_metadata.py
```

结果:`6 passed, 2 skipped`

```bash
python3 -m py_compile \
  torch_npu/_inductor/kernel/flex_attention.py \
  test/_inductor/test_flex_attention_dynamic_mask_out.py

git diff --check mainline/master...HEAD
```

结果:均通过。

Torch 2.13 + torch_npu 2.13 nightly 环境运行目标用例:

```bash
pytest -vs \
  test_flex_attention213.py::TestFlexAttentionPRIVATEUSE1::test_direct_backward_preserves_explicit_buffers_npu
```

结果:`1 passed, 20 warnings in 151.71s`

生成的 `output_code.py` 中确认物化参数为:

```python
PRESCALE_QK: tl.constexpr = False
WRITE_DQ: tl.constexpr = True
```

环境依赖检查:`uv pip check` 通过,36 个包兼容。

# 【CheckList】
- [x] 代码注释完备,正确记录错误日志(本修改不新增错误分支)
- [x] 代码实现进行了返回值、空指针等校验(本修改不涉及新的输入或指针处理)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常

See merge request: Ascend/pytorch!46010
2026-09-08 20:09:47 +08:00
stonexxx 5009bdee7a flexattention: revert decoding tiling 128 default
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!46031 merge decoding_tiling into master

flexattention: revert decoding tiling 128 default

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
https://gitcode.com/Ascend/pytorch/issues/4694

# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!46031
2026-09-08 19:11:58 +08:00
stonexxx 783cea03b3 flexattention: decoding use one config might ub overflow
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!45757 merge decoding_tiilng into master

flexattention: decoding use one config might ub overflow

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新

# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常

https://gitcode.com/Ascend/pytorch/issues/4496

See merge request: Ascend/pytorch!45757
2026-09-07 15:59:49 +08:00
stonexxx a6e3d16aa7 [flexattention]: sync 2.7.1 bugfix to master
Co-authored-by: ascend-robot<zhongyuanke@huawei.com>
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!45609 merge sync_master into master

add flexattention score_mod support zeros_and_scatter op

Created-by: stonexxx
Commit-by: ascend-robot;Stonexx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

https://gitcode.com/Ascend/pytorch/issues/4496

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!45609
2026-09-01 14:56:43 +08:00
stonexxx c0ee704dc0 fix(flex-attention): align score mod and torch 2.13 interfaces
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!45141 merge rebase_sync_master_06_torch213 into master

fix(flex-attention): align score mod and torch 2.13 interfaces

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] 重构优化

# 【修改方案】
1. 修正显式及默认 identity score_mod 的路由与模板处理。
2. 补齐动态 shape 场景所需的兼容修复。
3. 对齐 PyTorch 2.13 flex attention 模板输出、辅助函数和 lowering 接口。

本 PR 是 rebase_sync_master 拆分序列的第 6/6 个,依赖前序 PR #45140,请按编号顺序合入。

# 【资料变更】
不涉及。

# 【接口变更】
不涉及对外接口变更。

# 【功能验证】
- 受影响 Python 文件 compileall 通过。
- FlexAttentionConfigGenerator 各模式约束与 tiling 降序 smoke test 通过。
- squash 前后最终 tree 一致。

# 【CheckList】
- [x] 代码注释与错误处理已自检
- [x] PR 标题使用规范类型标签
- [x] 不提交设计文档或测试文件

# 【关联 Issue】
- [#4289 [FlexAttention] 对齐 score mod 与 Torch 2.13 接口](https://gitcode.com/Ascend/pytorch/issues/4289)


See merge request: Ascend/pytorch!45141
2026-08-25 11:57:59 +08:00
stonexxx 119c5ce680 feat(flex-attention): initialize community codegen path
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!45140 merge rebase_sync_master_05_community_codegen into master

feat(flex-attention): initialize community codegen path

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] 重构优化

# 【修改方案】
1. 引入社区 flex attention mask-in lowering 与 TritonTemplate 生成流程。
2. 保留 NPU 子图 additional lowerings、NPU tiling 与可编译 tiling 降序选择规则。
3. 将 mask-in 与 mask-out 路由解耦,同时保持 NPU compile-option forwarding。

本 PR 是 rebase_sync_master 拆分序列的第 5/6 个,依赖前序 PR #45139,请按编号顺序合入。

# 【资料变更】
不涉及。

# 【接口变更】
不涉及对外接口变更。

# 【功能验证】
- 受影响 Python 文件 compileall 通过。
- FlexAttentionConfigGenerator 各模式约束与 tiling 降序 smoke test 通过。
- squash 前后最终 tree 一致。

# 【CheckList】
- [x] 代码注释与错误处理已自检
- [x] PR 标题使用规范类型标签
- [x] 不提交设计文档或测试文件

# 【关联 Issue】
- [#4288 [FlexAttention] 接入社区 mask-in codegen 路径](https://gitcode.com/Ascend/pytorch/issues/4288)


See merge request: Ascend/pytorch!45140
2026-08-25 09:29:22 +08:00
stonexxx d2554209d3 refactor(flex-attention): cleanup metadata inference
Co-authored-by: stonexxx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!45138 merge rebase_sync_master_03_metadata into master

refactor(flex-attention): cleanup metadata inference

Created-by: stonexxx
Commit-by: stonexxx
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] 重构优化

# 【修改方案】
1. 清理 flex attention metadata 推导中的冗余路径。
2. 合并 compile mode 日志禁用相关同步结果。
3. 保持 eager BlockMask 元数据到 kernel options 的行为不变。

本 PR 是 rebase_sync_master 拆分序列的第 3/6 个,依赖前序 PR #45137,请按编号顺序合入。

# 【资料变更】
不涉及。

# 【接口变更】
不涉及对外接口变更。

# 【功能验证】
- 受影响 Python 文件 compileall 通过。
- FlexAttentionConfigGenerator 各模式约束与 tiling 降序 smoke test 通过。
- squash 前后最终 tree 一致。

# 【CheckList】
- [x] 代码注释与错误处理已自检
- [x] PR 标题使用规范类型标签
- [x] 不提交设计文档或测试文件

# 【关联 Issue】
- [#4286 [FlexAttention] 清理 metadata inference 与 compile logging](https://gitcode.com/Ascend/pytorch/issues/4286)


See merge request: Ascend/pytorch!45138
2026-08-24 21:02:43 +08:00
stonexxx 210fd8088f refactor(flex-attention): simplify tiling config generation
Co-authored-by: stonexxx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!45137 merge rebase_sync_master_02_tiling into master

refactor(flex-attention): simplify tiling config generation

Created-by: stonexxx
Commit-by: stonexxx
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] 重构优化

# 【修改方案】
1. 统一 FlexAttention 前向、反向及辅助模板的 tiling 候选生成入口。
2. 在生成阶段完成 sparse block 有效性约束,并按 block 面积从大到小排序。
3. 保留 NPU 模板额外 compile options 的设置边界。

本 PR 是 rebase_sync_master 拆分序列的第 2/6 个,依赖前序 PR #45136,请按编号顺序合入。

# 【资料变更】
不涉及。

# 【接口变更】
不涉及对外接口变更。

# 【功能验证】
- 受影响 Python 文件 compileall 通过。
- FlexAttentionConfigGenerator 各模式约束与 tiling 降序 smoke test 通过。
- squash 前后最终 tree 一致。

# 【CheckList】
- [x] 代码注释与错误处理已自检
- [x] PR 标题使用规范类型标签
- [x] 不提交设计文档或测试文件

# 【关联 Issue】
- [#4285 [FlexAttention] 统一并简化 tiling config 生成](https://gitcode.com/Ascend/pytorch/issues/4285)


See merge request: Ascend/pytorch!45137
2026-08-24 19:57:14 +08:00
stonexxx 013799cce3 refactor(flex-attention): cleanup and support scalar remainder
Co-authored-by: stonexxx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!45136 merge rebase_sync_master_01_cleanup into master

refactor(flex-attention): cleanup and support scalar remainder

Created-by: stonexxx
Commit-by: stonexxx
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] 重构优化

# 【修改方案】
1. 清理 flex attention 中未使用的 block mask cast 与冗余逻辑。
2. 补齐短序列 fallback、custom mod 标量余数处理及精度适配。
3. 保留当前 master 所需的 NPU compile-option forwarding。

本 PR 是 rebase_sync_master 拆分序列的第 1/6 个,合并后请继续审阅后续 PR。

# 【资料变更】
不涉及。

# 【接口变更】
不涉及对外接口变更。

# 【功能验证】
- 受影响 Python 文件 compileall 通过。
- FlexAttentionConfigGenerator 各模式约束与 tiling 降序 smoke test 通过。
- squash 前后最终 tree 一致。

# 【CheckList】
- [x] 代码注释与错误处理已自检
- [x] PR 标题使用规范类型标签
- [x] 不提交设计文档或测试文件

# 【关联 Issue】
- [#4284 FlexAttention 清理冗余逻辑并支持 scalar remainder](https://gitcode.com/Ascend/pytorch/issues/4284)


See merge request: Ascend/pytorch!45136
2026-08-24 18:12:49 +08:00
stonexxx 674bd50f69 flexattention: sync lse base conversion
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!45005 merge sync_lse_master into master

flexattention: sync lse base conversion

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

https://gitcode.com/Ascend/pytorch/issues/4246

# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!45005
2026-08-21 14:32:57 +08:00
stonexxx 11babe251d flexattention: port flexattention template to 2.13
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!44356 merge fa_213_origin into master

flexattention: port flexattention template to 2.13

Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>https://gitcode.com/Ascend/pytorch/issues/2571

- [x] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新

# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!44356
2026-08-12 17:45:31 +08:00