Skip to content

ML inference execution research

Reviewed 2026-09-20. These are recommended backlog decisions, not implemented behavior or hardware qualification. Sources are first-party documentation and implementation repositories.

Repository baseline

CONTEXT.md assigns meaning to Consumers and bounded mechanics to this library. At the reviewed 2026-09-20 baseline, src/telemetry/performance/evaluation.py executes synchronous callables serially, times with perf_counter_ns, discards warmup outputs, and records aggregate reports without case payloads. docs/performance-evaluation.md explicitly excludes killing arbitrary callables. pyproject.toml and compatibility.toml support Python >=3.12,<3.15 with no mandatory dependencies. Preserve these contracts while introducing explicit optional execution adapters. Existing telemetry delivery capacity research in docs/research/performance-testing.md is relevant methodology, but a model serving runner must have a separate workload/report identity. The file layout above is historical; use the current source inventory and current evaluator for implemented behavior.

Accelerator timing

PyTorch's Timer performs warmups, controls threadpool size, and synchronizes accelerators when needed. Its blocked autorange amortizes timing overhead across repeated statements. PyTorch benchmark utilities

Recommendation: expose distinct synchronized end-to-end latency and device-event timing modes. Default the PyTorch adapter to synchronized end-to-end completion on the selected device; record device, timing mode, precision, thread count, transfer inclusion, warmups, and compiler/setup scope. Use Timer for explicitly repeatable microbenchmarks, not automatic repetition of stateful Evaluation Cases. Never mix device-only and end-to-end measurements in baseline comparisons. Test synchronization ordering with a fake backend, delayed completion, error cleanup, CPU fallback, and a separately marked real-device integration contract. Hardware evidence must name the device and framework build.

Batch inference

Triton distinguishes concurrent outstanding requests from request-rate load and supports explicit scheduled request timestamps. These distinctions motivate separate batching and serving contracts. Triton load modes

Recommendation: add an explicit batch callable and Consumer-owned collate/split functions. Default batch size to one; use an explicitly declared bounded sweep. Preserve a partial final batch, reject output-count mismatches, and report both requests/s and cases/s with actual batch sizes. Do not infer per-case latency by dividing batch latency. Tests cover non-divisible case counts, reordering, whole-batch failures, padding masks, output mismatch, and equivalent quality at batch size one.

Async inference

Python 3.12 provides TaskGroup and cancellation-based timeouts; cancellation is cooperative and can be suppressed by user code. TaskGroup cancels siblings on an unhandled non-cancellation exception. Python task/cancellation documentation

Recommendation: provide an awaitable API usable inside an existing loop, with concurrency one by default and a bounded pending queue. Preserve case identity independently of completion order. Catch ordinary candidate exceptions inside workers when continue-on-error is selected; propagate caller cancellation after cleanup. Record admission delay separately from execution time. Require an explicit positive timeout for timeout-enabled operation, and label its guarantee cooperative. Tests prove concurrency/queue bounds, deterministic result association, partial failures, cancellation, and no leaked tasks with cooperative candidates. Never promise thread or remote-request termination.

Setup, reset, and cold execution

Recommendation: define setup, optional reset, warmup, measured execution, and teardown phases, with separate durations and bounded safe failure categories. Default warmed trials to one setup per run; require a fresh-process mode to claim process cold-start measurements. Make model reconstruction and cache-reset hooks Consumer-owned. No automatic cache deletion or device clock modification. Test phase order, exactly-once teardown after setup succeeds, setup failure, warmup exclusion, reset failure, and independent cold/warm report identities. Report compilation inclusion explicitly.

Enforceable process deadlines

Python documents spawn contexts and warns that terminating a process can corrupt shared queues or leave locks held; termination does not terminate descendants. Python multiprocessing

Recommendation: offer a separate opt-in isolated runner using an explicit spawn context, bounded IPC, and Consumer-owned importable factories. Retain sensitive cases and Measurements inside the worker and return only validated report summaries. Use disposable per-worker IPC, explicit deadline and termination grace, then kill/join when necessary. Mark incomplete cleanup distinctly; descendant containment requires an OS-specific supported strategy and must not be implied by Process. Tests include infinite loops, crash, oversized response, timeout during setup, serialization failure, subsequent healthy work, and no surviving direct child. This is process isolation, not a sandbox.

Resource measurements

NVML provides NVIDIA GPU monitoring and is thread-safe, with hardware-dependent support. NVML API PyTorch's maximum allocated memory measures tensor allocations and supports resetting peak statistics. PyTorch peak allocation

Recommendation: add optional samplers with capability probing. Distinguish process RSS, framework allocated/reserved bytes, device-wide memory, sampled utilization, and power. Record scope, units, sampling interval, sample count, and unavailable reason; unavailable is never zero. Reset framework peak counters at the declared measurement boundary. Device-wide usage is not model attribution. Use a bounded sampler with a configurable 100 ms initial interval, explicitly described as a sampling choice that can miss short peaks. Test unit conversion, missing/unsupported devices, shared-device scope, peak reset, bounded sample storage, cleanup, and sampler failures isolated from evaluation.

Serving load

wrk2 measures latency against intended send times to expose coordinated omission. wrk2 implementation rationale

Recommendation: build a separate serving runner with explicit open-loop constant-rate schedules; add seeded Poisson schedules and separately labelled closed-loop concurrency sweeps. Retain scheduled, sent, first-response, and completed timestamps in bounded in-process observations. Persist aggregate schedule lag, end-to-end latency, throughput, errors, dropped arrivals, timeout counts, and load model. Bound duration, outstanding requests, queue, and drain. A saturated generator must report invalid or generator-limited evidence rather than silently lower offered load. Tests with a controllable clock and delayed fake server prove arrivals remain independent of completions, accounting conservation, deadline/drain behavior, schedule-lag detection, and separation from Collector capacity evidence.

Optional adapters and compatibility

Recommendation: retain the dependency-free core and lazy imports. Start with PyTorch execution and NVML resource extras; keep provider HTTP clients behind structural interfaces. Adapter support must be an explicit Python/framework/OS/device matrix verified against installable distributions when implemented; documentation availability alone does not establish wheel compatibility. Do not narrow core Python support to accommodate an optional adapter. Test base installation with optional imports blocked, missing dependency diagnostics, minimum/maximum supported adapter versions, clean wheel installation, and declared unsupported combinations. Record dependency/build identity in execution evidence. Run packaging gates whenever extras change and real hardware jobs for advertised devices; mocked tests cannot substantiate accelerator performance.

Sequencing

First define execution/timing identity and lifecycle contracts. Then implement batch and async adapters, accelerator timing, optional resource sampling, isolated deadlines, and a separate serving runner. Update report schemas and comparison compatibility with each newly measurable boundary. Use observable contract tests at the lowest layer; require narrow tests, static/unit/integration gates, and build checks for packaging changes. Docker qualification is required only for changed Collector assets, not inferred from adding an ML execution adapter.