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

Add Python version of the basic benchmarks #4411

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ py-test:
py-test-allpy:
nox -s tests

# Run all Python benchmarks
py-bench *ARGS:
python -m pytest -c rerun_py/pyproject.toml --benchmark-only {{ARGS}}


# Serve the python docs locally
py-docs-serve:
mkdocs serve -f rerun_py/mkdocs.yml -w rerun_py
Expand Down
1 change: 1 addition & 0 deletions rerun_py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ python-packages = ["rerun_sdk/rerun"]
filterwarnings = """
error
"""
norecursedirs = ".* venv* target* build"
26 changes: 26 additions & 0 deletions tests/python/log_benchmark/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

import dataclasses

import numpy as np

MAX_INT64 = 2**63 - 1
MAX_INT32 = 2**31 - 1


@dataclasses.dataclass
class Point3DInput:
positions: np.ndarray
colors: np.ndarray
radii: np.ndarray
label: str = "some label"

@classmethod
def prepare(cls, seed: int, num_points: int):
rng = np.random.default_rng(seed=seed)

return cls(
positions=rng.integers(0, MAX_INT64, (num_points, 3)).astype(dtype=np.float32),
colors=rng.integers(0, MAX_INT32, num_points, dtype=np.uint32),
radii=rng.integers(0, MAX_INT64, num_points).astype(dtype=np.float32),
)
59 changes: 59 additions & 0 deletions tests/python/log_benchmark/test_log_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from __future__ import annotations

import numpy as np
import rerun as rr

from . import Point3DInput


def log_points3d_large_batch(data: Point3DInput):
# create a new, empty memory sink for the current recording
rr.memory_recording()

rr.log(
"large_batch",
rr.Points3D(positions=data.positions, colors=data.colors, radii=data.radii, labels=data.label),
)


def test_bench_points3d_large_batch(benchmark):
rr.init("rerun_example_benchmark_points3d_large_batch")
data = Point3DInput.prepare(42, 50_000_000)
benchmark(log_points3d_large_batch, data)
abey79 marked this conversation as resolved.
Show resolved Hide resolved


def log_points3d_many_individual(data: Point3DInput):
# create a new, empty memory sink for the current recording
rr.memory_recording()

for i in range(data.positions.shape[0]):
rr.log(
"single_point",
rr.Points3D(positions=data.positions[i], colors=data.colors[i], radii=data.radii[i]),
)


def test_bench_points3d_many_individual(benchmark):
rr.init("rerun_example_benchmark_points3d_many_individual")
data = Point3DInput.prepare(1337, 100_000)
benchmark(log_points3d_many_individual, data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there anyway to specify that the throughput of this benchmark is 100k per iteration, so that the stats make sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I've factored parametrisation in a better way that's explicit in the test name (and extensible if we want more test cases in the future).

Which reminds me to put a note that the num_point for many_individual is vastly smaller than the Rust version, as I actually want the benchmark to finish running inside of this year.



IMAGE_DIMENSION = 16_384
IMAGE_CHANNELS = 4
NUM_LOG_CALLS = 4


def log_image(image: np.ndarray):
# create a new, empty memory sink for the current recording
rr.memory_recording()

for i in range(NUM_LOG_CALLS):
rr.log("test_image", rr.Tensor(image))


def test_bench_image(benchmark):
rr.init("rerun_example_benchmark_image")

image = np.zeros((IMAGE_DIMENSION, IMAGE_DIMENSION, IMAGE_CHANNELS), dtype=np.uint8)
benchmark(log_image, image)
abey79 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions tests/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-r test_api/requirements.txt
-r nv12image/requirements.txt
pytest-benchmark
Loading