Skip to content

Commit

Permalink
Improve: Larger batch benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Dec 29, 2023
1 parent 8b8038c commit fdc8587
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions scripts/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,31 @@ def bench_captions(


def bench_image_embeddings(model, images):
total_duration, embeddings = duration(
lambda: model.encode_image(model.preprocess_image(images))
)
total_length = len(embeddings)
print(f"Throughput: {total_length/total_duration:.2f} images/s")
total_duration = 0
total_embeddings = 0
images *= 10
while total_duration < 10:
seconds, embeddings = duration(
lambda: model.encode_image(model.preprocess_image(images))
)
total_duration += seconds
total_embeddings += len(embeddings)

print(f"Throughput: {total_embeddings/total_duration:.2f} images/s")


def bench_text_embeddings(model, texts):
total_duration, embeddings = duration(
lambda: model.encode_text(model.preprocess_text(texts))
)
total_length = len(embeddings)
print(f"Throughput: {total_length/total_duration:.2f} queries/s")
total_duration = 0
total_embeddings = 0
texts *= 10
while total_duration < 10:
seconds, embeddings = duration(
lambda: model.encode_text(model.preprocess_text(texts))
)
total_duration += seconds
total_embeddings += len(embeddings)

print(f"Throughput: {total_embeddings/total_duration:.2f} queries/s")


if __name__ == "__main__":
Expand Down

0 comments on commit fdc8587

Please sign in to comment.