[NPU] Add causal conv1d#28267
Conversation
Signed-off-by: zhaozx-cn <zhaozx2116@163.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the Ascend GDN backend to use torch.ops.npu.causal_conv1d for both decode and extend forward passes, and introduces a device_print utility in utils.py for debugging on NPU. Key feedback includes caching transposed and contiguous convolution weights on the layer object to avoid performance overhead in hot paths, correcting the side-effect registration in _mark_op_side_effectful by adding ops to torch.fx.node._side_effectful_ops instead of calling has_side_effect, and removing unused imports (dataclass and List).
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| mixed_qkv = torch.ops.npu.causal_conv1d( | ||
| mixed_qkv, | ||
| layer.conv_weights.transpose(0, 1).contiguous(), | ||
| conv_states=conv_states, |
There was a problem hiding this comment.
Calling layer.conv_weights.transpose(0, 1).contiguous() on every forward pass introduces unnecessary overhead. Cache the transposed and contiguous weights on the layer object.
| mixed_qkv = torch.ops.npu.causal_conv1d( | |
| mixed_qkv, | |
| layer.conv_weights.transpose(0, 1).contiguous(), | |
| conv_states=conv_states, | |
| if not hasattr(layer, "_conv_weights_npu_cache"): | |
| layer._conv_weights_npu_cache = layer.conv_weights.transpose(0, 1).contiguous() | |
| mixed_qkv = torch.ops.npu.causal_conv1d( | |
| mixed_qkv, | |
| layer._conv_weights_npu_cache, | |
| conv_states=conv_states, |
| mixed_qkv = torch.ops.npu.causal_conv1d( | ||
| mixed_qkv, | ||
| layer.conv_weights, | ||
| layer.bias, | ||
| activation=layer.activation, | ||
| conv_states=conv_states_tmp, | ||
| has_initial_state=has_initial_states, | ||
| cache_indices=cache_indices, | ||
| layer.conv_weights.transpose(0, 1).contiguous(), | ||
| conv_states=conv_states_for_prefill, |
There was a problem hiding this comment.
Calling layer.conv_weights.transpose(0, 1).contiguous() on every forward pass introduces unnecessary overhead. Cache the transposed and contiguous weights on the layer object.
| mixed_qkv = torch.ops.npu.causal_conv1d( | |
| mixed_qkv, | |
| layer.conv_weights, | |
| layer.bias, | |
| activation=layer.activation, | |
| conv_states=conv_states_tmp, | |
| has_initial_state=has_initial_states, | |
| cache_indices=cache_indices, | |
| layer.conv_weights.transpose(0, 1).contiguous(), | |
| conv_states=conv_states_for_prefill, | |
| if not hasattr(layer, "_conv_weights_npu_cache"): | |
| layer._conv_weights_npu_cache = layer.conv_weights.transpose(0, 1).contiguous() | |
| mixed_qkv = torch.ops.npu.causal_conv1d( | |
| mixed_qkv, | |
| layer._conv_weights_npu_cache, | |
| conv_states=conv_states_for_prefill, |
Signed-off-by: zhaozx-cn <zhaozx2116@163.com>
Signed-off-by: zhaozx-cn <zhaozx2116@163.com>
Signed-off-by: zhaozx-cn <zhaozx2116@163.com>
Signed-off-by: zhaozx-cn <zhaozx2116@163.com>
Motivation
apply custom causal_conv1d on npu, sgl-project/sgl-kernel-npu#555 is required
Modifications
apply custom causal_conv1d on npu.
Accuracy Tests
Speed Tests and Profiling
Model:
Qwen/Qwen3.5-35B-A3BChecklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ❌ Run #29193910582
Latest PR Test (Extra): ❌ Run #29193910464