Skip to content

Commit 294e1dd

Browse files
committed
Merge branch 'develop' into add_cv_samples_5_need_fix
2 parents 8f46c3e + fd78a16 commit 294e1dd

File tree

1,185 files changed

+336665
-5111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,185 files changed

+336665
-5111
lines changed

.github/workflows/Validate-GPU.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
pull_request:
55
branches:
66
- develop
7+
paths:
8+
- "samples/**"
9+
- "paddle_samples/**"
710

811
env:
912
PR_ID: ${{ github.event.pull_request.number }}
@@ -31,7 +34,7 @@ jobs:
3134
with:
3235
ref: ${{ github.event.pull_request.base.ref }}
3336
submodules: 'recursive'
34-
fetch-depth: 1000
37+
fetch-depth: 10
3538

3639
- name: Check bypass
3740
id: check-bypass

GraphNet_technical_report.pdf

2.01 MB
Binary file not shown.

README.md

Lines changed: 72 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,41 @@
1-
# GraphNet ![](https://img.shields.io/badge/version-v0.1-brightgreen) ![](https://img.shields.io/github/issues/PaddlePaddle/GraphNet?label=open%20issues) [![](https://img.shields.io/badge/Contribute%20to%20GraphNet-blue)](https://github.com/PaddlePaddle/GraphNet/issues/98)
21

3-
**GraphNet** is a large-scale dataset of deep learning **computation graphs**, built as a standard benchmark for **tensor compiler** optimization. It provides 2.7K computation graphs extracted from state-of-the-art deep learning models spanning diverse tasks and ML frameworks. With standardized formats and rich metadata, GraphNet enables fair comparison and reproducible evaluation of the general optimization capabilities of tensor compilers, thereby supporting advanced research such as AI for System on compilers (AI for Compiler).
2+
<h1 align="center">GraphNet: A Large-Scale Computational Graph Dataset for Tensor Compiler Research</h1>
43

5-
<br>
64
<div align="center">
7-
<img src="/pics/Eval_result.png" alt="Violin plots of speedup distributions" width="65%">
8-
</div>
9-
10-
Compiler developers can use GraphNet samples to evaluate tensor compilers (e.g., CINN, TorchInductor, TVM) on target tasks. The figure above shows the speedup of two compilers (CINN and TorchInductor) across two tasks (CV and NLP).
11-
12-
## 🧱 Dataset Construction
13-
14-
To guarantee the dataset’s overall quality, reproducibility, and cross-compiler compatibility, we define the following construction **constraints**:
15-
16-
1. Computation graphs must be executable in imperative (eager) mode.
17-
2. Computation graphs and their corresponding Python code must support serialization and deserialization.
18-
3. The full graph can be decomposed into two disjoint subgraphs.
19-
4. Operator names within each computation graph must be statically parseable.
20-
5. If custom operators are used, their implementation code must be fully accessible.
215

