[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7984W6SW3BZM5EXGRJ1VBXY":3,"skill-same:01M7984W6SW3BZM5EXGRJ1VBXY":43},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":13,"repositoryHtmlUrl":26,"repositoryHomepageUrl":6,"ownerHtmlUrl":27,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":28,"install":29,"resources":42},"01M7984W6SW3BZM5EXGRJ1VBXY","triton-npu-convert-pytorch-operator",null,"Convert one PyTorch operator into a Triton NPU-backed PyTorch operator, preserve the trailing input-helper block, and validate the converted output through standalone or differential testing.","Piagari\u002Fhelix","Piagari","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F129916910?v=4","01M7980QB9Y8WK5TSSRJDC7H1X","01M7980QCA2FWSBBSSM695Y10B",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix\u002Fblob\u002Fmain\u002Fskills\u002Ftriton\u002Ftriton-npu-convert-pytorch-operator\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: triton-npu-convert-pytorch-operator\ndescription: Convert one PyTorch operator into a Triton NPU-backed PyTorch operator, preserve the trailing input-helper block, and validate the converted output through standalone or differential testing.\n---\n\n# Convert PyTorch Operator\n\nConvert one PyTorch operator file into a PyTorch-facing operator backed by a real Triton Ascend NPU kernel path.\n\nUse this skill when the user wants a new converted operator artifact instead of an in-place optimize round.\n\n## Inputs\n\n- one original PyTorch operator file\n- one requested output path for the converted operator\n- one requested standalone or differential test mode\n- optional remote execution context from the outer task\n\n## Outputs\n\n- one converted operator file, usually named `triton_\u003Corigin-name>.py`\n- preserved trailing input-helper block in the converted output\n- one generated standalone or differential test file for the converted output\n- a short summary of what was converted, what remained unchanged, and any blockers\n\n## Core Constraints\n\n- Treat the original input operator file as immutable source material and, for differential validation, the correctness oracle.\n- Do not modify, or overwrite the original input operator file.\n- Keep the public API PyTorch-facing when needed, but keep the converted computation on a real Triton Ascend NPU kernel path.\n- Target Ascend NPU only for this conversion flow; do not add CUDA, CPU, MPS, or generic multi-backend fallback logic unless the source file already requires shared import structure around the public API.\n- Do not introduce unnecessary wrappers, compatibility branches, helper layers, or standalone or differential test code inside the converted operator file.\n\n## Required Workflow\n\n1. Read the original operator file carefully before editing anything, and identify the public PyTorch entrypoint that should remain visible after conversion.\n2. Write the converted operator to the requested output path. Keep the delivered result PyTorch-facing when needed, but move the converted computation onto a real Triton Ascend NPU kernel path. You may replace some operators, leave some unchanged, fuse operations, or make targeted algorithmic changes when that helps the Triton NPU path.\n3. Preserve the trailing input-helper block from the source file in the converted output because later harness generation and validation may need it.\n4. Validate the converted output with the requested standalone or differential mode by following the validation flow below.\n5. Finish only after validation passes or a clear environment blocker prevents further progress.\n\n## Validation Flow\n\n1. If a suitable test already exists in the operator workspace, reuse it. This includes existing standalone and differential test cases when they already cover the operator workspace.\n2. Do not create a new test when an existing suitable test can be reused unless the user explicitly asks to regenerate it.\n3. When no suitable reusable test exists, use `ascend-npu-gen-test` to generate a test for the converted output.\n4. Use the original input operator as the reference implementation when the requested mode is differential, and use the converted output as the system under test in all cases.\n5. Use `ascend-npu-run-eval` to execute validation — run `run-test-convert` for both standalone and differential convert validation as prescribed by the skill. The command output must contain `PASS:` for validation to be considered successful. See \"Validation Enforcement Rules\" below for the complete set of mandatory validation constraints.\n6. If the converted output hits Triton compile, JIT, launch, or kernel-structure errors, use `triton-npu-repair-guide` for operator-side repair heuristics and then re-run validation.\n\n## Validation Enforcement Rules\n\nCorrectness validation is **not advisory** — it is the final gate before conversion is considered complete. The following rules are mandatory and non-negotiable.\n\n### Mandatory Validation Commands\n\nYou MUST use the validation commands prescribed by the `ascend-npu-run-eval` skill:\n\n- **Differential mode**: `cli.py run-test-convert` with `--ref-operator-file \u003Coriginal>`\n- **Standalone mode**: `cli.py run-test-convert`\n\nThese commands handle result archiving, `TRITON_ALWAYS_COMPILE`, NPU synchronization, and comparison — all of which you cannot replicate reliably with ad-hoc scripting.\n\n### Forbidden Validation Practices\n\nThe following self-validation patterns are **strictly forbidden**. Violating any of these means the conversion is incomplete, regardless of what other checks you believe have passed.\n\n| Forbidden | Example | Why |\n|-----------|---------|-----|\n| Ad-hoc `python3 -c \"import torch; ...\"` comparison scripts | `python3 -c \"import torch; ref=torch.load(...); torch.allclose(...)\"` | Bypasses the standard `compare_result.py` and its audited tolerance levels |\n| Using `torch.allclose` \u002F `torch.testing.assert_close` with custom tolerances | `torch.allclose(a, b, rtol=1e-5, atol=1e-8)` | Tolerances different from the NPU accuracy contract thresholds may mask real errors or produce false positives |\n| Running a differential test file directly with `python3` instead of through `cli.py` | `python3 differential_test_xxx.py --operator-file xxx` | Bypasses result archiving, `TRITON_ALWAYS_COMPILE`, synchronization, and comparison logic |\n| Generating and comparing custom `.pt` files on your own | `torch.save(ref, \"REFERENCE_RESULT.pt\")` then manual compare | Creates files that may interfere with the CLI validation loop and use inconsistent formats |\n| Self-declaring \"PASS\" based on your own comparison logic | \"PASS: Minor 1-ULP differences only (expected for cross-implementation)\" | Only `run-test-convert` output determines pass\u002Ffail |\n\n### What \"PASS\" Means\n\n- The literal output `PASS: all N case(s) matched the NPU accuracy contract.` (or per-case `PASS case '...' matched ...`) — differential mode conversion is definitively validated\n- The literal output `All tests passed!` or matching `All tests passed!` in the command output — standalone mode has passed\n- ANY other output (including `FAIL:`, Python exceptions, or empty output) — conversion has NOT passed\n- If the command does not print `PASS:` or `All tests passed!`, do NOT declare success. Instead, use the failure output to diagnose and fix the kernel, then re-run the same validation command.\n\n## Converted Example\n\nUse a real converted output example in the generated file, not only a prose description. For a simple elementwise add conversion, a converted output may look like this:\n\n```python\nimport torch\nimport torch.nn as nn\nimport triton\nimport triton.language as tl\n\n\n@triton.jit\ndef add_kernel(\n    x_ptr,\n    y_ptr,\n    out_ptr,\n    n_elements,\n    BLOCK_SIZE: tl.constexpr,\n):\n    block_start = tl.program_id(0) * BLOCK_SIZE\n    offsets = block_start + tl.arange(0, BLOCK_SIZE)\n    mask = offsets \u003C n_elements\n    x = tl.load(x_ptr + offsets, mask=mask, other=0.0)\n    y = tl.load(y_ptr + offsets, mask=mask, other=0.0)\n    out = x + y\n    tl.store(out_ptr + offsets, out, mask=mask)\n\n\ndef triton_add(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:\n    x = x.contiguous()\n    y = y.contiguous()\n    out = torch.empty_like(x)\n    n_elements = out.numel()\n    grid = lambda meta: ((n_elements + meta[\"BLOCK_SIZE\"] - 1) \u002F\u002F meta[\"BLOCK_SIZE\"],)\n    add_kernel[grid](x, y, out, n_elements, BLOCK_SIZE=128)\n    return out\n\n\nclass Model(nn.Module):\n    def __init__(self) -> None:\n        super().__init__()\n\n    def forward(self, a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:\n        return triton_add(a, b)\n\n\nN = 2048\n\n\ndef get_inputs():\n    a = torch.randn(N, N, device=\"npu\")\n    b = torch.randn(N, N, device=\"npu\")\n    return [a, b]\n\n\ndef get_init_inputs():\n    return []\n```\n\nIn this kind of conversion:\n\n- `def triton_add(...)` is the PyTorch-facing wrapper that calls the Triton kernel\n- `class Model` is the converted public architecture\n- the trailing `get_init_inputs()` \u002F `get_inputs()` block is preserved in the converted output instead of being dropped\n- the original source operator remains the correctness oracle for differential validation\n\n## Forward Method Constraints\n\nThe converted operator **must** be a pure Triton Ascend implementation. The `forward()` method may only allocate buffers and launch kernels — all computation must happen inside `@triton.jit` kernels.\n\n### Forbidden in forward()\n\n| Category | Examples | Reason |\n|----------|----------|--------|\n| `torch` compute functions | `torch.matmul(x, w)`, `torch.relu(x)`, `torch.sum(x)` | Must be inside a `@triton.jit` kernel |\n| `torch.nn.functional` | `F.softmax(x, dim=-1)`, `F.linear(x, w)`, `F.relu(x)` | Must be inside a `@triton.jit` kernel |\n| tensor method compute | `x.sum()`, `x.mean()`, `x.softmax(dim=-1)`, `x.relu()` | Must be inside a `@triton.jit` kernel |\n| tensor operators | `x @ w`, `x + y`, `x * y`, `x \u002F y` | Must be inside a `@triton.jit` kernel |\n| `nn.Module` calls | `self.conv(x)`, `self.linear(x)`, `self.layer(x)` | Must be inside a `@triton.jit` kernel |\n\n### Allowed in forward()\n\n| Category | Examples | Purpose |\n|----------|----------|---------|\n| buffer alloc | `torch.empty(shape)`, `torch.zeros(shape)`, `torch.ones(shape)` | Allocate output for kernel |\n| shape ops | `x.view(...)`, `x.reshape(...)`, `x.permute(...)`, `x.transpose(...)` | No compute involved |\n| metadata | `x.shape`, `x.dtype`, `x.device`, `x.numel()` | Needed for grid calculation |\n| kernel launch | `kernel[grid](...args)` | Call a custom `@triton.jit` kernel |\n\n### Anti-Patterns (These Fail Conversion)\n\n**1. Fully PyTorch — no kernel at all**\n```python\n# Forbidden: pure PyTorch, no Triton kernel\ndef forward(self, x, w):\n    return torch.matmul(x, w)\n```\n\n**2. Kernel defined but never called**\n```python\n@triton.jit\ndef matmul_kernel(...):\n    pass\n\ndef forward(self, x, w):\n    return torch.matmul(x, w)  # Forbidden: kernel defined but unused\n```\n\n**3. Mixed: partial kernel + partial torch**\n```python\ndef forward(self, x, w):\n    y = self.kernel[grid](x, w)\n    return y.sum(dim=-1)  # Forbidden: tensor method compute after kernel\n```\n\n**4. Tensor operators in forward**\n```python\ndef forward(self, x, w):\n    y = self.kernel[grid](x, w)\n    return y + 1  # Forbidden: + is a PyTorch operator\n```\n\n### Correct Pattern\n\n```python\n@triton.jit\ndef add_kernel(x_ptr, y_ptr, output_ptr, n, BLOCK_SIZE: tl.constexpr):\n    idx = tl.arange(0, BLOCK_SIZE)\n    x = tl.load(x_ptr + idx)\n    y = tl.load(y_ptr + idx)\n    output = x + y  # compute inside kernel\n    tl.store(output_ptr + idx, output)\n\nclass Model(nn.Module):\n    def forward(self, x, y):\n        output = torch.empty_like(x)  # Allowed: buffer alloc\n        add_kernel[(1,)](x, y, output, x.numel(), BLOCK_SIZE=128)  # Allowed: kernel launch\n        return output  # Allowed: return kernel output\n```\n\n## Quality Rules\n\n- Keep the delivered output as a real Triton NPU-backed implementation, not a pure PyTorch fallback. A pure PyTorch rewrite does not satisfy this convert task, even if differential tests pass.\n- Do not introduce unnecessary code.\n- Keep the converted file runnable as a PyTorch-facing operator artifact.\n- Prefer targeted conversion over unrelated refactoring.\n- Use the requested standalone or differential correctness validation mode instead of inventing a third validation workflow here.\n- Input validation in the converted operator must limit itself to zero-cost metadata checks (`.dtype`, `.ndim`, `.device`, `.shape`, `.numel()`). Never scan tensor data for bounds or value-range validation — calling `.min().item()`, `.max().item()`, or any reduction+`.item()` on input tensors forces a GPU→CPU synchronization on every forward call and destroys performance. The caller is responsible for providing valid inputs, just as it is for the original PyTorch operator.\n\n## Do Not\n\n- Do not call `optimize` or create `opt-round-*` directories from this workflow.\n- Do not create `baseline\u002F` or any optimize-session artifacts from this workflow.\n- Do not replace the converted Triton kernel path with pure PyTorch just to get validation green.\n- Do not create input-validation helpers (e.g., `_validate_index`, `_check_bounds`, `_assert_indices`, or similarly-named functions) that scan tensor data. Specifically, never call `.min().item()`, `.max().item()`, `.sum().item()`, or any reduction followed by `.item()` on GPU\u002FNPU tensors before launching a kernel. These force a full-tensor GPU→CPU synchronization on every forward call. The converted operator inherits the same input contract as the original PyTorch operator — if the caller passes out-of-bounds indices, that is a caller bug, not something the conversion must guard against.\n- Do not submit a pure PyTorch rewrite as the converted result, even when the wrapper signature or standalone or differential outputs still look correct.\n- Do not write your own comparison script (e.g., `python3 -c \"import torch; ...\"`) to compare result `.pt` files or operator outputs.\n- Do not use `torch.allclose`, `torch.testing.assert_close`, `torch.equal`, or any other numerical comparison function with custom tolerances to validate conversion correctness — always use `run-test-convert` from the `ascend-npu-run-eval` skill.\n- Do not self-declare the conversion as \"PASS\" based on your own tolerance analysis — only the printed output of `run-test-convert` determines success.\n- Do not run differential test files directly with `python3` — always use `cli.py run-test-convert`.\n- Do not save custom `.pt` files (e.g., `REFERENCE_RESULT.pt`, `COMPARE_RESULT.pt`) for manual comparison — this may interfere with the CLI validation loop's result caching.\n","# Convert PyTorch Operator\n\nConvert one PyTorch operator file into a PyTorch-facing operator backed by a real Triton Ascend NPU kernel path.\n\nUse this skill when the user wants a new converted operator artifact instead of an in-place optimize round.\n\n## Inputs\n\n- one original PyTorch operator file\n- one requested output path for the converted operator\n- one requested standalone or differential test mode\n- optional remote execution context from the outer task\n\n## Outputs\n\n- one converted operator file, usually named `triton_\u003Corigin-name>.py`\n- preserved trailing input-helper block in the converted output\n- one generated standalone or differential test file for the converted output\n- a short summary of what was converted, what remained unchanged, and any blockers\n\n## Core Constraints\n\n- Treat the original input operator file as immutable source material and, for differential validation, the correctness oracle.\n- Do not modify, or overwrite the original input operator file.\n- Keep the public API PyTorch-facing when needed, but keep the converted computation on a real Triton Ascend NPU kernel path.\n- Target Ascend NPU only for this conversion flow; do not add CUDA, CPU, MPS, or generic multi-backend fallback logic unless the source file already requires shared import structure around the public API.\n- Do not introduce unnecessary wrappers, compatibility branches, helper layers, or standalone or differential test code inside the converted operator file.\n\n## Required Workflow\n\n1. Read the original operator file carefully before editing anything, and identify the public PyTorch entrypoint that should remain visible after conversion.\n2. Write the converted operator to the requested output path. Keep the delivered result PyTorch-facing when needed, but move the converted computation onto a real Triton Ascend NPU kernel path. You may replace some operators, leave some unchanged, fuse operations, or make targeted algorithmic changes when that helps the Triton NPU path.\n3. Preserve the trailing input-helper block from the source file in the converted output because later harness generation and validation may need it.\n4. Validate the converted output with the requested standalone or differential mode by following the validation flow below.\n5. Finish only after validation passes or a clear environment blocker prevents further progress.\n\n## Validation Flow\n\n1. If a suitable test already exists in the operator workspace, reuse it. This includes existing standalone and differential test cases when they already cover the operator workspace.\n2. Do not create a new test when an existing suitable test can be reused unless the user explicitly asks to regenerate it.\n3. When no suitable reusable test exists, use `ascend-npu-gen-test` to generate a test for the converted output.\n4. Use the original input operator as the reference implementation when the requested mode is differential, and use the converted output as the system under test in all cases.\n5. Use `ascend-npu-run-eval` to execute validation — run `run-test-convert` for both standalone and differential convert validation as prescribed by the skill. The command output must contain `PASS:` for validation to be considered successful. See \"Validation Enforcement Rules\" below for the complete set of mandatory validation constraints.\n6. If the converted output hits Triton compile, JIT, launch, or kernel-structure errors, use `triton-npu-repair-guide` for operator-side repair heuristics and then re-run validation.\n\n## Validation Enforcement Rules\n\nCorrectness validation is **not advisory** — it is the final gate before conversion is considered complete. The following rules are mandatory and non-negotiable.\n\n### Mandatory Validation Commands\n\nYou MUST use the validation commands prescribed by the `ascend-npu-run-eval` skill:\n\n- **Differential mode**: `cli.py run-test-convert` with `--ref-operator-file \u003Coriginal>`\n- **Standalone mode**: `cli.py run-test-convert`\n\nThese commands handle result archiving, `TRITON_ALWAYS_COMPILE`, NPU synchronization, and comparison — all of which you cannot replicate reliably with ad-hoc scripting.\n\n### Forbidden Validation Practices\n\nThe following self-validation patterns are **strictly forbidden**. Violating any of these means the conversion is incomplete, regardless of what other checks you believe have passed.\n\n| Forbidden | Example | Why |\n|-----------|---------|-----|\n| Ad-hoc `python3 -c \"import torch; ...\"` comparison scripts | `python3 -c \"import torch; ref=torch.load(...); torch.allclose(...)\"` | Bypasses the standard `compare_result.py` and its audited tolerance levels |\n| Using `torch.allclose` \u002F `torch.testing.assert_close` with custom tolerances | `torch.allclose(a, b, rtol=1e-5, atol=1e-8)` | Tolerances different from the NPU accuracy contract thresholds may mask real errors or produce false positives |\n| Running a differential test file directly with `python3` instead of through `cli.py` | `python3 differential_test_xxx.py --operator-file xxx` | Bypasses result archiving, `TRITON_ALWAYS_COMPILE`, synchronization, and comparison logic |\n| Generating and comparing custom `.pt` files on your own | `torch.save(ref, \"REFERENCE_RESULT.pt\")` then manual compare | Creates files that may interfere with the CLI validation loop and use inconsistent formats |\n| Self-declaring \"PASS\" based on your own comparison logic | \"PASS: Minor 1-ULP differences only (expected for cross-implementation)\" | Only `run-test-convert` output determines pass\u002Ffail |\n\n### What \"PASS\" Means\n\n- The literal output `PASS: all N case(s) matched the NPU accuracy contract.` (or per-case `PASS case '...' matched ...`) — differential mode conversion is definitively validated\n- The literal output `All tests passed!` or matching `All tests passed!` in the command output — standalone mode has passed\n- ANY other output (including `FAIL:`, Python exceptions, or empty output) — conversion has NOT passed\n- If the command does not print `PASS:` or `All tests passed!`, do NOT declare success. Instead, use the failure output to diagnose and fix the kernel, then re-run the same validation command.\n\n## Converted Example\n\nUse a real converted output example in the generated file, not only a prose description. For a simple elementwise add conversion, a converted output may look like this:\n\n```python\nimport torch\nimport torch.nn as nn\nimport triton\nimport triton.language as tl\n\n\n@triton.jit\ndef add_kernel(\n    x_ptr,\n    y_ptr,\n    out_ptr,\n    n_elements,\n    BLOCK_SIZE: tl.constexpr,\n):\n    block_start = tl.program_id(0) * BLOCK_SIZE\n    offsets = block_start + tl.arange(0, BLOCK_SIZE)\n    mask = offsets \u003C n_elements\n    x = tl.load(x_ptr + offsets, mask=mask, other=0.0)\n    y = tl.load(y_ptr + offsets, mask=mask, other=0.0)\n    out = x + y\n    tl.store(out_ptr + offsets, out, mask=mask)\n\n\ndef triton_add(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:\n    x = x.contiguous()\n    y = y.contiguous()\n    out = torch.empty_like(x)\n    n_elements = out.numel()\n    grid = lambda meta: ((n_elements + meta[\"BLOCK_SIZE\"] - 1) \u002F\u002F meta[\"BLOCK_SIZE\"],)\n    add_kernel[grid](x, y, out, n_elements, BLOCK_SIZE=128)\n    return out\n\n\nclass Model(nn.Module):\n    def __init__(self) -> None:\n        super().__init__()\n\n    def forward(self, a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:\n        return triton_add(a, b)\n\n\nN = 2048\n\n\ndef get_inputs():\n    a = torch.randn(N, N, device=\"npu\")\n    b = torch.randn(N, N, device=\"npu\")\n    return [a, b]\n\n\ndef get_init_inputs():\n    return []\n```\n\nIn this kind of conversion:\n\n- `def triton_add(...)` is the PyTorch-facing wrapper that calls the Triton kernel\n- `class Model` is the converted public architecture\n- the trailing `get_init_inputs()` \u002F `get_inputs()` block is preserved in the converted output instead of being dropped\n- the original source operator remains the correctness oracle for differential validation\n\n## Forward Method Constraints\n\nThe converted operator **must** be a pure Triton Ascend implementation. The `forward()` method may only allocate buffers and launch kernels — all computation must happen inside `@triton.jit` kernels.\n\n### Forbidden in forward()\n\n| Category | Examples | Reason |\n|----------|----------|--------|\n| `torch` compute functions | `torch.matmul(x, w)`, `torch.relu(x)`, `torch.sum(x)` | Must be inside a `@triton.jit` kernel |\n| `torch.nn.functional` | `F.softmax(x, dim=-1)`, `F.linear(x, w)`, `F.relu(x)` | Must be inside a `@triton.jit` kernel |\n| tensor method compute | `x.sum()`, `x.mean()`, `x.softmax(dim=-1)`, `x.relu()` | Must be inside a `@triton.jit` kernel |\n| tensor operators | `x @ w`, `x + y`, `x * y`, `x \u002F y` | Must be inside a `@triton.jit` kernel |\n| `nn.Module` calls | `self.conv(x)`, `self.linear(x)`, `self.layer(x)` | Must be inside a `@triton.jit` kernel |\n\n### Allowed in forward()\n\n| Category | Examples | Purpose |\n|----------|----------|---------|\n| buffer alloc | `torch.empty(shape)`, `torch.zeros(shape)`, `torch.ones(shape)` | Allocate output for kernel |\n| shape ops | `x.view(...)`, `x.reshape(...)`, `x.permute(...)`, `x.transpose(...)` | No compute involved |\n| metadata | `x.shape`, `x.dtype`, `x.device`, `x.numel()` | Needed for grid calculation |\n| kernel launch | `kernel[grid](...args)` | Call a custom `@triton.jit` kernel |\n\n### Anti-Patterns (These Fail Conversion)\n\n**1. Fully PyTorch — no kernel at all**\n```python\n# Forbidden: pure PyTorch, no Triton kernel\ndef forward(self, x, w):\n    return torch.matmul(x, w)\n```\n\n**2. Kernel defined but never called**\n```python\n@triton.jit\ndef matmul_kernel(...):\n    pass\n\ndef forward(self, x, w):\n    return torch.matmul(x, w)  # Forbidden: kernel defined but unused\n```\n\n**3. Mixed: partial kernel + partial torch**\n```python\ndef forward(self, x, w):\n    y = self.kernel[grid](x, w)\n    return y.sum(dim=-1)  # Forbidden: tensor method compute after kernel\n```\n\n**4. Tensor operators in forward**\n```python\ndef forward(self, x, w):\n    y = self.kernel[grid](x, w)\n    return y + 1  # Forbidden: + is a PyTorch operator\n```\n\n### Correct Pattern\n\n```python\n@triton.jit\ndef add_kernel(x_ptr, y_ptr, output_ptr, n, BLOCK_SIZE: tl.constexpr):\n    idx = tl.arange(0, BLOCK_SIZE)\n    x = tl.load(x_ptr + idx)\n    y = tl.load(y_ptr + idx)\n    output = x + y  # compute inside kernel\n    tl.store(output_ptr + idx, output)\n\nclass Model(nn.Module):\n    def forward(self, x, y):\n        output = torch.empty_like(x)  # Allowed: buffer alloc\n        add_kernel[(1,)](x, y, output, x.numel(), BLOCK_SIZE=128)  # Allowed: kernel launch\n        return output  # Allowed: return kernel output\n```\n\n## Quality Rules\n\n- Keep the delivered output as a real Triton NPU-backed implementation, not a pure PyTorch fallback. A pure PyTorch rewrite does not satisfy this convert task, even if differential tests pass.\n- Do not introduce unnecessary code.\n- Keep the converted file runnable as a PyTorch-facing operator artifact.\n- Prefer targeted conversion over unrelated refactoring.\n- Use the requested standalone or differential correctness validation mode instead of inventing a third validation workflow here.\n- Input validation in the converted operator must limit itself to zero-cost metadata checks (`.dtype`, `.ndim`, `.device`, `.shape`, `.numel()`). Never scan tensor data for bounds or value-range validation — calling `.min().item()`, `.max().item()`, or any reduction+`.item()` on input tensors forces a GPU→CPU synchronization on every forward call and destroys performance. The caller is responsible for providing valid inputs, just as it is for the original PyTorch operator.\n\n## Do Not\n\n- Do not call `optimize` or create `opt-round-*` directories from this workflow.\n- Do not create `baseline\u002F` or any optimize-session artifacts from this workflow.\n- Do not replace the converted Triton kernel path with pure PyTorch just to get validation green.\n- Do not create input-validation helpers (e.g., `_validate_index`, `_check_bounds`, `_assert_indices`, or similarly-named functions) that scan tensor data. Specifically, never call `.min().item()`, `.max().item()`, `.sum().item()`, or any reduction followed by `.item()` on GPU\u002FNPU tensors before launching a kernel. These force a full-tensor GPU→CPU synchronization on every forward call. The converted operator inherits the same input contract as the original PyTorch operator — if the caller passes out-of-bounds indices, that is a caller bug, not something the conversion must guard against.\n- Do not submit a pure PyTorch rewrite as the converted result, even when the wrapper signature or standalone or differential outputs still look correct.\n- Do not write your own comparison script (e.g., `python3 -c \"import torch; ...\"`) to compare result `.pt` files or operator outputs.\n- Do not use `torch.allclose`, `torch.testing.assert_close`, `torch.equal`, or any other numerical comparison function with custom tolerances to validate conversion correctness — always use `run-test-convert` from the `ascend-npu-run-eval` skill.\n- Do not self-declare the conversion as \"PASS\" based on your own tolerance analysis — only the printed output of `run-test-convert` determines success.\n- Do not run differential test files directly with `python3` — always use `cli.py run-test-convert`.\n- Do not save custom `.pt` files (e.g., `REFERENCE_RESULT.pt`, `COMPARE_RESULT.pt`) for manual comparison — this may interfere with the CLI validation loop's result caching.\n",{"name":5,"description":7},"main","5d6a3de8bf1eb43267adffc8e27a87d85fd81a4b","skills\u002Ftriton\u002Ftriton-npu-convert-pytorch-operator","https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix","https:\u002F\u002Fgithub.com\u002FPiagari","2026-07-16 20:07:51",{"source":8,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add Piagari\u002Fhelix --skill triton-npu-convert-pytorch-operator",{"tool":35,"command":36},"bunx","bunx skills add Piagari\u002Fhelix --skill triton-npu-convert-pytorch-operator",{"tool":38,"command":39},"pnpm","pnpm dlx skills add Piagari\u002Fhelix --skill triton-npu-convert-pytorch-operator","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix\u002Fblob\u002Fmain\u002Fskills\u002Ftriton\u002Ftriton-npu-convert-pytorch-operator\u002FSKILL.md",true,[],[44,51,58,65,72,77],{"skillNo":45,"name":46,"nameZh":6,"description":47,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":48,"categories":49,"keywords":50,"publishedAt":18},"01M7985HE7EHEXX41M79MSZCMJ","triton-npu-repair-guide","Heuristic fixes for Ascend Triton compile\u002FJIT\u002Fkernel errors and numerical precision mismatches when editing or converting the operator. Does not replace ascend-npu-gen-test, ascend-npu-gen-bench, or harness specs.","https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix\u002Fblob\u002Fmain\u002Fskills\u002Ftriton\u002Ftriton-npu-repair-guide\u002FSKILL.md",[],[],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":18},"01M7985DFYH5RRCDFTWAFYDFGA","triton-npu-optimize","Iteratively optimize a Triton Ascend NPU operator with correctness and performance gates. Use for operator optimization tasks that need repeated correctness validation, benchmark validation, multi-round experiment tracking, reusable optimization notes, and profiler-backed performance analysis when benchmark results need deeper explanation.","https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix\u002Fblob\u002Fmain\u002Fskills\u002Ftriton\u002Ftriton-npu-optimize\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":18},"01M79858YFWE96X7ZA1BJRVDEX","triton-npu-optimize-knowledge","Generic reference-only optimize knowledge for pattern triage and evidence-backed symptom routing. This skill does not define optimize workflow or own round artifacts.","https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix\u002Fblob\u002Fmain\u002Fskills\u002Ftriton\u002Ftriton-npu-optimize-knowledge\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":18},"01M79854BZPJ0XY5PTPQWTCY7Q","triton-npu-optimize-knowledge-v3","Generic reference-only optimize knowledge (v3 working copy) for pattern triage and evidence-backed symptom routing. This skill does not define optimize workflow or own round artifacts; prefer this tree for ongoing knowledge updates.","https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix\u002Fblob\u002Fmain\u002Fskills\u002Ftriton\u002Ftriton-npu-optimize-knowledge-v3\u002FSKILL.md",[],[],{"skillNo":73,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":18},"01M79850QM6QZP8VP6ZRQBQHCT","https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix\u002Fblob\u002Fmain\u002Fskills\u002Ftriton\u002Ftriton-npu-optimize-knowledge-v2\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":18},"01M7984PRE5N1CWZBCXVC6G1K9","triton-npu-cann-ext-api-patterns","A5-only specialized optimization pattern references for Triton Ascend NPU kernels that use CANN Triton extension APIs. This skill does not define the optimize workflow; it only provides pattern material for optimize to consume.","https:\u002F\u002Fgithub.com\u002FPiagari\u002Fhelix\u002Fblob\u002Fmain\u002Fskills\u002Ftriton\u002Ftriton-npu-cann-ext-api-patterns\u002FSKILL.md",[],[]]