INNER CODE UNIT · Python
run
onnxsim/onnxsim · onnxsim/rpc/server.py:74
def run(self, inputs: Dict[str, np.ndarray]) -> Dict[str, np.ndarray]:
if self.session is not None:
names = [o.name for o in self.session.get_outputs()]
return dict(zip(names, self.session.run(None, inputs)))
from onnxsim import backend
return dict(backend.run_model(model_bytes_to_proto(self.model_bytes), inputs))
class _TinygradRunner:
"""Runs a model with tinygrad's ONNX frontend on a chosen tinygrad device.
Exists so tinygrad's code generation can be benchmarked on the server's hardware through the
same session API. ``options`` are tinygrad codegen knobs (an allow-list, e.g. ``{"BEAM": 2}``)
applied around compilation and execution. The frontend caches Python constants between calls,
so this suits static-shape models; a graph with data-dependent shapes needs a fresh load per
input.
"""