From 43be79a08004922c5cb1ee8f23cfb8e87aeb75b9 Mon Sep 17 00:00:00 2001 From: zhengyang Date: Thu, 18 Jun 2026 20:33:27 +0800 Subject: [PATCH 1/4] [SPEC] Move third_party/ascend/backend/spec/triton to python/triton/spec/ascend --- python/triton/flagtree_spec.py | 2 +- python/triton/spec/ascend/__init__.py | 1 + .../triton/spec/ascend}/compiler/code_generator.py | 0 .../triton => python/triton/spec/ascend}/compiler/compiler.py | 0 .../triton => python/triton/spec/ascend}/compiler/errors.py | 0 .../triton/spec/ascend}/extension/buffer/__init__.py | 0 .../triton/spec/ascend}/extension/buffer/language/__init__.py | 0 .../triton/spec/ascend}/extension/buffer/language/builder.py | 0 .../triton/spec/ascend}/extension/buffer/language/core.py | 0 .../triton/spec/ascend}/extension/buffer/language/semantic.py | 0 .../triton => python/triton/spec/ascend}/language/__init__.py | 0 .../spec/triton => python/triton/spec/ascend}/language/core.py | 0 .../spec/triton => python/triton/spec/ascend}/language/math.py | 0 .../triton => python/triton/spec/ascend}/language/random.py | 0 .../triton => python/triton/spec/ascend}/language/semantic.py | 0 .../triton => python/triton/spec/ascend}/language/standard.py | 0 .../triton/spec/ascend}/language/target_info.py | 0 .../triton => python/triton/spec/ascend}/runtime/__init__.py | 0 .../triton => python/triton/spec/ascend}/runtime/_allocation.py | 0 .../triton/spec/ascend}/runtime/_async_compile.py | 0 .../triton/spec/ascend}/runtime/ascend_interpreter.py | 0 .../triton => python/triton/spec/ascend}/runtime/autotuner.py | 0 .../spec/triton => python/triton/spec/ascend}/runtime/build.py | 0 .../triton => python/triton/spec/ascend}/runtime/code_cache.py | 0 .../spec/triton => python/triton/spec/ascend}/runtime/driver.py | 0 .../spec/triton => python/triton/spec/ascend}/runtime/errors.py | 0 .../triton => python/triton/spec/ascend}/runtime/interpreter.py | 0 .../spec/triton => python/triton/spec/ascend}/runtime/jit.py | 0 .../triton => python/triton/spec/ascend}/runtime/libentry.py | 0 .../triton/spec/ascend}/tools/get_ascend_devices.py | 0 third_party/ascend/backend/spec/__init__.py | 1 - 31 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 python/triton/spec/ascend/__init__.py rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/compiler/code_generator.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/compiler/compiler.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/compiler/errors.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/extension/buffer/__init__.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/extension/buffer/language/__init__.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/extension/buffer/language/builder.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/extension/buffer/language/core.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/extension/buffer/language/semantic.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/language/__init__.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/language/core.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/language/math.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/language/random.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/language/semantic.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/language/standard.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/language/target_info.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/__init__.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/_allocation.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/_async_compile.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/ascend_interpreter.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/autotuner.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/build.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/code_cache.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/driver.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/errors.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/interpreter.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/jit.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/runtime/libentry.py (100%) rename {third_party/ascend/backend/spec/triton => python/triton/spec/ascend}/tools/get_ascend_devices.py (100%) delete mode 100644 third_party/ascend/backend/spec/__init__.py diff --git a/python/triton/flagtree_spec.py b/python/triton/flagtree_spec.py index 017a7e7817..578a737932 100644 --- a/python/triton/flagtree_spec.py +++ b/python/triton/flagtree_spec.py @@ -45,7 +45,7 @@ def spec_path(path_list: list): return triton_root = current_path[:idx + len(marker)] rel_path = current_path[idx + 1 + len(marker):] - backend_path = os.path.join(triton_root, "backends", FLAGTREE_BACKEND, "spec", "triton", rel_path) + backend_path = os.path.join(triton_root, "spec", FLAGTREE_BACKEND, rel_path) if os.path.isdir(backend_path) and backend_path not in path_list: path_list.insert(0, backend_path) diff --git a/python/triton/spec/ascend/__init__.py b/python/triton/spec/ascend/__init__.py new file mode 100644 index 0000000000..7b9fa942f3 --- /dev/null +++ b/python/triton/spec/ascend/__init__.py @@ -0,0 +1 @@ +from .language import language_extend_globals diff --git a/third_party/ascend/backend/spec/triton/compiler/code_generator.py b/python/triton/spec/ascend/compiler/code_generator.py similarity index 100% rename from third_party/ascend/backend/spec/triton/compiler/code_generator.py rename to python/triton/spec/ascend/compiler/code_generator.py diff --git a/third_party/ascend/backend/spec/triton/compiler/compiler.py b/python/triton/spec/ascend/compiler/compiler.py similarity index 100% rename from third_party/ascend/backend/spec/triton/compiler/compiler.py rename to python/triton/spec/ascend/compiler/compiler.py diff --git a/third_party/ascend/backend/spec/triton/compiler/errors.py b/python/triton/spec/ascend/compiler/errors.py similarity index 100% rename from third_party/ascend/backend/spec/triton/compiler/errors.py rename to python/triton/spec/ascend/compiler/errors.py diff --git a/third_party/ascend/backend/spec/triton/extension/buffer/__init__.py b/python/triton/spec/ascend/extension/buffer/__init__.py similarity index 100% rename from third_party/ascend/backend/spec/triton/extension/buffer/__init__.py rename to python/triton/spec/ascend/extension/buffer/__init__.py diff --git a/third_party/ascend/backend/spec/triton/extension/buffer/language/__init__.py b/python/triton/spec/ascend/extension/buffer/language/__init__.py similarity index 100% rename from third_party/ascend/backend/spec/triton/extension/buffer/language/__init__.py rename to python/triton/spec/ascend/extension/buffer/language/__init__.py diff --git a/third_party/ascend/backend/spec/triton/extension/buffer/language/builder.py b/python/triton/spec/ascend/extension/buffer/language/builder.py similarity index 100% rename from third_party/ascend/backend/spec/triton/extension/buffer/language/builder.py rename to python/triton/spec/ascend/extension/buffer/language/builder.py diff --git a/third_party/ascend/backend/spec/triton/extension/buffer/language/core.py b/python/triton/spec/ascend/extension/buffer/language/core.py similarity index 100% rename from third_party/ascend/backend/spec/triton/extension/buffer/language/core.py rename to python/triton/spec/ascend/extension/buffer/language/core.py diff --git a/third_party/ascend/backend/spec/triton/extension/buffer/language/semantic.py b/python/triton/spec/ascend/extension/buffer/language/semantic.py similarity index 100% rename from third_party/ascend/backend/spec/triton/extension/buffer/language/semantic.py rename to python/triton/spec/ascend/extension/buffer/language/semantic.py diff --git a/third_party/ascend/backend/spec/triton/language/__init__.py b/python/triton/spec/ascend/language/__init__.py similarity index 100% rename from third_party/ascend/backend/spec/triton/language/__init__.py rename to python/triton/spec/ascend/language/__init__.py diff --git a/third_party/ascend/backend/spec/triton/language/core.py b/python/triton/spec/ascend/language/core.py similarity index 100% rename from third_party/ascend/backend/spec/triton/language/core.py rename to python/triton/spec/ascend/language/core.py diff --git a/third_party/ascend/backend/spec/triton/language/math.py b/python/triton/spec/ascend/language/math.py similarity index 100% rename from third_party/ascend/backend/spec/triton/language/math.py rename to python/triton/spec/ascend/language/math.py diff --git a/third_party/ascend/backend/spec/triton/language/random.py b/python/triton/spec/ascend/language/random.py similarity index 100% rename from third_party/ascend/backend/spec/triton/language/random.py rename to python/triton/spec/ascend/language/random.py diff --git a/third_party/ascend/backend/spec/triton/language/semantic.py b/python/triton/spec/ascend/language/semantic.py similarity index 100% rename from third_party/ascend/backend/spec/triton/language/semantic.py rename to python/triton/spec/ascend/language/semantic.py diff --git a/third_party/ascend/backend/spec/triton/language/standard.py b/python/triton/spec/ascend/language/standard.py similarity index 100% rename from third_party/ascend/backend/spec/triton/language/standard.py rename to python/triton/spec/ascend/language/standard.py diff --git a/third_party/ascend/backend/spec/triton/language/target_info.py b/python/triton/spec/ascend/language/target_info.py similarity index 100% rename from third_party/ascend/backend/spec/triton/language/target_info.py rename to python/triton/spec/ascend/language/target_info.py diff --git a/third_party/ascend/backend/spec/triton/runtime/__init__.py b/python/triton/spec/ascend/runtime/__init__.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/__init__.py rename to python/triton/spec/ascend/runtime/__init__.py diff --git a/third_party/ascend/backend/spec/triton/runtime/_allocation.py b/python/triton/spec/ascend/runtime/_allocation.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/_allocation.py rename to python/triton/spec/ascend/runtime/_allocation.py diff --git a/third_party/ascend/backend/spec/triton/runtime/_async_compile.py b/python/triton/spec/ascend/runtime/_async_compile.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/_async_compile.py rename to python/triton/spec/ascend/runtime/_async_compile.py diff --git a/third_party/ascend/backend/spec/triton/runtime/ascend_interpreter.py b/python/triton/spec/ascend/runtime/ascend_interpreter.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/ascend_interpreter.py rename to python/triton/spec/ascend/runtime/ascend_interpreter.py diff --git a/third_party/ascend/backend/spec/triton/runtime/autotuner.py b/python/triton/spec/ascend/runtime/autotuner.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/autotuner.py rename to python/triton/spec/ascend/runtime/autotuner.py diff --git a/third_party/ascend/backend/spec/triton/runtime/build.py b/python/triton/spec/ascend/runtime/build.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/build.py rename to python/triton/spec/ascend/runtime/build.py diff --git a/third_party/ascend/backend/spec/triton/runtime/code_cache.py b/python/triton/spec/ascend/runtime/code_cache.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/code_cache.py rename to python/triton/spec/ascend/runtime/code_cache.py diff --git a/third_party/ascend/backend/spec/triton/runtime/driver.py b/python/triton/spec/ascend/runtime/driver.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/driver.py rename to python/triton/spec/ascend/runtime/driver.py diff --git a/third_party/ascend/backend/spec/triton/runtime/errors.py b/python/triton/spec/ascend/runtime/errors.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/errors.py rename to python/triton/spec/ascend/runtime/errors.py diff --git a/third_party/ascend/backend/spec/triton/runtime/interpreter.py b/python/triton/spec/ascend/runtime/interpreter.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/interpreter.py rename to python/triton/spec/ascend/runtime/interpreter.py diff --git a/third_party/ascend/backend/spec/triton/runtime/jit.py b/python/triton/spec/ascend/runtime/jit.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/jit.py rename to python/triton/spec/ascend/runtime/jit.py diff --git a/third_party/ascend/backend/spec/triton/runtime/libentry.py b/python/triton/spec/ascend/runtime/libentry.py similarity index 100% rename from third_party/ascend/backend/spec/triton/runtime/libentry.py rename to python/triton/spec/ascend/runtime/libentry.py diff --git a/third_party/ascend/backend/spec/triton/tools/get_ascend_devices.py b/python/triton/spec/ascend/tools/get_ascend_devices.py similarity index 100% rename from third_party/ascend/backend/spec/triton/tools/get_ascend_devices.py rename to python/triton/spec/ascend/tools/get_ascend_devices.py diff --git a/third_party/ascend/backend/spec/__init__.py b/third_party/ascend/backend/spec/__init__.py deleted file mode 100644 index e9a5f27744..0000000000 --- a/third_party/ascend/backend/spec/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .triton.language import language_extend_globals From bc6ad505aa6482977c54c04faf17924cf78383d8 Mon Sep 17 00:00:00 2001 From: zhengyang Date: Thu, 18 Jun 2026 20:46:22 +0800 Subject: [PATCH 2/4] [CodeFormat] Fixed by pre-commit --- .../spec/ascend/compiler/code_generator.py | 1 - python/triton/spec/ascend/compiler/compiler.py | 2 +- .../ascend/extension/buffer/language/core.py | 4 ++-- .../ascend/extension/buffer/language/semantic.py | 2 +- python/triton/spec/ascend/language/semantic.py | 16 ++++++++-------- .../spec/ascend/runtime/ascend_interpreter.py | 2 +- python/triton/spec/ascend/runtime/autotuner.py | 5 ++--- python/triton/spec/ascend/runtime/interpreter.py | 4 ++-- python/triton/spec/ascend/runtime/libentry.py | 11 ----------- .../spec/ascend/tools/get_ascend_devices.py | 4 ++-- 10 files changed, 19 insertions(+), 32 deletions(-) diff --git a/python/triton/spec/ascend/compiler/code_generator.py b/python/triton/spec/ascend/compiler/code_generator.py index 066424ebf8..1294039830 100644 --- a/python/triton/spec/ascend/compiler/code_generator.py +++ b/python/triton/spec/ascend/compiler/code_generator.py @@ -13,7 +13,6 @@ from typing import Any, Callable, Dict, Optional, Tuple, Type, Union, Iterable, List import triton.language.extra.cann.extension as extension -from triton.extension.buffer.language import core as bl from triton.extension.buffer.language.builder import setup_unified_builder_with_buffer_builder from .. import knobs, language diff --git a/python/triton/spec/ascend/compiler/compiler.py b/python/triton/spec/ascend/compiler/compiler.py index 4d3df25ff8..505141ac91 100644 --- a/python/triton/spec/ascend/compiler/compiler.py +++ b/python/triton/spec/ascend/compiler/compiler.py @@ -8,7 +8,7 @@ from ..backends.compiler import BaseBackend, GPUTarget from .. import __version__, knobs from ..runtime.autotuner import OutOfResources -from ..runtime.cache import get_cache_manager, get_dump_manager, get_override_manager, get_cache_key, triton_key +from ..runtime.cache import get_cache_manager, get_dump_manager, get_override_manager, get_cache_key from ..runtime.driver import driver from ..tools.disasm import get_sass from .errors import MLIRCompilationError diff --git a/python/triton/spec/ascend/extension/buffer/language/core.py b/python/triton/spec/ascend/extension/buffer/language/core.py index 351c04e8d5..ad858aef47 100644 --- a/python/triton/spec/ascend/extension/buffer/language/core.py +++ b/python/triton/spec/ascend/extension/buffer/language/core.py @@ -260,7 +260,7 @@ def check_subview(src, offsets, sizes, strides): src_strides = [1] * length if length == 1: if offset[0] % base_byte != 0: - raise TypeError(f"all strides should be 1 and the offset value should be 32-bytes aligned.") + raise TypeError("all strides should be 1 and the offset value should be 32-bytes aligned.") return for i in range(length - 2, -1, -1): src_strides[i] = src_strides[i + 1] * src.shape[i + 1] @@ -276,7 +276,7 @@ def check_subview(src, offsets, sizes, strides): stride_1 = all(s == 1 for s in strides) is_unaligned = result_offset % base_byte != 0 or is_unaligned or not stride_1 if is_unaligned: - raise TypeError(f"all strides should be 1 and the offset value should be 32-bytes aligned.") + raise TypeError("all strides should be 1 and the offset value should be 32-bytes aligned.") @builtin diff --git a/python/triton/spec/ascend/extension/buffer/language/semantic.py b/python/triton/spec/ascend/extension/buffer/language/semantic.py index 277648e721..dcbabb709e 100644 --- a/python/triton/spec/ascend/extension/buffer/language/semantic.py +++ b/python/triton/spec/ascend/extension/buffer/language/semantic.py @@ -61,7 +61,7 @@ def to_buffer( if isinstance(bind_buffer, bl.buffer): builder.create_bind_buffer(tensor.handle, bind_buffer.handle) return bind_buffer - if not (bind_buffer is None): + if bind_buffer is not None: raise ValueError("bind_buffer must be a buffer or None") address_space = tl._unwrap_if_constexpr(address_space) addr_space_attr = (address_space.to_ir(builder) if address_space else builder.get_null_attr()) diff --git a/python/triton/spec/ascend/language/semantic.py b/python/triton/spec/ascend/language/semantic.py index 67549049bb..4b5ccb6cfb 100644 --- a/python/triton/spec/ascend/language/semantic.py +++ b/python/triton/spec/ascend/language/semantic.py @@ -515,7 +515,7 @@ def minus(self, input: TensorTy) -> TensorTy: input_sca_ty = input.type.scalar if hasattr(input, 'was_bool_to_int8'): if input.type.scalar.is_int8(): - raise TypeError(f"unexpected type bool") + raise TypeError("unexpected type bool") if input_sca_ty.is_ptr(): raise ValueError("wrong type argument to unary minus (" + input_sca_ty.__repr__() + ")") _0 = self.tensor(self.builder.get_null_value(input_sca_ty.to_ir(self.builder)), input_sca_ty) @@ -1633,13 +1633,13 @@ def dot_scaled(self, lhs: TensorTy, lhs_scale: TensorTy, lhs_format: str, rhs: T assert lhs.type.is_block() and rhs.type.is_block() if is_compile_on_910_95: assert lhs.dtype in [tl.float16, tl.bfloat16, tl.uint8, tl.float8e5, - tl.float8e4nv], f"lhs matrix dtype must be in [bf16, fp16, uint8, e5m2, e4m3]" + tl.float8e4nv], "lhs matrix dtype must be in [bf16, fp16, uint8, e5m2, e4m3]" assert rhs.dtype in [tl.float16, tl.bfloat16, tl.uint8, tl.float8e5, - tl.float8e4nv], f"rhs matrix dtype must be in [bf16, fp16, uint8, e5m2, e4m3]" + tl.float8e4nv], "rhs matrix dtype must be in [bf16, fp16, uint8, e5m2, e4m3]" else: - assert lhs.dtype == tl.bfloat16 or lhs.dtype == tl.float16, f"lhs matrix dtype must be bf16 or fp16" - assert rhs.dtype == tl.bfloat16 or lhs.dtype == tl.float16, f"rhs matrix dtype must be bf16 or fp16" - assert lhs.dtype == rhs.dtype, f"lhs rhs matrix must get same dtype" + assert lhs.dtype == tl.bfloat16 or lhs.dtype == tl.float16, "lhs matrix dtype must be bf16 or fp16" + assert rhs.dtype == tl.bfloat16 or lhs.dtype == tl.float16, "rhs matrix dtype must be bf16 or fp16" + assert lhs.dtype == rhs.dtype, "lhs rhs matrix must get same dtype" #TODO: validate types. lhs_rank = len(lhs.shape) rhs_rank = len(rhs.shape) @@ -1657,10 +1657,10 @@ def dot_scaled(self, lhs: TensorTy, lhs_scale: TensorTy, lhs_format: str, rhs: T rhs_scale_is_none = rhs_scale is None or (isinstance(rhs_scale, tl.constexpr) and rhs_scale.value is None) lhs_scale_is_none = lhs_scale is None or (isinstance(lhs_scale, tl.constexpr) and lhs_scale.value is None) assert isinstance(lhs_scale, tl.tensor) and (lhs_scale.dtype == tl.int8 or lhs_scale.dtype - == tl.uint8), f"lhs_scale must be int8 or uint8 tensor" + == tl.uint8), "lhs_scale must be int8 or uint8 tensor" if not rhs_scale_is_none: assert isinstance(rhs_scale, tl.tensor) and (rhs_scale.dtype == tl.int8 or rhs_scale.dtype - == tl.uint8), f"rhs_scale must be int8 or uint8 tensor" + == tl.uint8), "rhs_scale must be int8 or uint8 tensor" lhs = self._bitcast_to_fp_type(lhs, lhs_format) rhs = self._bitcast_to_fp_type(rhs, rhs_format) assert lhs_k_pack or lhs_format == "e2m1", "only mxfp4 inputs can be packed along a dimension different than K" diff --git a/python/triton/spec/ascend/runtime/ascend_interpreter.py b/python/triton/spec/ascend/runtime/ascend_interpreter.py index 9482e57ca7..2dcefcfe4d 100644 --- a/python/triton/spec/ascend/runtime/ascend_interpreter.py +++ b/python/triton/spec/ascend/runtime/ascend_interpreter.py @@ -730,7 +730,7 @@ def get_i64_array_attr(self, val): def create_annotation_mark(self, ptr_data, hint_name: str, hint_val): if hint_name == "overflow_mode": - raise ValueError(f"overflow_mode is not supported in interpreter mode, may have accuracy issues") + raise ValueError("overflow_mode is not supported in interpreter mode, may have accuracy issues") else: warnings.warn(f"compile_hint '{hint_name}' is not supported in interpreter mode, just pass it", UserWarning, stacklevel=2) diff --git a/python/triton/spec/ascend/runtime/autotuner.py b/python/triton/spec/ascend/runtime/autotuner.py index cb419b2461..223eedf9cf 100644 --- a/python/triton/spec/ascend/runtime/autotuner.py +++ b/python/triton/spec/ascend/runtime/autotuner.py @@ -6,13 +6,12 @@ import hashlib import json from functools import cached_property -import itertools -from typing import Any, Dict, Tuple, List, Optional, List +from typing import Dict, Tuple, Optional, List from .. import knobs from .jit import KernelInterface, JITFunction -from .errors import OutOfResources, PTXASError +from .errors import OutOfResources from .driver import driver from .cache import get_cache_manager, triton_key from triton._C.libtriton import get_cache_invalidating_env_vars diff --git a/python/triton/spec/ascend/runtime/interpreter.py b/python/triton/spec/ascend/runtime/interpreter.py index 36065e02f6..52341a24d4 100644 --- a/python/triton/spec/ascend/runtime/interpreter.py +++ b/python/triton/spec/ascend/runtime/interpreter.py @@ -30,10 +30,10 @@ def _try_import_ascend(): from . import ascend_interpreter AscendInterpreterBuilder = ascend_interpreter.AscendInterpreterBuilder _has_ascend_support = True - except ImportError as e: + except ImportError: _has_ascend_support = False AscendInterpreterBuilder = None - except Exception as e: + except Exception: # Catch other exceptions (like circular import) and log them _has_ascend_support = False AscendInterpreterBuilder = None diff --git a/python/triton/spec/ascend/runtime/libentry.py b/python/triton/spec/ascend/runtime/libentry.py index d360ab15b3..2281111b45 100644 --- a/python/triton/spec/ascend/runtime/libentry.py +++ b/python/triton/spec/ascend/runtime/libentry.py @@ -33,23 +33,12 @@ import ast from collections import OrderedDict from typing import ( - Any, - Callable, Dict, - Final, - Iterator, - List, Optional, - Tuple, - Type, - Union, - overload, ) import triton -from triton._C import libentryC import torch -import torch_npu torch_device_fn = torch.npu diff --git a/python/triton/spec/ascend/tools/get_ascend_devices.py b/python/triton/spec/ascend/tools/get_ascend_devices.py index 49b5511af2..f6ba1c9c01 100644 --- a/python/triton/spec/ascend/tools/get_ascend_devices.py +++ b/python/triton/spec/ascend/tools/get_ascend_devices.py @@ -38,8 +38,8 @@ def check_npu_smi_device(): output = result.stdout.lower() return "ascend910_95" in output or "ascend950" in output or "910_958b" in output return False - except Exception as e: - logger.warning(f"can not use command: npu-smi info") + except Exception: + logger.warning("can not use command: npu-smi info") return False From f1ab8997215558210c6d122f2acc736dfaf2c66e Mon Sep 17 00:00:00 2001 From: zhengyang Date: Thu, 18 Jun 2026 20:59:52 +0800 Subject: [PATCH 3/4] [CodeFormat] Fixed by noqa --- python/triton/spec/ascend/compiler/code_generator.py | 6 +++--- python/triton/spec/ascend/extension/buffer/language/core.py | 2 +- python/triton/spec/ascend/language/semantic.py | 4 ++-- python/triton/spec/ascend/runtime/ascend_interpreter.py | 6 +++--- python/triton/spec/ascend/runtime/libentry.py | 3 ++- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/python/triton/spec/ascend/compiler/code_generator.py b/python/triton/spec/ascend/compiler/code_generator.py index 1294039830..5cb773d9ac 100644 --- a/python/triton/spec/ascend/compiler/code_generator.py +++ b/python/triton/spec/ascend/compiler/code_generator.py @@ -38,8 +38,8 @@ def check_identifier_legality(name, type): WITH_DISPATCH = {} # Import and register Ascend extension dispatch handlers -from triton.language.extra.cann.extension.dispatch import ASCEND_WITH_DISPATCH -from triton.language.extra.cann.extension.builder import setup_unified_builder +from triton.language.extra.cann.extension.dispatch import ASCEND_WITH_DISPATCH # noqa: E402 +from triton.language.extra.cann.extension.builder import setup_unified_builder # noqa: E402 WITH_DISPATCH.update(ASCEND_WITH_DISPATCH) @@ -1205,7 +1205,7 @@ def visit_For(self, node): warp_specialize = iterator.warp_specialize disable_licm = iterator.disable_licm if (IteratorClass is extension.parallel): - bind_sub_block = iterator.bind_sub_block + bind_sub_block = iterator.bind_sub_block # noqa: F841 elif IteratorClass is range: # visit iterator arguments # note: only `range` iterator is supported now diff --git a/python/triton/spec/ascend/extension/buffer/language/core.py b/python/triton/spec/ascend/extension/buffer/language/core.py index ad858aef47..d170561813 100644 --- a/python/triton/spec/ascend/extension/buffer/language/core.py +++ b/python/triton/spec/ascend/extension/buffer/language/core.py @@ -259,7 +259,7 @@ def check_subview(src, offsets, sizes, strides): length = len(strides) src_strides = [1] * length if length == 1: - if offset[0] % base_byte != 0: + if offset[0] % base_byte != 0: # noqa: F821 raise TypeError("all strides should be 1 and the offset value should be 32-bytes aligned.") return for i in range(length - 2, -1, -1): diff --git a/python/triton/spec/ascend/language/semantic.py b/python/triton/spec/ascend/language/semantic.py index 4b5ccb6cfb..1c43eef24c 100644 --- a/python/triton/spec/ascend/language/semantic.py +++ b/python/triton/spec/ascend/language/semantic.py @@ -1091,7 +1091,7 @@ def _load_legacy(self, ptr, mask, other, boundary_check, padding, cache, evictio "pointers or loading a scalar. Because the compiler does not know the boundary; please " "use block pointers (defined by `make_block_ptr`) instead") - if mask is not None and other is None and care_padding == True: + if mask is not None and other is None and care_padding == True: # noqa: E712 # Get element type to determine default padding value elt_ty = ptr.type.scalar.element_ty # Use 0.0 for floating point types, 0 for integer types @@ -1583,7 +1583,7 @@ def dot(self, lhs: TensorTy, rhs: TensorTy, acc: TensorTy, input_precision: Opti M = lhs.type.shape[-2] N = rhs.type.shape[-1] - K = lhs.type.shape[-1] + K = lhs.type.shape[-1] # noqa: F841 B = lhs.type.shape[0] if lhs_rank == 3 else None ret_ty = tl.block_type(ret_scalar_ty, [B, M, N] if B else [M, N]) if acc is None: diff --git a/python/triton/spec/ascend/runtime/ascend_interpreter.py b/python/triton/spec/ascend/runtime/ascend_interpreter.py index 2dcefcfe4d..d159b8421a 100644 --- a/python/triton/spec/ascend/runtime/ascend_interpreter.py +++ b/python/triton/spec/ascend/runtime/ascend_interpreter.py @@ -534,7 +534,7 @@ def create_gather_out_to_ub(self, src_ptr, index_tensor, index_boundary, dim, sr # Convert src_stride, start_offset, end_offset to integers src_stride_vals = [self.to_int_val(s) for s in src_stride] start_offset_vals = [self.to_int_val(s) for s in start_offset] - end_offset_vals = [self.to_int_val(s) for s in end_offset] + end_offset_vals = [self.to_int_val(s) for s in end_offset] # noqa: F841 # Element type dtype_tt = src_ptr.get_element_ty() @@ -604,7 +604,7 @@ def create_scatter_ub_to_out(self, dst_ptr, value_tensor, index_tensor, index_bo # Convert dst_stride, start_offset, end_offset to integers dst_stride_vals = [self.to_int_val(s) for s in dst_stride] start_offset_vals = [self.to_int_val(s) for s in start_offset] - end_offset_vals = [self.to_int_val(s) for s in end_offset] + end_offset_vals = [self.to_int_val(s) for s in end_offset] # noqa: F841 # Element type dtype_tt = dst_ptr.get_element_ty() @@ -616,7 +616,7 @@ def create_scatter_ub_to_out(self, dst_ptr, value_tensor, index_tensor, index_bo index_rank = len(index_shape) total_elements = np.prod(index_shape) flat_values = value_tensor.data.flatten() - flat_indices = index_tensor.data.flatten() + flat_indices = index_tensor.data.flatten() # noqa: F841 # Generate coordinates all_coords = [] diff --git a/python/triton/spec/ascend/runtime/libentry.py b/python/triton/spec/ascend/runtime/libentry.py index 2281111b45..7c1b2fe73a 100644 --- a/python/triton/spec/ascend/runtime/libentry.py +++ b/python/triton/spec/ascend/runtime/libentry.py @@ -39,10 +39,11 @@ import triton import torch +import torch_npu # noqa: F401 torch_device_fn = torch.npu -from .code_cache import config_cache_dir +from .code_cache import config_cache_dir # noqa: E402 DEVICE_COUNT = torch_device_fn.device_count() version = triton.__version__.split(".") From 824bf546ea1d50e5defc5141da7d97e0cd46d86d Mon Sep 17 00:00:00 2001 From: zhengyang Date: Mon, 22 Jun 2026 23:16:11 +0800 Subject: [PATCH 4/4] [SPEC] Fix spec module --- python/triton/flagtree_spec.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/python/triton/flagtree_spec.py b/python/triton/flagtree_spec.py index 578a737932..f32ab10dfc 100644 --- a/python/triton/flagtree_spec.py +++ b/python/triton/flagtree_spec.py @@ -16,18 +16,12 @@ def _triton_root() -> str | None: def _get_spec_module(): global _spec_module from ._flagtree_backend import FLAGTREE_BACKEND - if not FLAGTREE_BACKEND: - return None - triton_root = _triton_root() - if triton_root is None: - return None - spec_dir = os.path.join(triton_root, "backends", FLAGTREE_BACKEND, "spec") - if not os.path.isdir(spec_dir): - return None if _spec_module is not None: return _spec_module + if not FLAGTREE_BACKEND: + return None try: - _spec_module = importlib.import_module(f"triton.backends.{FLAGTREE_BACKEND}.spec") + _spec_module = importlib.import_module(f"triton.spec.{FLAGTREE_BACKEND}") except ImportError: return None return _spec_module