Co-authored-by: chenhaozhe<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !47662 merge fxrt-port-squash into master fxrt: port upstream runtime changes made since the in-tree integration Created-by: c_34 Commit-by: chenhaozhe Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 https://gitcode.com/Ascend/pytorch/issues/5278 - [ ] 资料更新 同步进行in-tree合入过程中修改的原始仓库内容。 ## 背景 fxrt 整改合入 master 之后,上游(pta 分支)又积累了一批运行时改动。本 PR 把这些改动移植进 in-tree 的 `torch_npu.fxrt`,使两边重新对齐。 **`e64806be`** (08-31) 按生成时的 stride 寻址 compiled-kernel 参数 融合后端是针对参数在 trace 时的 stride 生成 kernel 的。记录这些 layout 并在调用前恢复,使期间被重新 layout 的参数仍按 kernel 预期的方式寻址。 → `compiled_kernel_adapter.py`、`fx_backend.py` **`81a537aa`** (09-02) DVM op 通过 pybind 头文件已授予 `fxrt::ops::OpDvmCallV2` 的 friendship 访问 torch_npu 的 DVM kernel 状态,而不是它从未存在过的公有 accessor;helper 折进 op 类以使 friendship 生效。动态与静态 kernel 合并为一个入口,由 kernel 的 `F_DYN` 标志区分。附带效果见下方「需要注意」。 → `src/ops/ascend/dvm/`、`dvm_adapter.py` **`ad4c84cc`** (09-02) AutoFuse 新增 `autofuse_call` op:dlopen AutoFuse codegen 产出的 wrapper stub 并直接 launch,外加生成该 stub 的 Python codegen。下降位置在 DVM 与通用 compiled-kernel 路径之间,由 `FXRT_AUTOFUSE_NATIVE=1` 门控。算子注册无需登记表,`LoadOpLib` 按 `libops_ascend*` 前缀发现。 → `src/ops/ascend/autofuse/`、`autofuse_codegen.py`、`ops.list` **`bbf45634`** (09-07) custom / torch / python call 的 ref、view 零拷贝 仅重新解释输入 storage 的输出不再拷贝。`OpRunner` 里通用的 ref 元数据同步会跳过输出 shape 与输入不同的算子,因此 view 类自定义算子自行计算元数据;`AclnnCustomViewOperator` 是它们的新基类,经 custom op API 暴露。 → `op_custom_call`、`op_torch_call`、`op_python_call`、`aclnn_custom_view_operator.h`、`data_convert` **`0ae75226`** (09-12) FXRT 自定义集合通信 用 arg-mapping hook 把 vLLM 四参数的 all_gather ABI 适配到 FXRT 原生三参数 HCCL ABI;从 FX 图收集通信信息时,把 vLLM 的逻辑 group 名解析为对应的 torch device ProcessGroup。 → `fx_backend.py`、`utils.py` **`c7e3a2e0`** (09-12) FX 操作数分类,自定义调用加固 一个 FX 参数能否走标量算子 ABI,改由 FXRT 运行时实际可表示的值决定,而不是看 node target —— `item` 节点不再仅凭名字就被当成标量。自定义调用侧在转换前校验操作数种类,并报出出错的那一个,而不是在转换深处失败。 → `fx_backend.py`、`symbolic_shape.py`、`op_torch_call`、`data_convert` **`37fcc1bb`** (09-22) 修复多输出 ref 算子的输出数据校验 ref alias 输出与输入共享 storage,且两侧都不持有 deleter,清掉共享的 data pointer 会让第一个之后的每个输出都校验失败。改为读取 storage 地址而不取走它,仅在持有所有权的路径上移出 data pointer。影响 split、unbind、chunk。 → `op_torch_call.cpp` **`6051b291`** (09-22) `Tensor[]` 自定义调用输出保留 ref alias 返回 `Tensor[]` 的自定义调用丢失了单 Tensor 输出能保留的 ref aliasing,导致列表里每个元素各自声明 storage。让 alias 穿过列表输出,并把 `c7e3a2e0` 引入的操作数预校验换成转换点上的检查。 → `fx_backend.py`、`op_torch_call`、`data_convert` ## 内容 建议按三组顺序审阅: 1. **compiled-kernel 路径**(`compiled_kernel_adapter.py`、`fx_backend.py`、`autofuse_codegen.py`、`src/ops/ascend/autofuse/`)——按 inductor 生成的 stride 寻址 kernel 参数而不再假定连续;FX 操作数分类,标量不再走张量路径;新增 `OP(autofuse_call)` 与 `FXRT_AUTOFUSE_NATIVE` 门控的原生 AutoFuse 下降。vLLM 集合通信 hook 在同一路径上,自成一体。 2. **零拷贝 view**(`op_custom_call`、`op_torch_call`、`op_python_call`、`aclnn_custom_view_operator.h`)——改为交出 ref 输出而非拷贝,`data_convert` 删掉只为喂拷贝而存在的转换。多输出校验修复与 `Tensor[]` alias 修复是对同一段代码的纠正。 3. **DVM v2**(`src/ops/ascend/dvm/`)——CMake 探测改为匹配 `torch_npu/csrc/inductor/dvm/pybind_api.h` 实际携带的 friend 声明,并通过该 friendship 访问 kernel 私有成员。 ## 需要 reviewer 注意 **两处对上游的有意偏离,均在 CMake**:autofuse 的 `CMakeLists.txt` 采用 in-tree 同级算子模块的写法,而非上游的 glob + 自带 `install()` 形式(上游还链接了 in-tree 不存在的 `fxrt::securec`);`ops_ascend_autofuse` 加入 `FXRT_OP_LIBS` 与 `install_fxrt` 拷贝列表,使 wheel 携带该库。 **一处告警屏蔽**: 为了处理autofuse的自动生成算子函数签名,实现中使用了一个长f-string字符串进行代码生成,这个长字符串触发了超长行的告警,参考之前cpp_wapper中类似情况的处理方式增加的`.flak8`的告警屏蔽。 ## 验证 Ascend 910B3 实测: - `test/fxrt` 7 项全部通过 - `libops_ascend_autofuse.so` / `libops_ascend_dvm_v2.so` 均构建产出、随 wheel 安装,运行时经 `/proc/self/maps` 确认已 dlopen - ref/view 定向用例 10/10 与 eager 一致:split(均分/不均分)、unbind、chunk、`split->add`、broadcast_tensors、select/permute、flatten/reshape、`item()` 标量、标量乘 - AutoFuse 门控双向验证:默认关闭与 `FXRT_AUTOFUSE_NATIVE=1` 结果均正确 - eta 推荐模型(inductor + fx_wrapper -> fxrt 运行时,batch 128)精度校验通过,QPS 8929;IR dump 显示 146 个 `compiled_kernel_mutation`,即本 PR 的 stride 与操作数分类改动在真实负载下被覆盖 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!47662
58 lines
2.1 KiB
INI
58 lines
2.1 KiB
INI
[flake8]
|
|
# NOTE: **Mirror any changes** to this file the [tool.ruff] config in pyproject.toml
|
|
# before we can fully move to use ruff
|
|
enable-extensions = G
|
|
select = B,C,E,F,G,P,SIM1,SIM911,T4,W,B9
|
|
max-line-length = 120
|
|
# C408 ignored because we like the dict keyword argument syntax
|
|
# E501 is not flexible enough, we're using B950 instead
|
|
ignore =
|
|
E203,E305,E402,E501,E704,E741,F405,F841,F999,W503,W504,C408,E302,W291,E303,F824,
|
|
# shebang has extra meaning in fbcode lints, so I think it's not worth trying
|
|
# to line this up with executable bit
|
|
EXE001,
|
|
# these ignores are from flake8-bugbear; please fix!
|
|
B007,B008,B017,B019,B023,B028,B903,B905,B906,B907,B908,B910
|
|
# these ignores are from flake8-simplify. please fix or ignore with commented reason
|
|
SIM105,SIM108,SIM110,SIM111,SIM113,SIM114,SIM115,SIM116,SIM117,SIM118,SIM119,SIM12,
|
|
# SIM104 is already covered by pyupgrade ruff
|
|
SIM104,
|
|
# flake8-simplify code styles
|
|
SIM102,SIM103,SIM106,SIM112
|
|
per-file-ignores =
|
|
__init__.py: F401
|
|
test/**: F821
|
|
test/**/__init__.py: F401,F821
|
|
torch/utils/cpp_extension.py: B950
|
|
torchgen/api/types/__init__.py: F401,F403
|
|
torchgen/executorch/api/types/__init__.py: F401,F403
|
|
test/dynamo/test_higher_order_ops.py: B950
|
|
test/dynamo/test_error_messages.py: B950
|
|
torch/testing/_internal/dynamo_test_failures.py: B950
|
|
torch/__init__.py: F401
|
|
torch/_prims/__init__.py: F401
|
|
# This file embeds long generated C++ launcher templates in f-strings.
|
|
torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/codegen/cpp_wrapper.py: B950,E128
|
|
# This file embeds the generated C++ AutoFuse launcher stub in an f-string.
|
|
fxrt/fxrt/python/fxrt/autofuse_codegen.py: B950
|
|
optional-ascii-coding = True
|
|
exclude =
|
|
./.git,
|
|
./build_test_custom_build,
|
|
./build,
|
|
./caffe2,
|
|
./docs/caffe2,
|
|
./docs/cpp/src,
|
|
./docs/src,
|
|
./functorch/docs,
|
|
./functorch/examples,
|
|
./functorch/docs/source/tutorials,
|
|
./torch/testing/_internal/py312_intrinsics.py
|
|
./scripts,
|
|
./test/generated_type_hints_smoketest.py,
|
|
./third_party,
|
|
./torch/include,
|
|
./torch/lib,
|
|
./venv,
|
|
*.pyi
|