{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# For tips on running notebooks in Google Colab, see\n",
    "# https://docs.pytorch.org/tutorials/beginner/colab\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Introduction to ONNX** \\|\\| [Exporting a PyTorch model to\n",
    "ONNX](export_simple_model_to_onnx_tutorial.html) \\|\\| [Extending the\n",
    "ONNX exporter operator support](onnx_registry_tutorial.html) \\|\\|\n",
    "[Export a model with control flow to\n",
    "ONNX](export_control_flow_model_to_onnx_tutorial.html)\n",
    "\n",
    "# Introduction to ONNX\n",
    "\n",
    "Authors: [Ti-Tai Wang](https://github.com/titaiwangms), [Thiago\n",
    "Crepaldi](https://github.com/thiagocrepaldi).\n",
    "\n",
    "[Open Neural Network eXchange (ONNX)](https://onnx.ai/) is an open\n",
    "standard format for representing machine learning models. The\n",
    "`torch.onnx` module provides APIs to capture the computation graph from\n",
    "a native PyTorch `torch.nn.Module`{.interpreted-text role=\"class\"} model\n",
    "and convert it into an [ONNX\n",
    "graph](https://github.com/onnx/onnx/blob/main/docs/IR.md).\n",
    "\n",
    "The exported model can be consumed by any of the many [runtimes that\n",
    "support ONNX](https://onnx.ai/supported-tools.html#deployModel),\n",
    "including Microsoft\\'s [ONNX Runtime](https://www.onnxruntime.ai).\n",
    "\n",
    "When setting `dynamo=True`, the exporter will use\n",
    "[torch.export](https://pytorch.org/docs/stable/export.html) to capture\n",
    "an `ExportedProgram`, before translating the graph into ONNX\n",
    "representations. This approach is the new and recommended way to export\n",
    "models to ONNX. It works with PyTorch 2.0 features more robustly, has\n",
    "better support for newer ONNX operator sets, and consumes less resources\n",
    "to make exporting larger models possible.\n",
    "\n",
    "## Dependencies\n",
    "\n",
    "PyTorch 2.5.0 or newer is required.\n",
    "\n",
    "The ONNX exporter depends on extra Python packages:\n",
    "\n",
    "> -   [ONNX](https://onnx.ai) standard library\n",
    "> -   [ONNX Script](https://microsoft.github.io/onnxscript/) library\n",
    ">     that enables developers to author ONNX operators, functions and\n",
    ">     models using a subset of Python in an expressive, and yet simple\n",
    ">     fashion\n",
    "> -   [ONNX Runtime](https://onnxruntime.ai) accelerated machine\n",
    ">     learning library.\n",
    "\n",
    "They can be installed through [pip](https://pypi.org/project/pip/):\n",
    "\n",
    "``` bash\n",
    "pip install --upgrade onnx onnxscript onnxruntime\n",
    "```\n",
    "\n",
    "To validate the installation, run the following commands:\n",
    "\n",
    "``` python\n",
    "import torch\n",
    "print(torch.__version__)\n",
    "\n",
    "import onnxscript\n",
    "print(onnxscript.__version__)\n",
    "\n",
    "import onnxruntime\n",
    "print(onnxruntime.__version__)\n",
    "```\n",
    "\n",
    "Each [import]{.title-ref} must succeed without any errors and the\n",
    "library versions must be printed out.\n",
    "\n",
    "## Further reading\n",
    "\n",
    "The list below refers to tutorials that ranges from basic examples to\n",
    "advanced scenarios, not necessarily in the order they are listed. Feel\n",
    "free to jump directly to specific topics of your interest or sit tight\n",
    "and have fun going through all of them to learn all there is about the\n",
    "ONNX exporter.\n",
    "\n",
    "::: {.toctree hidden=\"\"}\n",
    ":::\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
