MWONGOZO wa Kiufundi

ONNX na Ushirikiano wa Mfano

ONNX (Open Neural Network Exchange) is an open file format and operator standard for machine learning models, announced by Facebook and Microsoft in September 2017 and now governed by the Linux Foundation.

Sikiliza mwongozo huuInaonyeshwa na AI · ~8 min

Katika ukurasa huudk 9 kusoma
  1. Muhtasari
  2. Mambo muhimu ya kuchukua
  3. Dive ya kina
  4. Exporting and checking a small PyTorch model
  5. Utekelezaji wa Ulimwengu Halisi
  6. Mustakabali wa ONNX na Ushirikiano wa Mfano
  7. Kuiweka katika vitendo
  8. Vyanzo na kusoma zaidi
  9. Endelea Kuchunguza
  10. Maswali yanayoulizwa mara kwa mara

Muhtasari

It lets a model trained in one framework, such as PyTorch, be saved as a portable computation graph and run by a different engine on servers, phones, browsers or specialized chips.

Mambo muhimu ya kuchukua

  1. ONNX is an open format that stores a trained model as a graph of standardized operators plus its weights, so different engines can run it.
  2. Facebook and Microsoft announced ONNX in September 2017, and it became a Linux Foundation AI graduate project in November 2019.
  3. Every ONNX model declares versioned operator sets, and any change to an operator's behavior must ship as a new operator version.
  4. ONNX Runtime splits a model across hardware execution providers such as CUDA, TensorRT, DirectML, OpenVINO and QNN, with CPU as the fallback.
  5. Models larger than the 2 GB Protocol Buffers limit store their weights in external data files next to the graph.

Dive ya kina

ONNX, the Open Neural Network Exchange, is a shared language for describing trained machine learning models. A model in ONNX form is a computation graph: a list of operations, such as matrix multiplication, convolution or softmax, connected by the tensors (multi-dimensional arrays of numbers) that flow between them, together with the learned weights. Because the graph uses a standard set of operators with precisely defined behavior, any software that implements those operators can run the model, regardless of which framework trained it. This separation of training from deployment is what model interoperability means in practice.

The format is defined by the ONNX intermediate representation (IR) specification and stored as a Protocol Buffers file, a compact binary encoding developed by Google. The top-level object is a model, which records the IR version, the operator sets it relies on, metadata such as the producing tool, and the graph. The graph holds nodes, each naming an operator type, its inputs, its outputs and fixed attributes such as a convolution's kernel size. Initializers store constant tensors, usually the weights. Inputs and outputs are declared with a data type and shape, and a dimension can be a symbolic name such as batch_size instead of a fixed number. The specification requires nodes to be listed in topological order, so every value is produced before it is used, with no cycles, and every output name must be unique within a graph.

Versioning is the part of ONNX that makes long-term compatibility possible. Operators are grouped into operator sets, or opsets, identified by a domain and an integer version. The default domain covers neural network operators, and ONNX-ML adds operators for classical, non-neural machine learning algorithms. Every model must declare the opsets it uses. Under the versioning rules, any change to an operator's inputs, outputs, attributes, supported types or meaning is a breaking change that must appear as a new operator version in a new opset. A runtime that supports opset 17 therefore knows exactly what every operator in an opset 17 model does. The ONNX versioning table runs from ONNX 1.0, with IR version 3 and opset 1, to ONNX 1.23.0, with IR version 14 and opset 28.

ONNX began inside Facebook's PyTorch team under the name Toffee and was renamed and announced jointly by Facebook and Microsoft in September 2017. IBM, Huawei, Intel, AMD, Arm and Qualcomm later announced support, and in October 2017 Microsoft said it would bring its Cognitive Toolkit and Project Brainwave into the effort. On November 14, 2019, the format became a graduate project of the Linux Foundation's LF AI Foundation, which TechCrunch described as a step toward vendor-neutral governance, with more than 30 companies contributing code. The license moved from MIT to Apache 2.0. Only the format joined the foundation; ONNX Runtime, the inference engine Microsoft had open-sourced about a year earlier, stayed a separate Microsoft-led project.

In a typical workflow, a developer trains a model in PyTorch and calls torch.onnx.export. Since PyTorch 2.9, the default exporter is built on torch.export, which traces the model ahead of time into a graph of basic operations, removes most Python control flow and records shape constraints. The developer marks which dimensions may vary, such as batch size or text length, chooses an opset, and can ask the exporter to verify the result with ONNX Runtime. The resulting .onnx file is then loaded by a runtime. ONNX Runtime splits the graph among execution providers, plug-ins for specific hardware: each provider in a priority list claims the nodes it can run, and the default CPU provider runs whatever is left. Higher-level tools wrap this process; Hugging Face Optimum can export a Transformers model in one command, validate the outputs against the original, and split encoder-decoder models into separate files so the encoder runs once while the decoder loops.

