Files
2026-04-24 08:30:50 -05:00

26 lines
1.0 KiB
Python

from openpilot.iqpilot.models.helpers import get_active_bundle
from openpilot.iqpilot.models.runners.model_runner import ModelRunner
from openpilot.iqpilot.models.runners.tinygrad.tinygrad_runner import TinygradRunner, TinygradSplitRunner
from openpilot.iqpilot.models.runners.constants import ModelType
def get_model_runner() -> ModelRunner:
"""
Factory function to create and return the appropriate ModelRunner instance.
Selects TinygradRunner, choosing TinygradSplitRunner if separate vision/policy
models are detected in the active bundle.
:return: An instance of a ModelRunner subclass (ONNXRunner, TinygradRunner, or TinygradSplitRunner).
"""
bundle = get_active_bundle()
if bundle and bundle.models:
model_types = {m.type.raw for m in bundle.models}
split_types = {ModelType.vision, ModelType.policy, ModelType.offPolicy, ModelType.onPolicy}
if model_types & split_types:
return TinygradSplitRunner()
if bundle.models:
return TinygradRunner(bundle.models[0].type.raw)
return TinygradRunner(ModelType.supercombo)