[NPU] make torch_native lora backend a little bit faster (#17228)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Egor Filimonov <44640852+ssshinigami@users.noreply.github.com> Co-authored-by: ronnie_zheng <zl19940307@163.com>
This commit is contained in:
@@ -35,7 +35,7 @@ def sgemm_lora_a_fwd(
|
||||
x_seq = inputs[token_offset : token_offset + seq_len, :]
|
||||
w_seq = weights[lora_idx, : num_slices * rank, :]
|
||||
|
||||
result = torch.einsum("si, oi -> so", x_seq, w_seq)
|
||||
result = torch.mm(x_seq, w_seq.T)
|
||||
output[token_offset : token_offset + seq_len, : num_slices * rank] = (
|
||||
scaling_tensor[lora_idx] * result
|
||||
)
|
||||
@@ -98,11 +98,10 @@ def sgemm_lora_b_fwd(
|
||||
lora_idx, slice_start_output:slice_end_output, :rank
|
||||
] # (slice_dim, rank)
|
||||
|
||||
result = torch.einsum("si, oi -> so", x_slice, w_slice)
|
||||
output[
|
||||
token_offset : token_offset + seq_len,
|
||||
slice_start_output:slice_end_output,
|
||||
] += result
|
||||
].add_(torch.mm(x_slice, w_slice.T))
|
||||
|
||||
token_offset += seq_len
|
||||
|
||||
|
||||
Reference in New Issue
Block a user