ONNX is not the only way to move models around. Framework-native formats, such as PyTorch's saved programs, keep every framework feature but tie deployment to that framework's runtime. Vendor formats, such as compiled TensorRT engines, are faster on one family of hardware but are not portable. ONNX sits between them: broadly supported, with a stable specification, but limited to what its operators can express. Weight-only formats, which store tensors but not the computation graph, solve a different problem: sharing parameters for use in a framework that already knows the architecture.

The limits are real. Not every framework operation has an ONNX equivalent, so custom layers may need custom operators that only some runtimes support. Dynamic behavior is hard to capture: PyTorch's documentation notes that loops are not exported directly and points to explicit control-flow operators instead. If dynamic dimensions are not declared, the exporter freezes the example input's shapes, so a text model may only accept one length. Protocol Buffers files are limited to 2 GB, so larger models store their weights as external data files beside the graph. Optimizations can reduce portability: Optimum warns that some ONNX Runtime-specific graph optimizations produce files that OpenVINO or TensorRT cannot run. Small numerical differences between runtimes are normal, which is why exporters compare outputs within a tolerance instead of expecting exact matches.

In practice ONNX costs nothing to use: the format, the onnx Python package and ONNX Runtime are open source. The real costs are engineering time to make a model export cleanly, testing on each target runtime, and keeping the opset version aligned with what the deployment engine supports. ONNX Runtime offers APIs for Python, C#, JavaScript, Java and C++, among others, and runs on Linux, Windows, macOS, iOS, Android and in web browsers.

04Mfano uliofanya kazi

Exporting and checking a small PyTorch model

  1. Build or load a small PyTorch image classifier and put it in evaluation mode.

  2. Call torch.onnx.export with an example input of shape 1 by 3 by 224 by 224, and declare the batch dimension as dynamic using dynamic_shapes.

  3. Open the saved file with the onnx Python package and run its checker to confirm the graph is valid.

  4. Load the file in ONNX Runtime with the provider list CUDAExecutionProvider then CPUExecutionProvider.

  5. Feed the same random input with a batch of 4 to both PyTorch and ONNX Runtime.

  6. Compare outputs element by element and confirm the largest absolute difference is below a small tolerance such as 0.0001.

Nini inaonyesha

The learner has a portable .onnx file that accepts any batch size and produces the same predictions as the PyTorch model within a numerical tolerance. If the batch of 4 fails, the dynamic dimension was not declared, which is the most common export mistake.

Utekelezaji wa Ulimwengu Halisi

Microsoft products: the ONNX Runtime website says the engine powers AI features in Windows, Office, Azure Cognitive Services and Bing, running models that were exported to the ONNX format.

Hugging Face models: the command optimum-cli export onnx --model gpt2 gpt2_onnx/ exports a Transformers model, then checks that the ONNX outputs match the original within a tolerance such as 0.0001.

Hardware portability: one ONNX file can run on Nvidia GPUs through the CUDA or TensorRT execution providers, on Windows GPUs through DirectML, on Intel hardware through OpenVINO, or on Qualcomm chips through QNN.

In-browser and mobile inference: ONNX Runtime Web runs exported models inside a web browser, and ONNX Runtime Mobile targets Android and iOS apps, so no Python installation is needed on the device.

Framework handoff: Hugging Face's documentation gives the example of exporting a model trained in PyTorch to ONNX and then importing it into Nvidia TensorRT or Intel OpenVINO for optimized serving.

Mustakabali wa ONNX na Ushirikiano wa Mfano

The ONNX specification keeps expanding to cover newer workloads. The IR documentation records multi-device configuration support added in IR version 11, and the type list now includes 8-bit, 6-bit, 4-bit and 2-bit numeric formats used for compressed models, reflecting the shift toward running quantized language models on local hardware. The versioning table shows opset 28 shipping with ONNX 1.23.0. On the tooling side, PyTorch moved its default exporter to the torch.export-based path in version 2.9, deprecated older options such as dynamic_axes for that path, and removed the fallback to the older exporter in version 2.11. That transition aims to make exports more faithful to the original program, but models that rely on Python-level control flow still need rewriting with explicit control-flow operators. Open questions include how well a static graph format can represent large generative models whose inference involves caches, variable-length loops and sampling, which tools such as onnxruntime-genai and Optimum handle partly outside the graph, and how to keep hardware-specific optimizations from fragmenting a format whose value depends on portability. The number of execution providers listed by ONNX Runtime, spanning CPUs, GPUs, NPUs and browsers, suggests that hardware vendors still treat ONNX as a common entry point, though support levels vary and several providers are marked as previews.

