Skip to content

[Hardware][XPU] Register matmul and linear batch-invariant kernels for XPU - #49209

Merged
hmellor merged 24 commits into
vllm-project:mainfrom
tzielinski-habana:matmul_linear_bi
Sep 2, 2026
Merged

hmellor merged 24 commits into
vllm-project:mainfrom
tzielinski-habana:matmul_linear_bi

Conversation

@tzielinski-habana

Copy link
Copy Markdown
Contributor

Purpose

This is the second (2/2) PR introducing batch invariance to Intel XPU devices. You can find the first one here.

This PR registers the missing matmul and linear kernels. It also adds a new matmul_kernel_descriptor_persistent Triton kernel for better matmul performance on XPU.

Test Plan

Tested with unit tests covering batch invariance on XPU.

Test Result

All tests pass.

Note

The code was co-developed with GitHub Copilot.


Details Matmul and linear kernels were skipped in the previous PR, because they required more work. I tested batch invariance in Reinforcement Learning context and there I hit an error, because backward kernels were not registered for the "XPU" dispatch key. Also, I wanted to introduce a new Triton matmul kernel based on Tensor Derscriptors, because that implementation has shown ~3x speedup on XPU vs. the one based on pointers.

tzielinski-habana and others added 5 commits July 15, 2026 19:32
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
@mergify mergify Bot added the v1 label Jul 20, 2026
@tzielinski-habana tzielinski-habana changed the title Matmul linear bi [Hardware][XPU] Register matmul and linear batch-invariant kernels for XPU Jul 20, 2026
@mergify mergify Bot added the intel-gpu Related to Intel GPU label Jul 20, 2026
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
@mergify

mergify Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Documentation preview: https://vllm--49209.org.readthedocs.build/en/49209/

@mergify mergify Bot added the documentation Improvements or additions to documentation label Jul 20, 2026
@tzielinski-habana
tzielinski-habana marked this pull request as ready for review July 21, 2026 13:25

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@yewentao256 yewentao256 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work!

Comment thread vllm/model_executor/determinism/batch_invariant.py

@yewentao256 yewentao256 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work, please also test with e2e performance with / without batch invariance

Comment thread vllm/model_executor/layers/batch_invariant.py Outdated
Comment thread vllm/model_executor/layers/batch_invariant.py
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
Comment thread vllm/model_executor/layers/batch_invariant.py Outdated
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
@tzielinski-habana

tzielinski-habana commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the work, please also test with e2e performance with / without batch invariance

Running this benchmark:
vllm bench throughput --model meta-llama/Llama-3.2-3B-Instruct --max-model-len 2048 --num-prompts 100

I get a ~4.4x slowdown with batch invariance.

When I run a kernel-level benchmark for matmul related kernels, the average slowdowns are as follows:
addmm ~3.49x
linear ~1.61x
matmul ~3.59x
mm ~4.71x

I'm attaching a more detailed kernel-level info in a txt file
kernel_level_BI_slowdown.txt

As for RL, for which we need BI, rollouts from vLLM are only a small part of the whole training process, so the slowdowns there are less impactful. When I checked on one RL benchmark, I got only a ~20% slowdown.

Comment on lines +1099 to +1107
def _matmul_backward_xpu(grad, self, other, mask):
"""XPU implementation of aten::matmul_backward."""
grad_self = (
matmul_batch_invariant(grad, other.transpose(-1, -2)) if mask[0] else None
)
grad_other = (
matmul_batch_invariant(self.transpose(-1, -2), grad) if mask[1] else None
)
return grad_self, grad_other

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need backward inside vLLM? I don't think it is a good idea

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point

Comment thread vllm/model_executor/determinism/batch_invariant.py
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>

@yewentao256 yewentao256 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work!

Comment thread vllm/model_executor/determinism/batch_invariant.py
Comment on lines +285 to +288
# Tensor descriptors require contiguous row-major layout.
a = a.contiguous()
# Descriptor kernel expects B in [N, K] layout (K-contiguous).
b_t = b.t().contiguous()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would contiguous be safe enough? Eg. K=60、N=17?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know it's safe. With strange dimensions we would still be correct, but slower.

Comment thread vllm/model_executor/layers/batch_invariant.py Outdated
Comment thread vllm/model_executor/layers/batch_invariant.py Outdated
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>

@yewentao256 yewentao256 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only one nit left, thanks for the iteration!

Comment thread vllm/model_executor/determinism/batch_invariant.py
@github-actions

Copy link
Copy Markdown

✅ Queued 1 failed job(s) for retry in Buildkite CI #85014.

@mergify mergify Bot removed the needs-rebase label Aug 21, 2026
@tzielinski-habana

Copy link
Copy Markdown
Contributor Author

@hmellor will you find some time for review, please? It looks like I need your approval as well

@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @tzielinski-habana.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Aug 24, 2026
@mergify mergify Bot removed the needs-rebase label Aug 25, 2026
@tzielinski-habana

tzielinski-habana commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Some new PRs entered and reorganized the code quite significantly. I solved merge conflicts, but I'll have to reorganize the matmul config bit in my PR to match the new code. I'll probably have it ready tomorrow.

_get_descriptor_matmul_config now sits next to _get_matmul_config in
batch_invariant_configs.py, which became the home for persistent-matmul
config selection in vllm-project#53247. Pure move: the returned configs are identical
for every M and dtype.

Also record why BLOCK_SIZE_K is derived from dtype alone: an M-dependent
BLOCK_K would change the K-reduction order and break batch invariance.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
@tzielinski-habana

Copy link
Copy Markdown
Contributor Author

@hmellor will you find some time for review, please? It looks like I need your approval as well

@hmellor can you please review?

@yewentao256

Copy link
Copy Markdown
Member

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #86379 for commit 83e2b2278b91.

Comment thread docs/features/batch_invariance.md Outdated
tzielinski-habana and others added 2 commits September 1, 2026 14:45
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Tomasz Zielinski <85164140+tzielinski-habana@users.noreply.github.com>
@hmellor

hmellor commented Sep 1, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #86600 for commit efbdfdc6235f.

@tzielinski-habana

Copy link
Copy Markdown
Contributor Author

/ci retry

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

✅ No failed, timed-out, or expired jobs need retrying: https://buildkite.com/vllm/ci/builds/86600

@tzielinski-habana

Copy link
Copy Markdown
Contributor Author

/ci run

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

✅ Triggered Buildkite CI #86863 for commit 5535256199e1.

@hmellor
hmellor enabled auto-merge (squash) September 2, 2026 12:29
@hmellor
hmellor merged commit ffe3bb3 into vllm-project:main Sep 2, 2026
72 of 73 checks passed
mylibrar pushed a commit to tanyuqian/vllm that referenced this pull request Sep 3, 2026
…r XPU (vllm-project#49209)

Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
Signed-off-by: Tomasz Zielinski <85164140+tzielinski-habana@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
sheralskumar pushed a commit to sheralskumar/vllm that referenced this pull request Sep 8, 2026
…r XPU (vllm-project#49209)

Signed-off-by: tzielinski-habana <tomasz.zielinski@intel.com>
Signed-off-by: Tomasz Zielinski <85164140+tzielinski-habana@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation intel-gpu Related to Intel GPU ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants