From 47db84ebfb47f82bfe3ebb3d78cb13d4bc9a91a3 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 2 Sep 2026 01:28:43 -0400 Subject: [PATCH] models: add big model ONNX hash tracking (#1982) --- openpilot/sunnypilot/models/default_model.py | 14 ++++++++++ .../sunnypilot/models/tests/big_model_hash | 1 + .../models/tests/test_default_model.py | 27 ++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 openpilot/sunnypilot/models/tests/big_model_hash diff --git a/openpilot/sunnypilot/models/default_model.py b/openpilot/sunnypilot/models/default_model.py index e3c9360835..84e962cdcd 100755 --- a/openpilot/sunnypilot/models/default_model.py +++ b/openpilot/sunnypilot/models/default_model.py @@ -20,7 +20,9 @@ def get_default_model() -> str: DEFAULT_MODEL_NAME_PATH = os.path.join(BASEDIR, "openpilot", "sunnypilot", "models", "model_name.py") MODEL_HASH_PATH = os.path.join(BASEDIR, "openpilot", "sunnypilot", "models", "tests", "model_hash") +BIG_MODEL_HASH_PATH = os.path.join(BASEDIR, "openpilot", "sunnypilot", "models", "tests", "big_model_hash") SUPERCOMBO_ONNX_PATH = os.path.join(BASEDIR, "openpilot", "selfdrive", "modeld", "models", "driving_supercombo.onnx") +BIG_SUPERCOMBO_ONNX_PATH = os.path.join(BASEDIR, "openpilot", "selfdrive", "modeld", "models", "big_driving_supercombo.onnx") def update_model_hash(): @@ -32,6 +34,18 @@ def update_model_hash(): print(f"Generated and updated new combined model hash to {MODEL_HASH_PATH}") + if os.path.exists(BIG_SUPERCOMBO_ONNX_PATH): + import subprocess + rel = os.path.relpath(BIG_SUPERCOMBO_ONNX_PATH, os.getcwd()) + pointer = subprocess.check_output(["git", "show", f"HEAD:{rel}"], text=True) + oid = next(l.split(":", 1)[1] for l in pointer.splitlines() if l.startswith("oid sha256:")) + big_combined_hash = hashlib.sha256(oid.encode()).hexdigest() + + with open(BIG_MODEL_HASH_PATH, "w") as f: + f.write(big_combined_hash) + + print(f"Generated and updated new big model hash to {BIG_MODEL_HASH_PATH}") + def get_ref_for_name(url: str, name: str) -> str: response = requests.get(url, timeout=10) diff --git a/openpilot/sunnypilot/models/tests/big_model_hash b/openpilot/sunnypilot/models/tests/big_model_hash new file mode 100644 index 0000000000..e957940fdd --- /dev/null +++ b/openpilot/sunnypilot/models/tests/big_model_hash @@ -0,0 +1 @@ +8bba37156aa17d49210cad028744c839ea9ed7b1f19428a8ecfafdc1e07a73b6 \ No newline at end of file diff --git a/openpilot/sunnypilot/models/tests/test_default_model.py b/openpilot/sunnypilot/models/tests/test_default_model.py index b72c2b4c89..c322d3b699 100644 --- a/openpilot/sunnypilot/models/tests/test_default_model.py +++ b/openpilot/sunnypilot/models/tests/test_default_model.py @@ -5,12 +5,25 @@ This file is part of sunnypilot and is licensed under the MIT License. See the LICENSE.md file in the root directory for more details. """ +import os +import subprocess + from openpilot.sunnypilot import get_file_hash -from openpilot.sunnypilot.models.default_model import MODEL_HASH_PATH, SUPERCOMBO_ONNX_PATH +from openpilot.sunnypilot.models.default_model import MODEL_HASH_PATH, SUPERCOMBO_ONNX_PATH, BIG_MODEL_HASH_PATH, \ + BIG_SUPERCOMBO_ONNX_PATH import hashlib from openpilot.common.test import OpenpilotTestCase +def _get_lfs_oid(path: str) -> str: + """Extract the LFS OID (SHA256 of actual content) from git, works whether the file is smudged or not.""" + pointer = subprocess.check_output(["git", "show", f"HEAD:{path}"], text=True) + for line in pointer.splitlines(): + if line.startswith("oid sha256:"): + return line.split(":", 1)[1] + raise ValueError(f"No LFS OID found for {path}") + + class TestDefaultModel(OpenpilotTestCase): def test_compare_onnx_hashes(self): supercombo_hash = get_file_hash(SUPERCOMBO_ONNX_PATH) @@ -21,3 +34,15 @@ class TestDefaultModel(OpenpilotTestCase): current_hash = f.read().strip() assert combined_hash == current_hash, "Run openpilot/sunnypilot/models/default_model.py to update the default model name and hash" + + def test_compare_big_onnx_hashes(self): + if not os.path.exists(BIG_SUPERCOMBO_ONNX_PATH): + self.skipTest("big_driving_supercombo.onnx not present") + + oid = _get_lfs_oid(os.path.relpath(BIG_SUPERCOMBO_ONNX_PATH, os.getcwd())) + combined_hash = hashlib.sha256(oid.encode()).hexdigest() + + with open(BIG_MODEL_HASH_PATH) as f: + current_hash = f.read().strip() + + assert combined_hash == current_hash, "Run openpilot/sunnypilot/models/default_model.py to update the default model name and hash"