Skip to content

Commit 956fb0d

Browse files
committed
Merge branch 'develop' of github.com:PaddlePaddle/GraphNet into develop
2 parents 7b950b9 + c1bc381 commit 956fb0d

File tree

1,838 files changed

+2349076
-68610
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,838 files changed

+2349076
-68610
lines changed

.github/actions/check-bypass/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Check bypass"
2-
description: "A custom action to encapsulate PFCCLab/ci-bypass"
2+
description: "A custom action to encapsulate GraphNet"
33
inputs:
44
github-token:
55
description: "GitHub token"
@@ -18,7 +18,7 @@ runs:
1818
- id: check-bypass
1919
name: Check Bypass
2020
env:
21-
CI_TEAM_MEMBERS: '["SigureMo", "risemeup1", "tianshuo78520a", "0x3878f", "swgu98", "luotao1", "XieYunshen"]'
21+
CI_TEAM_MEMBERS: '["lixinqi", "Xreki"]'
2222
uses: PFCCLab/ci-bypass@v1
2323
with:
2424
github-token: ${{ inputs.github-token }}

.github/workflows/Validate-GPU.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
-v "/home/data/cfs/.ccache:/root/.ccache" \
6262
-v "/dev/shm:/dev/shm" \
6363
-v ${{ github.workspace }}/../../..:${{ github.workspace }}/../../.. \
64-
-v ${{ github.workspace }}:/graphnet \
64+
-v ${{ github.workspace }}:${{ github.workspace }} \
6565
-e python \
6666
-e core_index \
6767
-e BRANCH \
@@ -73,7 +73,7 @@ jobs:
7373
-e CACHE_DIR \
7474
-e GITHUB_API_TOKEN \
7575
-e CFS_DIR \
76-
-w /graphnet --network host ${docker_image}
76+
-w ${{ github.workspace }} --network host ${docker_image}
7777
7878
- name: Run check
7979
env:

README.md

Lines changed: 86 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,150 @@
11
# 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)
22

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

4-
**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, reproducible evaluation, and deeper research into the general optimization capabilities of tensor compilers.
55
<br>
66
<div align="center">
7-
<img src="/pics/graphnet_overview.jpg" alt="GraphNet Architecture Overview" width="65%">
7+
<img src="/pics/Eval_result.png" alt="Violin plots of speedup distributions" width="65%">
88
</div>
99

10-
With GraphNet, users can:
11-
1. **Contribute new computation graphs** through the built-in automated extraction and validation pipeline.
12-
2. **Evaluate tensor compilers** on existing graphs with the integrated compiler evaluation tool, supporting multiple compiler backends.
13-
3. **Advance research** in tensor compiler optimization using the test data and statistics provided by GraphNet.
14-
15-
16-
17-
18-
**Vision**: We aim to achieve cross-hardware portability of compiler optimizations by allowing models to learn and transfer optimization strategies. It will significantly reduce the manual effort required to develop efficient operator implementations.
19-
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).
2011

21-
## Dataset Construction
12+
## 🧱 Dataset Construction
2213

2314
To guarantee the dataset’s overall quality, reproducibility, and cross-compiler compatibility, we define the following construction **constraints**:
2415

25-
1. Dynamic graphs must execute correctly.
26-
2. Graphs and their corresponding Python code must support serialization and deserialization.
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.
2718
3. The full graph can be decomposed into two disjoint subgraphs.
2819
4. Operator names within each computation graph must be statically parseable.
2920
5. If custom operators are used, their implementation code must be fully accessible.
3021

31-
3222
### Graph Extraction & Validation
33-
For full implementation details, please refer to the [Co-Creation Tutorial](https://github.com/PaddlePaddle/GraphNet/blob/develop/CONTRIBUTE_TUTORIAL.md#co-creation-tutorial).
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%">
28+
</div>
3429

3530
**Demo: Extract & Validate ResNet‑18**
36-
```
31+
```bash
3732
git clone https://github.com/PaddlePaddle/GraphNet.git
3833
cd GraphNet
3934

4035
# Set your workspace directory
41-
export GRAPH_NET_EXTRACT_WORKSPACE=/home/yourname/graphnet_workspace
36+
export GRAPH_NET_EXTRACT_WORKSPACE=/home/yourname/graphnet_workspace/
4237

4338
# Extract the ResNet‑18 computation graph
4439
python graph_net/test/vision_model_test.py
4540

46-
# Validate the extracted graph (e.g. /home/yourname/graphnet_workspace/resnet18)
41+
# Validate the extracted graph (e.g. /home/yourname/graphnet_workspace/resnet18/)
4742
python -m graph_net.torch.validate \
48-
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/resnet18
43+
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/resnet18/
4944
```
5045

51-
**graph_net.torch.extract**
46+
**Illustration: How does GraphNet extract and construct a computation graph sample on PyTorch?**
47+
48+
<div align="center">
49+
<img src="/pics/graphnet_sample.png" alt="GraphNet Extract Sample" width="65%">
50+
</div>
51+
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**
5255

53-
```python
56+
Import and wrap the model with `graph_net.torch.extract(name=model_name, dynamic=dynamic_mode)()` is all you need:
57+
58+
```bash
5459
import graph_net
5560

5661
# Instantiate the model (e.g. a torchvision model)
5762
model = ...
5863

5964
# Extract your own model
60-
model = graph_net.torch.extract(name="model_name")(model)
61-
62-
# After running, the extracted graph will be saved to:
63-
# $GRAPH_NET_EXTRACT_WORKSPACE/model_name
65+
model = graph_net.torch.extract(name="model_name", dynamic="True")(model)
6466
```
6567

66-
**graph_net.torch.validate**
67-
```
68-
# Verify that the extracted model meets requirements
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:
75+
76+
```bash
6977
python -m graph_net.torch.validate \
7078
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/model_name
7179
```
7280

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

74-
## Compiler Evaluation
75-
76-
The compiler evaluation process takes a GraphNet sample as input and involves:
77-
1. Running the original model in eager mode to record a baseline.
78-
2. Compiling the model with the specified backend (e.g., CINN, TorchInductor, TVM).
79-
3. Executing the compiled model and collecting its runtime and outputs.
80-
4. Analyzing performance by comparing the compiled results against the baseline.
83+
## ⚖️ Compiler Evaluation
8184

82-
### Evaluation Metrics
85+
**Step 1: Benchmark**
8386

84-
We define two key metrics here: **rectified speedup** and **GraphNet Score**. Rectified speedup measures runtime performance while incorporating compilation success, time cost, and correctness. GraphNet Score aggregates the rectified speedup of a compiler on specified tasks, providing a measure of its general optimization capability.
87+
We use `graph_net.torch.test_compiler` to benchmark GraphNet samples with specific batch and log configurations:
8588

86-
**Demo: How to benchmark your compiler on the model:**
89+
```bash
90+
# Set your benchmark directory
91+
export GRAPH_NET_BENCHMARK_PATH=/home/yourname/graphnet_benchmark/
8792

88-
```
89-
python3 -m graph_net.torch.test_compiler \
93+
# Run benchmark
94+
python -m graph_net.torch.test_compiler \
9095
--model-path $GRAPH_NET_EXTRACT_WORKSPACE/model_name/ \
91-
--compiler /path/to/custom/compiler
96+
--compiler /custom/or/builtin/compiler/ \
97+
--device /device/to/execute/ \
98+
--warmup /times/to/warmup/ \
99+
--trials /times/to/test/ \
100+
> $GRAPH_NET_BENCHMARK_PATH/log.log 2>&1
101+
92102
# Note: if --compiler is omitted, PyTorch’s built-in compiler is used by default
93103
```
94104

95-
### Evaluation Results Example
105+
After executing, `graph_net.torch.test_compiler` will:
106+
1. Running the original model in eager mode to record a baseline.
107+
2. Compiling the model with the specified backend (e.g., CINN, TVM, Inductor, TensorRT, XLA, BladeDISC).
108+
3. Executing the compiled model and collecting its runtime and outputs.
109+
4. Conduct speedup by comparing the compiled results against the baseline (if no execution failure occurs).
96110

97-
<div align="center">
98-
<img src="/pics/Eval_result.jpg" alt="Violin plots of rectified speedup distributions" width="65%">
99-
</div>
111+
**Step 2: Generate JSON Record**
100112

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:
101115

102-
## Roadmap
116+
```bash
117+
python -m graph_net.torch.log2json \
118+
--log-file $GRAPH_NET_BENCHMARK_PATH/log.log \
119+
--output-dir $GRAPH_NET_BENCHMARK_PATH
120+
```
121+
122+
**Step 3: Analysis**
123+
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.
125+
126+
```bash
127+
python -m graph_net.analysis \
128+
--benchmark-path /path/to/read/JSON/result/file/ \
129+
--output-dir /path/to/save/output/figures/
130+
```
131+
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.
133+
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.
135+
136+
## 📌 Roadmap
103137

104138
1. Scale GraphNet to 10K+ graphs.
105139
2. Further annotate GraphNet samples into more granular sub-categories
106140
3. Extract samples from multi-GPU scenarios to support benchmarking and optimization for large-scale, distributed computing.
107141
4. Enable splitting full graphs into independently optimized subgraphs and operator sequences.
108142

109-
## GraphNet Community:
110-
143+
**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.
111144

112-
You can join GraphNet community via the following group chats.
145+
## 💬 GraphNet Community
113146

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

115149
<div align="center">
116150
<table>
@@ -126,8 +160,5 @@ You can join GraphNet community via the following group chats.
126160
</table>
127161
</div>
128162

129-
130-
131-
## License
163+
## 🪪 License
132164
This project is released under the [MIT License](LICENSE).
133-

graph_net/benchmark_demo.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

graph_net/paddle/check_redundant_incrementally.py

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,72 @@ def is_single_model_dir(model_dir):
4343

4444

4545
def main(args):
46-
assert os.path.isdir(args.model_path)
47-
assert os.path.isdir(args.graph_net_samples_path)
48-
current_model_graph_hash_pathes = set(
49-
graph_hash_path
50-
for model_path in get_recursively_model_pathes(args.model_path)
51-
for graph_hash_path in [f"{model_path}/graph_hash.txt"]
46+
assert os.path.isdir(
47+
args.graph_net_samples_path
48+
), f"args.graph_net_samples_path ({args.graph_net_samples_path}) is not a directory!"
49+
50+
current_model_graph_hash_pathes = set()
51+
if args.model_path:
52+
assert os.path.isdir(
53+
args.model_path
54+
), f"args.model_path {args.model_path} is not a directory!"
55+
current_model_graph_hash_pathes = set(
56+
graph_hash_path
57+
for model_path in get_recursively_model_pathes(args.model_path)
58+
for graph_hash_path in [f"{model_path}/graph_hash.txt"]
59+
)
60+
61+
find_redundant = False
62+
graph_hash2graph_net_model_path = {}
63+
for model_path in get_recursively_model_pathes(args.graph_net_samples_path):
64+
graph_hash_path = f"{model_path}/graph_hash.txt"
65+
if (
66+
os.path.isfile(graph_hash_path)
67+
and graph_hash_path not in current_model_graph_hash_pathes
68+
):
69+
graph_hash = open(graph_hash_path).read()
70+
if graph_hash not in graph_hash2graph_net_model_path.keys():
71+
graph_hash2graph_net_model_path[graph_hash] = [graph_hash_path]
72+
else:
73+
find_redundant = True
74+
graph_hash2graph_net_model_path[graph_hash].append(graph_hash_path)
75+
print(
76+
f"Totally {len(graph_hash2graph_net_model_path)} unique samples under {args.graph_net_samples_path}."
5277
)
53-
graph_hash2graph_net_model_path = {
54-
graph_hash: graph_hash_path
55-
for model_path in get_recursively_model_pathes(args.graph_net_samples_path)
56-
for graph_hash_path in [f"{model_path}/graph_hash.txt"]
57-
if os.path.isfile(graph_hash_path)
58-
if graph_hash_path not in current_model_graph_hash_pathes
59-
for graph_hash in [open(graph_hash_path).read()]
60-
}
61-
for current_model_graph_hash_path in current_model_graph_hash_pathes:
62-
graph_hash = open(current_model_graph_hash_path).read()
78+
79+
if args.model_path:
80+
# Check whether the specified model is redundant.
81+
for current_model_graph_hash_path in current_model_graph_hash_pathes:
82+
graph_hash = open(current_model_graph_hash_path).read()
83+
assert (
84+
graph_hash not in graph_hash2graph_net_model_path
85+
), f"Redundant models detected.\n\tgraph_hash:{graph_hash}, newly-added-model-path:{current_model_graph_hash_path}, existing-model-path:{graph_hash2graph_net_model_path[graph_hash]}."
86+
else:
87+
# Check whether there are redundant samples under samples directory.
88+
for graph_hash, graph_paths in graph_hash2graph_net_model_path.items():
89+
if len(graph_paths) > 1:
90+
print(f"Redundant models detected for grap_hash {graph_hash}:")
91+
for model_path in graph_paths:
92+
print(f" {model_path}")
6393
assert (
64-
graph_hash not in graph_hash2graph_net_model_path
65-
), f"Redundant models detected. old-model-path:{current_model_graph_hash_path}, new-model-path:{graph_hash2graph_net_model_path[graph_hash]}."
94+
not find_redundant
95+
), f"Redundant models detected under {args.graph_net_samples_path}."
6696

6797

6898
if __name__ == "__main__":
6999
parser = argparse.ArgumentParser(description="Test compiler performance.")
70100
parser.add_argument(
71101
"--model-path",
72102
type=str,
73-
required=True,
103+
required=False,
74104
help="Path to model file(s), each subdirectory containing graph_net.json will be regarded as a model",
75105
)
76106
parser.add_argument(
77107
"--graph-net-samples-path",
78108
type=str,
79-
required=False,
80-
default="default",
109+
required=True,
81110
help="Path to GraphNet samples",
82111
)
83112
args = parser.parse_args()
113+
print(args)
84114
main(args=args)

graph_net/paddle/samples_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44

55
def get_default_samples_directory():
6-
return f"{os.path.dirname(graph_net.__file__)}/../paddle_samples"
6+
graph_net_root = os.path.dirname(os.path.dirname(graph_net.__file__))
7+
return f"{graph_net_root}/paddle_samples"

0 commit comments

Comments
 (0)