GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - atonyhonesto/race-speed-inference: Python race-day inference demo with latency budgets, confidence gating, drift detection and fallback logic.

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
racespeed
racespeed
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
demo.py
demo.py
 
 

Repository files navigation

๐Ÿ race-speed-inference

A pit call has to be on the wall in 25 ms. This is the system that makes sure it always is, even when the model can't be trusted.

tests Python Dependencies License

Companion code for my LinkedIn article
AI/ML at Race Speed: Low-Latency Inference, Confidence Thresholds & Fallback Logic โ†’


The idea in one paragraph

A model that answers in 8 ms is no use if the system around it takes 40. A model that says it's 91% sure but is right 60% of the time is worse than one that admits it doesn't know. This repo builds the parts that turn a model into something you could put on a pit wall: a latency budget per stage, a hard timeout on inference, a dual-threshold confidence gate, calibration, drift detection, a three-tier fallback chain and an audit log of every call. The model itself is deliberately small; the engineering is in everything around it.

How a lap flows through it

flowchart TB
    A["๐Ÿ“ก Telemetry frame arrives ยท 0 ms"] --> B{"Features complete?"}
    B -- yes --> C{"Inside training envelope?"}
    C -- yes --> D["โšก Edge inference ยท hard timeout โ‰ค 10 ms"]
    D -- answered --> E{"๐ŸŽฏ Confidence gate ยท โ‰ค 12 ms"}
    E -- "โ‰ฅ 0.85" --> P["โœ… PRIMARY: model's call"]
    E -- "0.70 โ€“ 0.85" --> V["๐ŸŸก ADVISORY: fallback call, model shown alongside"]
    E -- "< 0.70" --> F
    B -- "no: sensor dropout" --> F
    C -- "no: out of distribution" --> F
    D -- "timeout" --> F
    V --> F
    F["๐Ÿ›Ÿ Fallback chain: 1 ยท rules โ†’ 2 ยท cached call (decays per lap) โ†’ 3 ยท crew chief with context"]
    P --> W["๐Ÿ–ฅ๏ธ Pit wall ยท โ‰ค 25 ms ยท every call written to the audit log"]
    F --> W
Loading

From article to code

The article says Where it lives
Five stages, each with a hard latency budget (10 / 12 / 18 / 25 ms) pipeline.py โ€“ STAGE_DEADLINES_MS, cumulative deadlines from frame arrival
A slow model must not make the call late pipeline.py โ€“ inference runs on a worker thread with future.result(timeout=โ€ฆ)
Dual-threshold gate: โ‰ฅ0.85 primary, 0.70โ€“0.85 advisory, <0.70 fallback gate.py
Confidence without calibration is noise calibration.py โ€“ temperature scaling + expected calibration error
Distributional shift detection drift.py โ€“ z-score envelope from training data
Four failure modes: missing features, timeout, low confidence, out-of-distribution pipeline.py โ€“ each is a named failure_mode on the decision
Tier 1 rules โ†’ Tier 2 cached model โ†’ Tier 3 human override fallback.py
Every prediction logged with context for post-race analysis Decision.to_dict() โ†’ one JSON line per lap

Run it

No dependencies beyond Python 3.10+.

git clone https://github.com/atonyhonesto/race-speed-inference.git
cd race-speed-inference
python demo.py            # simulate a 200-lap race with injected faults
python -m unittest -v     # 15 tests covering every gate zone and failure mode

Real output from python demo.py:

Calibration (expected calibration error, lower is better)
  model as trained              ECE 0.025   (fitted T=1.05)
  simulated overconfident net   ECE 0.091
  ...after temperature scaling  ECE 0.017   (fitted T=3.20)

Race report: 200 laps, seed 2026
----------------------------------------------------
Who made the call             Laps     Share
PRIMARY_MODEL                  166     83.0%
ADVISORY                         4      2.0%
RULES                           10      5.0%
CACHED                          19      9.5%
HUMAN                            1      0.5%
----------------------------------------------------
Why the model was bypassed    Laps
LOW_CONFIDENCE                  14
OUT_OF_DISTRIBUTION              8
FEATURE_UNAVAILABLE              6
MODEL_TIMEOUT                    6
----------------------------------------------------
Primary-model accuracy on laps it owned: 91.6%
Latency  p50 0.07 ms   p99 9.20 ms   max 9.24 ms   (budget 25 ms)
Every call inside its stage deadlines: True

The demo injects three kinds of trouble so every path gets used: 3% sensor dropouts, 3% of inferences artificially stalled for 30 ms, and an eight-lap track-temperature spike the model never trained on. The stalled inferences are cut off at the deadline and handed to the fallback chain, which is why p99 sits just under 10 ms rather than at 30.

One lap from the audit log, when the heat spike pushed the model out of its envelope and neither the rules nor the cache had an answer:

{
  "lap": 157,
  "action": "CREW_CHIEF_CALL",
  "source": "HUMAN",
  "failure_mode": "OUT_OF_DISTRIBUTION",
  "reasons": ["escalated: lap=157, drifted=['track_temp_c']"],
  "stage_ms": {"inference": 0.003, "gate": 0.003, "strategy": 0.022, "dashboard": 0.023},
  "deadline_met": true,
  "injected": ["heat_spike"]
}

Design notes

  • The fallback is a feature, not a failure. In the sample race the model owns 83% of laps. The other 17% still get a safe, explainable call on time, and each one records why the model was bypassed.
  • Calibration is shown on purpose. Logistic regression is close to calibrated out of the box (Tโ‰ˆ1.05), so the demo also sharpens the logits 3x to imitate an overconfident deep network. ECE jumps from 0.025 to 0.091, and temperature scaling (Tโ‰ˆ3.2) brings it back to 0.017.
  • Deadlines are cumulative, not per-stage. Every stage is measured from the moment the frame arrived, so slack early on can't hide a slow stage later.
  • The cache decays. A trusted call from three laps ago is worth less than one from last lap; once it drops below the lower threshold it expires and the chain moves to the human.
  • Accuracy is capped by design. The simulated "right call" has 8% label noise, standing in for strategists who'd disagree, so ~92% is the ceiling.

What's simulated, and what production would swap in

Here On a real pit wall
Synthetic per-lap telemetry (telemetry.py) ECU stream at ~10 ms intervals from 60+ sensors
Pure-Python logistic regression INT8-quantized network on ONNX Runtime / TensorRT at the track edge
Thread-pool timeout Dedicated inference process or accelerator queue with deadline scheduling
Z-score drift envelope Conformal prediction / SafeML-style runtime monitors
JSON-lines audit log Time-series store feeding post-race retraining

Project layout

racespeed/
  telemetry.py     synthetic race + fault injection
  model.py         primary model (pure Python logistic regression)
  calibration.py   temperature scaling, expected calibration error
  drift.py         out-of-distribution detector
  gate.py          dual-threshold confidence gate
  fallback.py      rules โ†’ cached call โ†’ crew chief
  pipeline.py      deadlines, timeout, orchestration, Decision record
demo.py            race simulation + report
tests/             unit and end-to-end tests

Built by Tony Honesto, cloud & integration engineer with roots in IndyCar timing & scoring and NASCAR Race Control. More articles and companion repos: github.com/atonyhonesto ยท LinkedIn

About

Python race-day inference demo with latency budgets, confidence gating, drift detection and fallback logic.

Topics

inferencelow-latencymachine-learningmodel-monitoringmotorsportpythontelemetrytesting

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.