Skip to content

Extract optimized causal conv1d prefill algorithm from Qwen3.5 into standalone function + tests#2

Draft
HeJunyan with Copilot wants to merge 1 commit into
mainfrom
copilot/extract-optimized-conv1d
Draft

Extract optimized causal conv1d prefill algorithm from Qwen3.5 into standalone function + tests#2
HeJunyan with Copilot wants to merge 1 commit into
mainfrom
copilot/extract-optimized-conv1d

Conversation

Copilot AI commented Apr 7, 2026

Copy link
Copy Markdown

The optimized prefill-path depth-wise causal conv1d in qwen3_5.py (lines 377–412) was inlined inside the model's forward() with no reusable interface or test coverage.

Changes

  • vllm/model_executor/models/qwen3_5_conv1d.py — new standalone function optimized_causal_conv1d_prefill

    • Accepts x: [bs, seq_len, dim], preprocessed weight: [kernel_size, dim], optional bias: [dim]
    • Implements the loop-based in-place accumulation strategy (avoids large intermediate tensors from F.conv1d), then applies SiLU
    • Input validation with descriptive errors
  • tests/kernels/test_qwen3_5_conv1d.py — test suite covering:

    • Numerical correctness vs. nn.Conv1d reference across shapes, kernel sizes, dtypes, and bias combinations
    • Causality: future token perturbations must not affect past outputs
    • Degenerate cases: kernel_size=1 (pointwise), zero weights, single-token sequence
    • Shape invariance
    • Validation error paths

Usage

from vllm.model_executor.models.qwen3_5_conv1d import optimized_causal_conv1d_prefill

# weight in preprocessed [kernel_size, dim] form:
# conv1d.weight.squeeze(1).transpose(0,1).flatten().reshape(kernel_size, dim)
out = optimized_causal_conv1d_prefill(x, weight, bias=bias, activation="silu")
# out: [bs, seq_len, dim]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants