Inferensys

Glossary

Graph Serialization

Graph serialization is the process of converting a neural network's computational graph and its metadata into a persistent, platform-independent byte stream for storage, transmission, or deployment.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
GLOSSARY

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.

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.

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.

GRAPH SERIALIZATION

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.

01

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.
02

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.
03

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.
04

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.
05

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 COMPILATION STRATEGIES

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.

GRAPH SERIALIZATION

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.

05

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's pickle module, often combined with TorchScript's intermediate representation for graph capture.
  • TensorFlow SavedModel: A directory containing a protobuf file (saved_model.pb) storing the MetaGraphDef, and a subdirectory (variables/) storing checkpointed weights. It's the standard for serving.
  • JAX Flax Checkpoints: Often use msgpack or TensorFlow's tf.train.Checkpoint format via orbax-checkpoint to 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.

06

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).

COMPILER OPTIMIZATION CONTEXT

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 / AspectGraph SerializationGraph LoweringGraph CanonicalizationIntermediate 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.

GRAPH SERIALIZATION

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.

Prasad Kumkar

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.