To guarantee the dataset’s overall quality, reproducibility, and cross-compiler compatibility, we define the following construction constraints:
- Computation graphs must be executable in imperative (eager) mode.
- Computation graphs and their corresponding Python code must support serialization and deserialization.
- The full graph can be decomposed into two disjoint subgraphs.
- Operator names within each computation graph must be statically parseable.
- If custom operators are used, their implementation code must be fully accessible.
GraphNet provides automated tools for graph extraction and validation.
Demo: Extract & Validate ResNet‑18
git clone https://github.com/PaddlePaddle/GraphNet.git
cd GraphNet
# Set your workspace directory
export GRAPH_NET_EXTRACT_WORKSPACE=/home/yourname/graphnet_workspace/
# Extract the ResNet‑18 computation graph
python graph_net/test/vision_model_test.py
# Validate the extracted graph (e.g.,/home/yourname/graphnet_workspace/resnet18/)
python -m graph_net.torch.validate \
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/resnet18/Illustration – Extraction Workflow
- Source code of custom_op is required only when corresponding operator is used in the module, and no specific format is required.
Step 1: graph_net.torch.extract
Wrap the model with the extractor — that’s all you need:
import graph_net
# Instantiate the model (e.g., a torchvision model)
model = ...
# Extract your own model
model = graph_net.torch.extract(name="model_name", dynamic=True)(model)After running, the extracted graph will be saved to: $GRAPH_NET_EXTRACT_WORKSPACE/model_name/.
For more details, see docstring of graph_net.torch.extract defined in graph_net/torch/extractor.py.
Step 2: graph_net.torch.validate
To verify that the extracted model meets requirements, we use graph_net.torch.validate in the CI tool and also ask contributors to self-check in advance:
python -m graph_net.torch.validate \
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/model_nameAll construction constraints will be examined automatically. After passing validation, a unique graph_hash.txt will be generated and later checked in the CI procedure to avoid redundancy.
This repository is organized as follows:
| Directory | Description |
|---|---|
| graph_net/ | Core module for graph extraction, validation, and benchmarking |
| paddle_samples/ | Computation graph samples extracted from PaddlePaddle |
| samples/ | Computation graph samples extracted from PyTorch |
| docs/ | Technical documents and contributor guides |
Below is the structure of the graph_net/:
graph_net/
├─ config/ # Config files, params
├─ paddle/ # PaddlePaddle graph extraction & validation
├─ torch/ # PyTorch graph extraction & validation
├─ test/ # Unit tests and example scripts
└─ *.py # Benchmark & analysis scripts