Kuiweka katika vitendo

Kwa nini ni muhimu

  • Gharama na bajeti. Maamuzi ya usanifu huendesha utendaji na gharama ya uendeshaji kwa miaka.
  • Maamuzi ya wazi zaidi. Elimu ya kiufundi husaidia timu kuchagua safu sahihi, sio tu mpya zaidi.
  • Udhibiti wa ubora. Chaguo bora za uhandisi hupunguza matukio ya kuaminika katika uzalishaji.

Jihadharini na

  • Kuboresha kiwango kimoja kunaweza kuficha udhaifu mkubwa wa mfumo.
  • Gharama za miundombinu na matengenezo mara nyingi hupunguzwa.
  • Mapengo ya usalama na uonekanaji yanaweza kukua kadiri mifumo inavyozidi kuwa ngumu.

Hatua zinazofuata

  1. Bainisha muda, ubora na malengo ya gharama kabla ya utekelezaji.
  2. Benchmark chini ya mzigo halisi na hali ya data.
  3. Ufuatiliaji wa ala kwa makosa, kuteleza, na athari za mtumiaji.
  4. Tayarisha njia za urejeshaji na majibu ya matukio kabla ya kuongeza ukubwa.

Vyanzo na kusoma zaidi

  1. ONNX project, GitHubOpen Neural Network Exchange Intermediate Representation (ONNX IR) Specification
  2. ONNX project, GitHubONNX Versioning
  3. TechCrunchThe ONNX format becomes the newest Linux Foundation project
  4. ONNX Runtime documentationONNX Runtime Execution Providers
  5. MicrosoftMuda wa Kuendesha wa ONNX
  6. PyTorch documentationtorch.onnx
  7. Hugging FaceExport a model to ONNX with optimum.exporters.onnx
  8. WikipediaOpen Neural Network Exchange

Endelea Kuchunguza

Jarida halali

Pata taarifa ya kila siku ya AI

Hadithi tatu za AI zilizothibitishwa kila asubuhi ya wiki, zimetengenezwa kwa Kiingereza rahisi. Bila malipo daima, hakuna matangazo.

Barua pepe moja kila siku ya wiki. Jiondoe kwa bonyeza moja. Hatutauza au kushiriki anwani yako.

Jijaribu mwenyewe

Take the ONNX and Model Interoperability quiz

Maoni ya haraka juu ya kila jibu, na cheti kinachoweza kushirikishwa na kitambulisho kinachoweza kuthibitishwa baada ya kupita kozi.

Anza chemsha bongo

Changia elimu ya AI bila malipo. AI Understanding ni 501(c)(3) isiyo na faida — hakuna matangazo, hakuna kizuizi cha malipo, daima. Toa mchango

Maswali yanayoulizwa mara kwa mara

ONNX na Ushirikiano wa Mfano ni nini?

ONNX (Open Neural Network Exchange) is an open file format and operator standard for machine learning models, announced by Facebook and Microsoft in September 2017 and now governed by the Linux Foundation. It lets a model trained in one framework, such as PyTorch, be saved as a portable computation graph and run by a different engine on servers, phones, browsers or specialized chips.

Ni tatizo gani la msingi ambalo ONNX hutatua kimsingi?

ONNX inafafanua umbizo la pamoja ili kielelezo kilichofunzwa katika mfumo mmoja kiweze kutumwa katika mazingira mengine bila kuandikwa upya.

Je, faili ya ONNX inawakilishaje mfano?

Muundo wa ONNX ni grafu ya kukokotoa ambayo nodi zake ni waendeshaji sanifu (kama vile Conv, MatMul, Relu) zilizounganishwa na vipino.

What does the acronym ONNX stand for?

ONNX is short for Open Neural Network Exchange, the open format and ecosystem for representing machine-learning models.

Katika ONNX Runtime, 'mtoa huduma wa utekelezaji' ni nini?

Watoa huduma wa utekelezaji ni viambajengo vya nyuma vinavyoweza kuchomekwa (CPU, CUDA, TensorRT, na zaidi) ambazo ONNX Runtime hutumia kuendesha waendeshaji kila moja ikitumia vyema zaidi.

Toleo la 'opset' (seti ya kiendeshaji) katika modeli ya ONNX inafafanua nini?

Toleo la opset linabainisha ni seti gani iliyosanifishwa na toleo la waendeshaji ambalo muundo hutegemea, na kuhakikisha muda wa utekelezaji unaolingana unatafsiri kwa usahihi.