{ "cells": [ { "cell_type": "markdown", "id": "595ea0614f62df9", "metadata": {}, "source": "# Command Line Usage" }, { "cell_type": "markdown", "id": "adba064bef83d8fe", "metadata": {}, "source": [ "To know what passes to run, what are its inputs, outputs and arguments, olive uses **run configurations**.\n", "A run configuration is a JSON file that you pass to the command-line tool, and it defines the entire workflow.\n", "\n", "If you already have your own configuration file, update the path in the examples below accordingly.\n", "If not, an example configuration is provided for you to download and review." ] }, { "cell_type": "markdown", "id": "a7ce4104c7eb0255", "metadata": {}, "source": "## 1. Prepare configuration" }, { "cell_type": "code", "id": "21de07739f7c7eff", "metadata": {}, "source": [ "from pathlib import Path\n", "import requests\n", "\n", "# Change this if you have your own model.\n", "config_path = Path(\"my_path_to_config.json\")" ], "outputs": [], "execution_count": null }, { "cell_type": "code", "id": "10fef7c018520dd8", "metadata": {}, "source": [ "# Alternatively download example model.\n", "example_config_url = \"https://eiq.nxp.com/training-materials/_misc/config.json\"\n", "\n", "with open(config_path, \"wb\") as f:\n", " response = requests.get(\n", " url=example_config_url\n", " )\n", " f.write(response.content)\n", "\n", " if response.status_code != 200:\n", " print(f\"Failed to download model: {response.content}\")\n", " else:\n", " print(f\"Configuration file downloaded and saved to {config_path} file.\")\n" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "id": "953de5657b3a49df", "metadata": {}, "source": [ "The example JSON file contains the configuration shown below.\n", "The first part of the configuration defines the input model for the entire workflow.\n", "Notice that the path is set to `input_model.onnx`. In the next step, we download this model and use it with the `eiq-olive` package.\n", "If you want to use your own model instead, make sure to update the path in the configuration file.\n", "\n", "The next section of the configuration file describes the passes applied to the input model.\n", "\n", "In this example, the workflow uses:\n", "\n", "* TFLiteConversion pass — converts the input ONNX model into a TFLite model\n", "* VelaConversion pass — converts the resulting TFLite model for deployment on the i.MX 93 NPU\n", "\n", "For more details on specific passes and their available parameters, see the [Conversion and Quantization](../../convQuant/index.rst) guide." ] }, { "cell_type": "markdown", "id": "85fe691bc6c08b60", "metadata": {}, "source": [ "```json\n", "{\n", " \"input_model\": {\n", " \"type\": \"onnxmodel\",\n", " \"config\": {\n", " \"model_path\": \"input_model.onnx\"\n", " }\n", " },\n", " \"systems\": {\n", " \"local_system\": {\n", " \"type\": \"LocalSystem\"\n", " }\n", " },\n", " \"passes\": {\n", " \"0\": [\n", " {\n", " \"type\": \"TFLiteConversion\",\n", " \"config\": {}\n", " }\n", " ],\n", " \"1\": [\n", " {\n", " \"type\": \"VelaConversion\",\n", " \"config\": {}\n", " }\n", " ]\n", " },\n", " \"engine\": {\n", " \"log_severity_level\": 0,\n", " \"host\": \"local_system\",\n", " \"target\": \"local_system\",\n", " \"evaluate_input_model\": false,\n", " \"clean_cache\": true,\n", " \"cache_dir\": \"cache_dir\",\n", " \"output_dir\": \"models_dir\"\n", " }\n", "}\n", "\n", "```" ] }, { "cell_type": "markdown", "id": "56737f2f71186db5", "metadata": {}, "source": "## 2. Prepare model" }, { "cell_type": "markdown", "id": "a1e30b904b8d102", "metadata": {}, "source": [ "Now we download an example model to use in the conversion workflow.\n", "If you prefer to use your own model, simply set the path to its location and remember to update the JSON configuration file accordingly." ] }, { "cell_type": "code", "id": "975c4ba912c58e6d", "metadata": {}, "source": [ "model_path = Path(\"input_model.onnx\")" ], "outputs": [], "execution_count": null }, { "cell_type": "code", "id": "b84b5beb5cd17479", "metadata": {}, "source": [ "example_model_url = \"https://eiq.nxp.com/training-materials/_misc/models/quantized_model.onnx\"\n", "\n", "with open(model_path, \"wb\") as f:\n", " response = requests.get(\n", " url=example_model_url\n", " )\n", " f.write(response.content)\n", "\n", " if response.status_code != 200:\n", " print(f\"Failed to download model: {response.content}\")\n", " else:\n", " print(f\"Model downloaded and saved to {model_path} file.\")" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "id": "6e8d82fcee233f64", "metadata": {}, "source": "## 3. Run workflow" }, { "cell_type": "markdown", "id": "9a31c06cc68b7597", "metadata": {}, "source": "With both the model and the configuration file ready, we can now run the conversion workflow." }, { "cell_type": "code", "id": "377377b30c112dfc", "metadata": {}, "source": [ "!python -m olive run --run-config $config_path" ], "outputs": [], "execution_count": null }, { "cell_type": "markdown", "id": "74a8fa50837c4d3e", "metadata": {}, "source": "If you want to see additional command‑line options, run:" }, { "cell_type": "code", "id": "88e25ae275cdfaea", "metadata": {}, "source": [ "!python -m olive run -h\n", "!python -m olive -h" ], "outputs": [], "execution_count": null } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.12" } }, "nbformat": 4, "nbformat_minor": 5 }