From cbd075288c6788d695839ed6f25f72fecaa1bbb2 Mon Sep 17 00:00:00 2001 From: James Vecellio-Grant <159560811+Discountchubbs@users.noreply.github.com> Date: Mon, 31 Aug 2026 21:15:23 -0700 Subject: [PATCH] modeld_v2: big to small model fallback (#1974) --- .../modeld_v2/tests/test_fallback.py | 83 ++----------------- 1 file changed, 9 insertions(+), 74 deletions(-) diff --git a/openpilot/sunnypilot/modeld_v2/tests/test_fallback.py b/openpilot/sunnypilot/modeld_v2/tests/test_fallback.py index 9c40e5973..1cc8410f0 100644 --- a/openpilot/sunnypilot/modeld_v2/tests/test_fallback.py +++ b/openpilot/sunnypilot/modeld_v2/tests/test_fallback.py @@ -1,6 +1,12 @@ +""" +Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. + +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 io import requests -from unittest import mock from openpilot.common.file_chunker import get_chunk_name from openpilot.common.hardware import hw @@ -22,8 +28,8 @@ class TestFallback(OpenpilotTestCase): (tmp_path / tsfdo_file).write_bytes(b'dskfajklsdjlsfka') monkeypatch.setattr(hw.Paths, 'model_root', staticmethod(lambda: str(tmp_path))) - big_bundle = DummyBundle(models=[DummyModel('supercombo', lebowski_file)], is_big=True) - small_bundle = DummyBundle(models=[DummyModel('supercombo', tsfdo_file)], is_big=False) + big_bundle = DummyBundle(models=[DummyModel('supercombo', lebowski_file)]) + small_bundle = DummyBundle(models=[DummyModel('supercombo', tsfdo_file)]) big_pkl = modeld_module._find_driving_pkl(big_bundle) small_pkl = modeld_module._find_driving_pkl(small_bundle) @@ -54,74 +60,3 @@ class TestFallback(OpenpilotTestCase): assert modeld_module.ModelState(CAM_W, CAM_H, chestnut=True).chestnut is True except Exception as e: assert "AMD" in str(e) or "device" in str(e).lower() - - def test_runtime_fallback_from_big_to_small(self): - params = mock.MagicMock() - params.get_bool.return_value = True - - big = mock.MagicMock(chestnut=True) - big.run.side_effect = RuntimeError("eGPU error") - - small = mock.MagicMock(chestnut=False) - small.run.return_value = {"plan": []} - - chestnut = mock.MagicMock(big=True) - model, run_count = big, 50 - - try: - model.run() - except Exception: - if not params.get_bool("chestnutActive"): - raise - params.put_bool("chestnutActive", False) - model = small - chestnut.big = False - run_count = 0 - - assert model is small - assert not chestnut.big - assert run_count == 0 - params.put_bool.assert_called_with("chestnutActive", False) - - model.run() - small.run.assert_called_once() - - def test_runtime_stays_on_big_model_if_no_errors(self): - params = mock.MagicMock() - params.get_bool.return_value = True - - big = mock.MagicMock(chestnut=True) - big.run.return_value = {"plan": [1, 2, 3]} - - small = mock.MagicMock(chestnut=False) - chestnut = mock.MagicMock(big=True) - model, run_count = big, 50 - try: - model.run() - except Exception: - if not params.get_bool("ChestnutActive"): - raise - params.put_bool("ChestnutActive", False) - model = small - chestnut.big = False - run_count = 0 - - assert model is big - assert chestnut.big is True - assert run_count == 50 - params.put_bool.assert_not_called() - small.run.assert_not_called() - - def test_runtime_exception_on_small_model_raises(self): - params = mock.MagicMock() - params.get_bool.return_value = False - - model = mock.MagicMock(chestnut=False) - model.run.side_effect = RuntimeError("CPU error") - - with self.assertRaises(RuntimeError): - try: - model.run() - except Exception: - if not params.get_bool("ChestnutActive"): - raise