Skip to content

Handling input dim size greater than 3 in tuned_gemm.py #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions vllm/model_executor/layers/tuned_gemm.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def scaled_mm(
def mm(self, inp, weights, bias=None):
if not support_tuned_gemms:
return F.linear(inp, weights, bias)
# F.Linear can take a 3 dimensional input. vllm
# uses this for linear units. However, sampler
# will use torch.matmul with 2 dimensions only
if inp.dim() == 3:
# F.Linear can take a 3 dimensional (or even larger)
# input. vllm uses this for linear units. However,
# sampler will use torch.matmul with 2 dimensions only
if inp.dim() >= 3:
try:
inp_view = inp.view(-1, inp.size(-1))
batched = True
Expand All @@ -157,7 +157,7 @@ def mm(self, inp, weights, bias=None):
out = self.apply_skinny(m, n, k, inp_view, weights)
if out is not None:
if batched:
out = out.view(inp.shape[0], inp.shape[1], weights.shape[0])
out = out.view(*inp.shape[:-1], weights.shape[0])
if bias is not None:
return out + bias
return out
Expand All @@ -182,7 +182,7 @@ def mm(self, inp, weights, bias=None):
self.tuned_df.to_csv(self.untune_path, index=False)
return F.linear(inp, weights, bias)
if batched:
out = out.view(inp.shape[0], inp.shape[1], weights.shape[0])
out = out.view(*inp.shape[:-1], weights.shape[0])
return out


Expand Down