"""Run the packaged model on synthetic inputs and reuse its next state.""" import mlx.core as mx from model import Model def main(): mx.set_default_device(mx.cpu) model = Model() states = model.initial_state() inputs = {name: mx.zeros(shape, dtype) for name, (shape, dtype) in model.inputs.items() if name not in states} if "traffic_convention" in inputs: shape, dtype = model.inputs["traffic_convention"] inputs["traffic_convention"] = mx.array([1, 0], dtype=dtype).reshape(shape) if "action_t" in inputs: inputs["action_t"] = mx.array([[0.2, 0.3]], dtype=mx.float32) for _ in range(2 if states else 1): outputs = model(**inputs, **states) mx.eval(*outputs.values()) states = {name: outputs[f"next_{name}"] for name in states} print({name: (value.shape, str(value.dtype)) for name, value in outputs.items()}) for head in model.graph["output_slices"]: tensor = head.get("tensor", "outputs") values = outputs[tensor][..., head["start"]:head["stop"]] print(head["name"], values.shape, values[0, 0].item()) if __name__ == "__main__": main()