Graph serialization is the process of converting a computational graph—a data structure representing a neural network's operations and data dependencies—and its associated metadata (weights, attributes, tensor shapes) into a persistent, platform-independent byte stream format for storage or transmission. This serialized artifact, often called a model file (e.g., ONNX, TensorFlow SavedModel, TorchScript), serves as the definitive, versioned representation of a trained model, enabling deployment across diverse hardware and software environments. The process involves encoding the graph's topology, operator types, and constant parameters into a standardized schema.
Glossary
Graph Serialization

What is Graph Serialization?
Graph serialization is a fundamental step in the machine learning compilation pipeline, converting a computational graph into a portable, persistent format.
For NPU acceleration, serialization is critical for the ahead-of-time (AOT) compilation workflow. A serialized graph is ingested by a vendor's proprietary compiler toolchain (e.g., NVIDIA's TensorRT, Google's Edge TPU Compiler), which performs hardware-specific optimizations like kernel fusion and memory planning before generating an executable binary. Common serialization formats include Protocol Buffers, FlatBuffers, and MessagePack, chosen for their efficiency, backward/forward compatibility, and language neutrality. This creates a clean separation between model development frameworks and deployment runtimes.
Key Components of a Serialized Graph
A serialized graph is not a monolithic blob but a structured archive containing distinct, essential components. These components work together to provide a complete, portable, and executable representation of a neural network.
Computational Graph Structure
The core component is the directed acyclic graph (DAG) defining the model's architecture. This includes:
- Nodes/Operators: Represent mathematical operations (e.g., Conv2D, MatMul, ReLU).
- Edges/Tensors: Represent the multi-dimensional data arrays flowing between operators.
- Attributes: Static parameters for each operator (e.g., kernel size, stride, padding). This structural definition is abstract and hardware-agnostic, describing what to compute, not how.
Model Parameters (Weights & Biases)
Serialization embeds the learned parameters of the model. This is the state acquired during training.
- Weights: The core matrices and filters for layers like convolutions and linear transformations.
- Biases: The additive constants applied in many layers. These are typically stored as raw binary blobs of floating-point or quantized integer data, often compressed. Their exact memory layout must be preserved for deterministic execution.
Tensor Metadata & Type Information
This component provides the semantic context for the raw tensor data.
- Data Types: Precision of each tensor (e.g., FP32, FP16, INT8).
- Tensor Shapes: Static or dynamic dimensions (e.g.,
[batch, channels, height, width]). - Tensor Names: Human-readable identifiers for inputs, outputs, and intermediates, crucial for runtime binding. This metadata enables the runtime to allocate correct memory buffers and validate graph execution.
Versioning & Framework Metadata
Serialization formats include provenance information to ensure compatibility and traceability.
- Producer Information: The framework and version that created the graph (e.g., PyTorch 2.1, TensorFlow 2.13).
- Format Version: The specific version of the serialization protocol itself.
- Model Signature: A formal definition of the model's inputs and outputs, including expected names and types. This is critical for deployment toolchains.
Optimization & Execution Hints
Advanced serialization may include hardware-aware directives to guide the deployment runtime.
- Fused Operator Patterns: Annotations indicating groups of nodes that are candidates for kernel fusion.
- Preferred Data Layouts: Hints for memory format (e.g., NCHW vs. NHWC) to avoid costly runtime transformations.
- Quantization Parameters: Scales and zero-points for quantized tensors. These hints bridge the gap between the abstract graph and efficient hardware execution.
Graph Serialization
Graph serialization is the foundational process for persisting and exchanging neural network models, enabling deployment across diverse hardware and software environments.
Graph serialization is the process of converting a computational graph—including its operators, tensor data, and metadata—into a persistent, platform-independent byte stream format for storage or transmission. This byte stream, often called a model file or graph protocol buffer, serves as the definitive, portable representation of a trained neural network. Serialization enables critical workflows like model checkpointing during training, sharing between researchers, and deployment to production inference servers. Common serialization formats include ONNX, TensorFlow's SavedModel, and PyTorch's TorchScript, each providing a standardized schema for graph structure, parameters, and execution semantics.
Within NPU acceleration, serialization is the crucial output of the graph compilation pipeline. After a high-level framework graph undergoes optimizations like graph fusion and constant folding, the compiler serializes the final, hardware-optimized graph into a vendor-specific binary format. This serialized artifact contains not just the graph structure but also the compiled kernel code and memory plans tailored for the target accelerator. The runtime system then deserializes this binary to execute the model efficiently, separating the costly compilation phase from low-latency inference. Effective serialization thus bridges the gap between flexible model development and deterministic, high-performance deployment on specialized silicon.
Common Serialization Formats & Frameworks
Graph serialization converts a computational graph and its metadata into a persistent, platform-independent byte stream for storage or transmission. This is a critical step for deploying optimized models to NPUs and other accelerators.
Framework-Specific Formats
Major ML frameworks provide their own serialization formats, often combining graph structure and weights into a single archive.
- PyTorch TorchScript (
.pt/.pth): Serializes a PyTorch model's code and state via Python'spicklemodule, often combined with TorchScript's intermediate representation for graph capture. - TensorFlow SavedModel: A directory containing a protobuf file (
saved_model.pb) storing theMetaGraphDef, and a subdirectory (variables/) storing checkpointed weights. It's the standard for serving. - JAX Flax Checkpoints: Often use
msgpackor TensorFlow'stf.train.Checkpointformat viaorbax-checkpointto serialize the model state dictionary (parameters) separately from the functional model code.
These formats are typically the starting point before conversion to more deployment-oriented formats like ONNX or TFLite.
Considerations for NPU Deployment
Serialization for NPU targets involves unique requirements beyond simple persistence.
- Hardware-Specific Annotations: The serialized graph may need to embed vendor-specific attributes (e.g.,
#tpu,#npu.core_assignment) to guide later compilation stages. - Quantization Information: Must preserve quantization parameters (scale/zero-point) for INT8/INT4 weights and activations, often stored as metadata alongside tensors.
- Static Graph Requirements: Most NPU compilers require a static graph—all tensor shapes must be inferable at serialization/compile time. Dynamic shapes complicate this process.
- Separated Weights: For very large models, weights may be serialized in a separate, indexable file (like safetensors) to allow memory-mapped loading, reducing RAM pressure on the host before NPU transfer.
The serialized artifact is the input to the vendor's proprietary compiler toolchain (e.g., NVIDIA's TensorRT, Google's Edge TPU Compiler, Qualcomm's AI Engine Direct).
Comparison: Serialization vs. Related Compiler Concepts
This table distinguishes graph serialization from other core compiler transformations and strategies used in NPU graph compilation. It clarifies their distinct purposes, scopes, and outputs.
| Feature / Aspect | Graph Serialization | Graph Lowering | Graph Canonicalization | Intermediate Representation (IR) |
|---|---|---|---|---|
Primary Purpose | Convert a computational graph into a persistent, portable byte stream for storage/transmission. | Transform a high-level graph into a lower-level, hardware-specific representation. | Rewrite a graph into a standard, simplified form to eliminate syntactic variations. | Serve as an internal, machine-independent data structure for analysis and transformation. |
Key Output | Platform-independent file (e.g., .onnx, .tflite). | Lower-level graph (e.g., vendor-specific operator set, buffer descriptors). | Canonicalized graph with standardized operator patterns. | IR code/objects (e.g., LLVM IR, MLIR dialects). |
Scope of Change | Non-destructive encoding; aims for perfect round-trip fidelity. | Destructive transformation; changes abstraction level and operator semantics. | Semantics-preserving transformation; changes graph structure for consistency. | Representational layer; the graph is an IR or exists within an IR. |
Typical Phase in Compilation | Final step (for export) or initial step (for loading). | Mid-to-late pipeline, after high-level optimizations. | Early pipeline, as a normalization step before major optimizations. | Core abstraction used throughout the entire compilation pipeline. |
Hardware Dependence | Minimal; format is designed for cross-platform portability. | High; target is a specific hardware backend or instruction set. | None; transformation is purely based on algebraic/structural rules. | Variable; IR can be abstract (machine-independent) or lowered (machine-specific). |
Optimization Role | Enabler for deployment and interchange; not an optimization per se. | Enabler for hardware-specific optimizations and code generation. | Enabler for reliable optimization by providing a predictable input form. | Framework for expressing and applying all compiler optimizations. |
Data Included | Graph structure, operator types, initial weights, metadata. | Graph structure, legalized operators, memory layout constraints. | Graph structure and normalized operators. | Graph structure, operations, types, and dataflow dependencies. |
Reversibility | Designed to be fully reversible (deserialization). | Generally irreversible; information is lost in lowering. | Reversible in principle, but not typically required. | Transformations applied to IR may be reversible or irreversible. |
Frequently Asked Questions
Graph serialization is the critical process of converting a neural network's computational graph—its structure, operations, and parameters—into a persistent, portable format. This enables storage, transmission, and deployment across diverse hardware and software environments. Below are key questions about its mechanisms, formats, and role in the NPU compilation pipeline.
Graph serialization is the process of converting a computational graph and its associated metadata—including operator definitions, tensor weights, and attributes—into a persistent, platform-independent byte stream format for storage or transmission. It is essential for NPU deployment because it creates a stable, versioned artifact that can be compiled, optimized, and executed on specialized hardware without dependency on the original training framework. This serialized graph serves as the Single Source of Truth (SSOT) for the model's architecture and parameters, enabling deterministic reproduction, efficient over-the-air updates, and secure distribution to edge devices. Without a robust serialization format, deploying optimized models to heterogeneous NPU architectures at scale would be impractical.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Graph serialization is a critical step within the broader graph compilation pipeline. These related concepts define the transformations, analyses, and optimizations that occur before and after serialization to produce an efficient, deployable model.
Intermediate Representation (IR)
An Intermediate Representation is a compiler's internal, abstract data structure used to represent a program between its high-level source form and low-level machine code. For neural networks, the IR captures the computational graph, enabling machine-independent analysis and transformations.
- Purpose: Serves as a common language for multiple optimization passes.
- Examples: LLVM IR, MLIR dialects, ONNX graph representation.
- Relation to Serialization: The optimized IR is the primary input to the serialization process, which encodes it into a persistent byte stream format like ONNX or TensorFlow SavedModel.
Graph Canonicalization
Graph canonicalization is a compiler transformation that rewrites a computational graph into a standard, simplified form. It eliminates syntactic variations (e.g., different operator names for the same function) to make subsequent analysis and optimization passes more effective and predictable.
- Key Benefit: Ensures deterministic optimization outcomes.
- Common Actions: Standardizing operator names, flattening nested structures, removing identity operations.
- Pipeline Order: Typically occurs early in the compilation pipeline, before major optimizations and serialization.
Static Shape Inference
Static shape inference is a compiler analysis that determines the dimensions (shape) of all tensors in a computational graph at compile time. This is crucial for memory planning and enabling certain optimizations before execution.
- Enables: Precise static memory allocation, kernel selection, and validation.
- Contrast with Dynamic Shapes: Graphs with fully static shapes are often more efficiently optimized and serialized.
- Serialization Role: Inferred shape metadata is a key component serialized alongside the graph structure, informing the runtime about buffer sizes.
Memory Planning
Memory planning is a compiler optimization pass that allocates memory buffers for tensors in a computational graph. It aims to minimize peak memory usage through techniques like buffer reuse and in-place operations.
- Objective: Reduce device memory footprint for deployment on constrained hardware (e.g., NPUs, mobile).
- Techniques: Liveness analysis, in-place optimization, shared memory allocation.
- Serialization Output: The memory plan may be explicitly encoded in the serialized format or left for the runtime to recompute using the serialized graph metadata.
Graph Lowering
Graph lowering is the process of transforming a high-level, abstract computational graph representation into a lower-level, more hardware-specific representation. This occurs through a series of legalization and conversion passes.
- Purpose: Bridge the gap between framework-level operators and hardware-specific kernels or primitives.
- Multi-Stage Process: May progress from a framework graph (e.g., PyTorch) to a vendor-specific graph (e.g., for a specific NPU).
- Final Stage: The fully lowered graph, targeting a specific execution backend, is what is ultimately serialized for deployment.
Ahead-Of-Time (AOT) Compilation
Ahead-Of-Time compilation is a strategy where source code or an intermediate representation is fully compiled into a native machine code binary before execution. This eliminates runtime compilation overhead, providing predictable performance.
- Contrast with JIT: AOT trades runtime flexibility for startup speed and determinism.
- NPU Context: Essential for embedded and edge NPU deployment where runtime compilers are unavailable or too costly.
- Serialization Link: The final output of an AOT compilation pipeline for an NPU is often a serialized graph and the compiled kernel binaries, packaged together into a deployable artifact.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us