Skip to content
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

include convert latency in bench_append_paged_kv_cache #590

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
28 changes: 17 additions & 11 deletions benchmarks/bench_append_paged_kv_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import dataclasses
from typing import cast
from typing import Tuple, cast

import torch
from triton.testing import do_bench
Expand Down Expand Up @@ -99,14 +99,19 @@ def main():
dtype=torch.int32,
)

batch_indices, positions = flashinfer.get_batch_indices_positions(
x_indptr,
flashinfer.get_seq_lens(kv_indptr, kv_last_page_len, page_len),
k.shape[0],
)
@torch.cuda.nvtx.range(f"convert model={model_name}, seqlens={seqlens}")
def fn_convert() -> Tuple[torch.Tensor, torch.Tensor]:
return flashinfer.get_batch_indices_positions(
x_indptr,
flashinfer.get_seq_lens(kv_indptr, kv_last_page_len, page_len),
k.shape[0],
)

batch_indices, positions = fn_convert()
convert_latency_ms = cast(float, do_bench(fn_convert))

@torch.cuda.nvtx.range(f"model={model_name}, seqlens={seqlens}")
def fn():
@torch.cuda.nvtx.range(f"append model={model_name}, seqlens={seqlens}")
def fn() -> None:
flashinfer.append_paged_kv_cache(
k,
v,
Expand All @@ -120,7 +125,7 @@ def fn():
)

latency_ms = cast(float, do_bench(fn))
all_layers_latency_ms = latency_ms * model.num_layers
all_layers_latency_ms = convert_latency_ms + latency_ms * model.num_layers
throughput = (
k.numel()
* k.element_size()
Expand All @@ -131,8 +136,9 @@ def fn():
print(
f"model: {model_name:8}",
f"seqlens: {seqlens!r:{seqlen_strlen}}",
f"single_layer: {latency_ms:5.3f}ms",
f"all_layers: {all_layers_latency_ms:7.3f}ms",
f"convert: {convert_latency_ms*1e3:2.0f}us",
f"1layer: {latency_ms*1e3:2.0f}us",
f"{model.num_layers}layers: {all_layers_latency_ms*1e3:3.0f}us",
f"throughput: {throughput*1e-9:8.3f}GB/s",
)
print("---")
Expand Down