Skip to content
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a33a35c
[Bugfix] Fix scaled_mm output narrowing for 3D input tensors
nemanjaudovic Mar 25, 2026
ba22382
Extract _get_num_tokens helper to avoid code duplication
nemanjaudovic Mar 25, 2026
87dcb20
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 6, 2026
ba54f2e
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 7, 2026
76feda3
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 7, 2026
19cb57b
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 9, 2026
31643a8
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 15, 2026
2bff959
Merge branch 'main' into bugfix/scaled-mm-3d-input
tjtanaa Apr 16, 2026
b9f06de
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 16, 2026
f85ee1a
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 16, 2026
58a09ae
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 16, 2026
943f06d
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 16, 2026
b76dc53
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 16, 2026
e69f03e
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
a061ff2
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
e1f6c5d
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
449f9be
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
9d518d8
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
effc1a6
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
4e43000
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
2fd5499
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
0514ae5
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 17, 2026
77cbad3
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 18, 2026
6ad0b5c
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 18, 2026
98cf3d2
Merge branch 'main' into bugfix/scaled-mm-3d-input
nemanjaudovic Apr 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions vllm/model_executor/kernels/linear/scaled_mm/pytorch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project

import math

import torch

Expand All @@ -13,6 +14,13 @@
)


def _get_num_tokens(output_shape: list) -> int:
# torch._scaled_mm works with 2D tensors, so input tensors are
# flattened if they are 3D. If output_shape is 3D, num_tokens is
# the product of all dims except the last (hidden dim).
return math.prod(output_shape[:-1])


class TorchFP8ScaledMMLinearKernel(FP8ScaledMMLinearKernel):
"""
Base class for FP8 linear kernels using Torch.
Expand Down Expand Up @@ -78,7 +86,8 @@ def apply_scaled_mm(
if type(output) is tuple and len(output) == 2:
output = output[0]

return torch.narrow(output, 0, 0, output_shape[0]).view(*output_shape)
num_tokens = _get_num_tokens(output_shape)
return torch.narrow(output, 0, 0, num_tokens).view(*output_shape)


class RowWiseTorchFP8ScaledMMLinearKernel(TorchFP8ScaledMMLinearKernel):
Expand Down Expand Up @@ -145,7 +154,8 @@ def apply_scaled_mm(
bias=bias,
)

return torch.narrow(output, 0, 0, output_shape[0]).view(*output_shape)
num_tokens = _get_num_tokens(output_shape)
return torch.narrow(output, 0, 0, num_tokens).view(*output_shape)


class ChannelWiseTorchFP8ScaledMMLinearKernel(TorchFP8ScaledMMLinearKernel):
Expand Down Expand Up @@ -206,8 +216,9 @@ def apply_scaled_mm(
output = output[0]

# Unpad (undo num_token_padding)
output = torch.narrow(output, 0, 0, output_shape[0])
x_scale = torch.narrow(As, 0, 0, output_shape[0])
num_tokens = _get_num_tokens(output_shape)
output = torch.narrow(output, 0, 0, num_tokens)
x_scale = torch.narrow(As, 0, 0, num_tokens)

# DQ
# C = sw * sx * (X * W) + bias
Expand Down
Loading