From 933bd97878ba54e767bb78319cc3e3354ae0c8c3 Mon Sep 17 00:00:00 2001 From: Maxime Ellerbach Date: Tue, 21 Jul 2026 09:42:36 +0000 Subject: [PATCH] avoid cold first spike --- src/lerobot/rollout/inference/rtc.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lerobot/rollout/inference/rtc.py b/src/lerobot/rollout/inference/rtc.py index 0eef62cef..5ef86cc7e 100644 --- a/src/lerobot/rollout/inference/rtc.py +++ b/src/lerobot/rollout/inference/rtc.py @@ -252,6 +252,8 @@ class RTCInferenceEngine(InferenceEngine): policy_device = torch.device(self._device) warmup_required = max(1, self._compile_warmup_inferences) if self._use_torch_compile else 0 + # exclude the first N inferences from the latency tracker to avoid cold-start spikes + latency_warmup_required = max(1, warmup_required) inference_count = 0 consecutive_errors = 0 @@ -273,7 +275,7 @@ class RTCInferenceEngine(InferenceEngine): idx_before = queue.get_action_index() prev_actions = queue.get_left_over() - latency = latency_tracker.max() + latency = latency_tracker.p95() delay = math.ceil(latency / time_per_chunk) if latency else 0 obs_batch = build_dataset_frame(self._hw_features, obs, prefix="observation") @@ -316,7 +318,8 @@ class RTCInferenceEngine(InferenceEngine): inference_count += 1 consecutive_errors = 0 is_warmup = self._use_torch_compile and inference_count <= warmup_required - if is_warmup: + # Ignore the first N inferences for latency tracking to avoid cold-start spikes + if inference_count <= latency_warmup_required: latency_tracker.reset() else: latency_tracker.add(new_latency)