22-
### Graph Extraction & Validation
23-
24-
We provide automated extraction and validation tools for constructing this dataset.
25-
26-
<div align="center">
27-
<img src="/pics/graphnet_overview.jpg" alt="GraphNet Architecture Overview" width="65%">
6+
![](https://img.shields.io/github/issues/PaddlePaddle/GraphNet?label=open%20issues)
7+
[![arXiv](https://img.shields.io/badge/arXiv-2510.24035-b31b1b.svg)](https://arxiv.org/abs/2510.24035)
8+
<a href="https://github.com/user-attachments/assets/125e3494-25c9-4494-9acd-8ad65ca85d03"><img src="https://img.shields.io/badge/微信-green?logo=wechat&amp"></a>
289
</div>
2910

30-
**Demo: Extract & Validate ResNet‑18**
31-
```bash
32-
git clone https://github.com/PaddlePaddle/GraphNet.git
33-
cd GraphNet
34-
35-
# Set your workspace directory
36-
export GRAPH_NET_EXTRACT_WORKSPACE=/home/yourname/graphnet_workspace/
37-
38-
# Extract the ResNet‑18 computation graph
39-
python graph_net/test/vision_model_test.py
40-
41-
# Validate the extracted graph (e.g. /home/yourname/graphnet_workspace/resnet18/)
42-
python -m graph_net.torch.validate \
43-
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/resnet18/
44-
```
45-
46-
**Illustration: How does GraphNet extract and construct a computation graph sample on PyTorch?**
11+
**GraphNet** is a large-scale dataset of deep learning **computation graphs**, built as a standard benchmark for **tensor compiler** optimization. It provides over 2.7K computation graphs extracted from state-of-the-art deep learning models spanning diverse tasks and ML frameworks. With standardized formats and rich metadata, GraphNet enables fair comparison and reproducible evaluation of the general optimization capabilities of tensor compilers, thereby supporting advanced research such as AI for System on compilers.
4712

13+
## 📣 News
14+
- [2025-10-14] ✨ Our technical report is out: a detailed study of dataset construction and compiler benchmarking, introducing the novel performance metrics Speedup Score S(t) and Error-aware Speedup Score ES(t). [📘 GraphNet: A Large-Scale Computational Graph Dataset for Tensor Compiler Research](https://arxiv.org/abs/2510.24035)
15+
- [2025-8-20] 🚀 The second round of [open contribution tasks](https://github.com/PaddlePaddle/Paddle/issues/74773) was released. (completed ✅)
16+
- [2025-7-30] 🚀 The first round of [open contribution tasks](https://github.com/PaddlePaddle/GraphNet/issues/44) was released. (completed ✅)
17+
## 📊 Benchmark Results
18+
We evaluate two representative tensor compiler backends, CINN (PaddlePaddle) and TorchInductor (PyTorch), on GraphNet's NLP and CV subsets. The evaluation adopts two quantitative metrics proposed in the [Technical Report](https://arxiv.org/abs/2510.24035):
19+
- **Speedup Score** S(t) — evaluates compiler performance under varying numerical tolerance levels.
4820
<div align="center">
49-
<img src="/pics/graphnet_sample.png" alt="GraphNet Extract Sample" width="65%">
21+
<img src="/pics/St-result.jpg" alt="Speedup Score S_t Results" width="80%">
5022
</div>
5123

52-
* Source code of custom_op is required **only when** corresponding operator is used in the module, and **no specific format** is required.
53-
54-
**Step 1: graph_net.torch.extract**
55-
56-
Import and wrap the model with `graph_net.torch.extract(name=model_name, dynamic=dynamic_mode)()` is all you need:
57-
58-
```bash
59-
import graph_net
60-
61-
# Instantiate the model (e.g. a torchvision model)
62-
model = ...
63-
64-
# Extract your own model
65-
model = graph_net.torch.extract(name="model_name", dynamic="True")(model)
66-
```
67-
68-
After running, the extracted graph will be saved to: `$GRAPH_NET_EXTRACT_WORKSPACE/model_name/`.
69-
70-
For more details, see docstring of `graph_net.torch.extract` defined in `graph_net/torch/extractor.py`.
71-
72-
**Step 2: graph_net.torch.validate**
73-
74-
To verify that the extracted model meets requirements, we use `graph_net.torch.validate` in CI tool and also ask contributors to self-check in advance:
24+
- **Error-aware Speedup Score** ES(t) — further accounts for runtime and compilation errors.
25+
<div align="center">
26+
<img src="/pics/ESt-result.jpg" alt="Error-aware Speedup Score ES_t Results" width="80%">
7527

76-
```bash
77-
python -m graph_net.torch.validate \
78-
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/model_name
79-
```
28+
</div>
8029

81-
All the **construction constraints** will be examined automatically. After passing validation, a unique `graph_hash.txt` will be generated and later checked in CI procedure to avoid redundant.
30+
## ⚡ Quick Start
31+
This section shows how to evaluate tensor compilers and reproduce benchmark results (for compiler users and developers),
32+
as well as how to contribute new computation graphs (for GraphNet contributors).
8233

83-
## ⚖️ Compiler Evaluation
34+
### ⚖️ Compiler Evaluation
8435

8536
**Step 1: Benchmark**
8637

87-
We use `graph_net.torch.test_compiler` to benchmark GraphNet samples with specific batch and log configurations:
38+
Use graph_net.torch.test_compiler to benchmark GraphNet samples with specific batch and logging configurations:
8839

8940
```bash
9041
# Set your benchmark directory
@@ -99,7 +50,7 @@ python -m graph_net.torch.test_compiler \
9950
--trials /times/to/test/ \
10051
> $GRAPH_NET_BENCHMARK_PATH/log.log 2>&1
10152

102-
# Note: if --compiler is omitted, PyTorch’s built-in compiler is used by default
53+
# Note: If --compiler is omitted, PyTorch’s built-in compiler is used by default.
10354
```
10455

10556
After executing, `graph_net.torch.test_compiler` will:
@@ -110,30 +61,50 @@ After executing, `graph_net.torch.test_compiler` will:
11061

11162
**Step 2: Generate JSON Record**
11263

113-
This step is to extract information (including failure) from logs in benchmark.
114-
All the information will be saved to multiple `model_compiler.json` files via:
64+
Extract runtime, correctness, and failure information from benchmark logs:
11565

11666
```bash
117-
python -m graph_net.torch.log2json \
67+
python -m graph_net.log2json \
11868
--log-file $GRAPH_NET_BENCHMARK_PATH/log.log \
119-
--output-dir $GRAPH_NET_BENCHMARK_PATH
69+
--output-dir $GRAPH_NET_BENCHMARK_PATH/JSON_results/
12070
```
12171

12272
**Step 3: Analysis**
12373

124-
After processing, we provide `graph_net/analysis.py` to generate [violin plot](https://en.m.wikipedia.org/wiki/Violin_plot) based on the JSON results.
74+
Use the three scripts `graph_net.plot_St`, `graph_net.plot_ESt` and `graph_net.plot_violin` to generate St plot, ESt plot, and [violin plot](https://en.m.wikipedia.org/wiki/Violin_plot) based on the JSON results.
12575

12676
```bash
127-
python -m graph_net.analysis \
128-
--benchmark-path /path/to/read/JSON/result/file/ \
129-
--output-dir /path/to/save/output/figures/
77+
python -m graph_net.plot_St \
78+
--benchmark-path $GRAPH_NET_BENCHMARK_PATH/JSON_results/ \
79+
--output-dir $GRAPH_NET_BENCHMARK_PATH \
80+
--negative-speedup-penalty penalty/power/for/negative/speedup \
81+
--fpdb base/penalty/for/severe/errors
82+
83+
python -m graph_net.plot_ESt \
84+
--benchmark-path $GRAPH_NET_BENCHMARK_PATH/JSON_results/ \
85+
--output-dir $GRAPH_NET_BENCHMARK_PATH \
86+
--negative-speedup-penalty penalty/power/for/negative/speedup \
87+
--fpdb base/penalty/for/severe/errors
88+
89+
# Note: If --negative-speedup-penalty is omitted, p=0 is used by default.
90+
# If --fpdb, b=0.1 is used by default.
91+
92+
python -m graph_net.plot_violin \
93+
--benchmark-path $GRAPH_NET_BENCHMARK_PATH/JSON_results/ \
94+
--output-dir $GRAPH_NET_BENCHMARK_PATH
13095
```
13196

132-
After executing, one summary plot of results on all compilers, as well as multiple sub-plots of results in categories (model tasks, Library...) on a single compiler will be exported.
97+
The scripts are designed to process a file structure as `/benchmark_path/category_name/`, and items on x-axis are identified by name of the sub-directories. After executing, several summary plots of result in categories (model tasks, libraries...) will be exported to `$GRAPH_NET_BENCHMARK_PATH`.
98+
99+
### Hardware Regression Testing
100+
We also provide a two-step workflow that validates compiler correctness and performance against a "golden" reference, which is crucial for hardware-specific testing and regression tracking. Details can be found in this [guide](./docs/hardware_test.md).
101+
102+
### 🧱 Construction & Contribution Guide
103+
Want to understand how GraphNet is built or contribute new samples?
104+
Check out the [Construction Guide](./docs/README_contribute.md) for details on the extraction and validation workflow.
133105

134-
The script is designed to process a file structure as `/benchmark_path/compiler_name/category_name/` (for example `/benchmark_logs/paddle/nlp/`), and items on x-axis are identified by name of the folders. So you can modify `read_all_speedups` function to fit the benchmark settings on your demand.
135106

136-
## 📌 Roadmap
107+
## 🚀 Future Roadmap
137108

138109
1. Scale GraphNet to 10K+ graphs.
139110
2. Further annotate GraphNet samples into more granular sub-categories
@@ -142,7 +113,7 @@ The script is designed to process a file structure as `/benchmark_path/compiler_
142113

143114
**Vision**: GraphNet aims to lay the foundation for AI for Compiler by enabling **large-scale, systematic evaluation** of tensor compiler optimizations, and providing a **dataset for models to learn** and transfer optimization strategies.
144115

145-
## 💬 GraphNet Community
116+
## GraphNet Community
146117

147118
You can join our community via following group chats. Welcome to ask any questions about using and building GraphNet.
148119

@@ -160,5 +131,20 @@ You can join our community via following group chats. Welcome to ask any questio
160131
</table>
161132
</div>
162133

163-
## 🪪 License
164-
This project is released under the [MIT License](LICENSE).
134+
## License and Acknowledgement
135+
136+
GraphNet is released under the [MIT License](./LICENSE).
137+
138+
If you find this project helpful, please cite:
139+
140+
```bibtex
141+
@misc{li2025graphnetlargescalecomputationalgraph,
142+
title={GraphNet: A Large-Scale Computational Graph Dataset for Tensor Compiler Research},
143+
author={Xinqi Li and Yiqun Liu and Shan Jiang and Enrong Zheng and Huaijin Zheng and Wenhao Dai and Haodong Deng and Dianhai Yu and Yanjun Ma},
144+
year={2025},
145+
eprint={2510.24035},
146+
archivePrefix={arXiv},
147+
primaryClass={cs.LG},
148+
url={https://arxiv.org/abs/2510.24035},
149+
}
150+
```
File renamed without changes.
File renamed without changes.

docs/README_contribute.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Contributing to GraphNet
2+
To guarantee the dataset’s overall quality, reproducibility, and cross-compiler compatibility, we define the following construction **constraints**:
3+
4+
1. Computation graphs must be executable in imperative (eager) mode.
5+
2. Computation graphs and their corresponding Python code must support serialization and deserialization.
6+
3. The full graph can be decomposed into two disjoint subgraphs.
7+
4. Operator names within each computation graph must be statically parseable.
8+
5. If custom operators are used, their implementation code must be fully accessible.
9+
10+
## Graph Extraction & Validation
11+
GraphNet provides automated tools for graph extraction and validation.
12+
13+
<div align="center">
14+
<img src="/pics/graphnet_overview.jpg" alt="GraphNet Architecture Overview" width="65%">
15+
</div>
16+
17+
**Demo: Extract & Validate ResNet‑18**
18+
```bash
19+
git clone https://github.com/PaddlePaddle/GraphNet.git
20+
cd GraphNet
21+
22+
# Set your workspace directory
23+
export GRAPH_NET_EXTRACT_WORKSPACE=/home/yourname/graphnet_workspace/
24+
25+
# Extract the ResNet‑18 computation graph
26+
python graph_net/test/vision_model_test.py
27+
28+
# Validate the extracted graph (e.g. /home/yourname/graphnet_workspace/resnet18/)
29+
python -m graph_net.torch.validate \
30+
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/resnet18/
31+
```
32+
33+
**Illustration – Extraction Workflow**
34+
35+
<div align="center">
36+
<img src="/pics/dataset_composition.png" alt="GraphNet Extract Sample" width="65%">
37+
</div>
38+
39+
* Source code of custom_op is required **only when** corresponding operator is used in the module, and **no specific format** is required.
40+
41+
**Step 1: graph_net.torch.extract**
42+
43+
Wrap the model with the extractor — that’s all you need:
44+
45+
```bash
46+
import graph_net
47+
48+
# Instantiate the model (e.g. a torchvision model)
49+
model = ...
50+
51+
# Extract your own model
52+
model = graph_net.torch.extract(name="model_name", dynamic="True")(model)
53+
```
54+
55+
After running, the extracted graph will be saved to: `$GRAPH_NET_EXTRACT_WORKSPACE/model_name/`.
56+
57+
For more details, see docstring of `graph_net.torch.extract` defined in `graph_net/torch/extractor.py`.
58+
59+
**Step 2: graph_net.torch.validate**
60+
61+
To verify that the extracted model meets requirements, we use `graph_net.torch.validate` in CI tool and also ask contributors to self-check in advance:
62+
63+
```bash
64+
python -m graph_net.torch.validate \
65+
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/model_name
66+
```
67+
68+
All the **construction constraints** will be examined automatically. After passing validation, a unique `graph_hash.txt` will be generated and later checked in CI procedure to avoid redundant.
69+
70+
## 📁 Repository Structure
71+
This repository is organized as follows:
72+
73+
| Directory | Description |
74+
|------------|--------------|
75+
| **graph_net/** | Core module for graph extraction, validation, and benchmarking |
76+
| **paddle_samples/** | Computation graph samples extracted from PaddlePaddle |
77+
| **samples/** | Computation graph samples extracted from PyTorch |
78+
| **docs/** | Technical documents and contributor guides|
79+
80+
Below is the structure of the **graph_net/**:
81+
```text
82+
graph_net/
83+
├─ config/ # Config files, params
84+
├─ paddle/ # PaddlePaddle graph extraction & validation
85+
├─ torch/ # PyTorch graph extraction & validation
86+
├─ test/ # Unit tests and example scripts
87+
└─ *.py # Benchmark & analysis scripts

docs/hardware_test.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Hardware Regression Testing
2+
### Step 1: Generate Reference Data
3+
First, use `graph_net.paddle.test_reference_device` on a trusted setting (e.g., a specific hardware/compiler version) to generate baseline logs and output files.
4+
```bash
5+
python -m graph_net.paddle.test_reference_device \
6+
--model-path /path/to/all_models/ \
7+
--reference-dir ./gold_reference \
8+
--compiler cinn \
9+
--device cuda
10+
# --reference-dir: (Required) Directory where the output .log (performance/config) and .pdout (output tensors) files will be saved.
11+
# --compiler: Specifies the compiler backend.
12+
```
13+
### Step 2: Run Regression Test
14+
After changing hardware, run the correctness test script. This script reads the reference data, re-runs the models using the exact same configuration, and compares the new results against the "golden" reference.
15+
```bash
16+
python -m graph_net.paddle.test_device_correctness \
17+
--reference-dir ./golden_reference \
18+
--device cuda
19+
```
20+
This script will report any failures (e.g., compilation errors, output mismatches) and print a performance comparison (speedup/slowdown) against the reference log, allowing you to quickly identify regressions.

0 commit comments

Comments
 (0)