AMG

Model Overview

AMG is a multi-graph neural operator for solving partial differential equations on arbitrary geometries. It was proposed by researchers from the Hong Kong University of Science and Technology (Guangzhou), Beihang University, and other institutions. The model uses multiscale graphs, a physics graph, and the dynamic graph-attention mechanism in GraphFormer to learn PDE solution operators on regularly or irregularly discretized domains. This package is trained for the ShapeNet-Car/CarCFD experiment. Given a three-dimensional vehicle geometry and mesh-node features, it predicts surface pressure and the surrounding airflow velocity field for rapid aerodynamic evaluation and drag-coefficient estimation.

This repository is an independent reproduction of the AMG ShapeNet-Car experiment, implemented through the OneScience workflow from the paper description and official configuration.

Paper: Harnessing Scale and Physics: A Multi-Graph Neural Operator Framework for PDEs on Arbitrary Geometries

Model Description

AMG uses an encoder, a multi-graph processor, and a decoder. It takes discrete mesh-point coordinates and node features as input. A local graph captures high-frequency local variations, a global graph models long-range spatial dependencies, and a physics graph aggregates and propagates latent physical properties. The GraphFormer module performs cross-node interaction with dynamic graph attention and produces the PDE solution at the original discrete points. For the ShapeNet-Car/CarCFD task, the model predicts three velocity components and pressure on a three-dimensional unstructured mesh containing 32,186 points.

Use Cases

Use Case Description
Three-dimensional automotive external-flow prediction Predict the three-dimensional velocity field around complex vehicle geometries and pressure on the vehicle surface
Automotive aerodynamic evaluation Use predicted velocity and pressure fields to support drag-coefficient estimation and aerodynamic assessment
PDE learning on unstructured meshes Build PDE surrogate models for three-dimensional unstructured meshes and irregular geometric domains
CFD surrogate modeling Replace part of a costly numerical-simulation workflow to accelerate vehicle-shape design and batch evaluation of design candidates

Usage

1. OneCode

Use the online OneCode environment for an intelligent, one-click AI for Science (AI4S) programming experience:

Launch OneCode for one-click AI4S programming

2. Manual Setup

Hardware Requirements

  • A GPU or DCU is recommended.
  • A CPU can be used for import checks and small-scale pipeline validation, but full training and inference will be slow.
  • DCU users must install DTK in advance. DTK 25.04.2 or later, or the OneScience-recommended version for the target cluster, is recommended.

Download the Model Package from Hugging Face

pip install -U huggingface_hub
hf download OneScience-Group/AMG-ShapeNet-Car --local-dir ./AMG-ShapeNet-Car
cd AMG-ShapeNet-Car

Set Up the Runtime Environment

DCU Environment

# Activate DTK and Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
# Installation with uv is also supported
pip install onescience[cfd-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

GPU Environment

# Activate Conda first
conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
conda activate onescience311
# Installation with uv is also supported
pip install onescience[cfd-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

Training Data

The OneScience community provides the ShapeNetCar training data on Hugging Face. Download it with the command below, then update data.root in config/config.yaml so that it points to the downloaded preprocessed_data directory.

hf download OneScience-Group/ShapeNetCar --repo-type dataset --local-dir ./data

The dataset contains 889 three-dimensional automotive external-flow samples organized into nine shards, param0 through param8. It includes 690 training samples, 99 validation samples, and 100 test samples. Each sample contains 32,186 unstructured mesh points and the following files:

  • x.npy: node input features with shape (32186, 7); AMG uses the four features at indices [3, 4, 5, 6]
  • y.npy: ground-truth CFD solution with shape (32186, 4), containing three velocity components followed by pressure
  • pos.npy: three-dimensional mesh-point coordinates with shape (32186, 3)
  • surf.npy: vehicle-surface node mask with shape (32186,)
  • edge_index.npy: unstructured-mesh edge connectivity with shape (2, E)

Training

Single-device training:

  • Training parameters are read from the data, model, and training sections of config/config.yaml.
  • The default configuration follows the paper and trains for 500 epochs. Add --smoke for a minimal end-to-end test.
  • Before training, set data.root to the ShapeNetCar dataset's preprocessed_data directory.
  • For the two-device, eight-hour profile, use --profile fast_8h_2dcu.
python scripts/train.py

Multi-device training:

torchrun --standalone --nproc_per_node=<num_GPUs> scripts/train.py

Two-device, eight-hour training profile:

torchrun --standalone --nproc_per_node=2 scripts/train.py --profile fast_8h_2dcu

Training reports the training loss, validation pressure relative L2 error, and validation velocity relative L2 error. The best checkpoint is selected using the mean validation relative L2 error and saved to:

./weight/best_model.pt

Model Weights

The weight/ directory contains best_model.pt, the best AMG checkpoint obtained from this ShapeNet-Car/CarCFD reproduction. It can be loaded directly for inference.

Inference

python scripts/inference.py

Predictions, per-sample metrics, and aggregate metrics are saved under results/.

Evaluation and Visualization

python scripts/result.py

The evaluation report, paper-metric comparison plots, training curves, and flow-field visualizations are saved under results/.

Official OneScience Resources

Citations and License


中文说明

模型概览

AMG 是一种用于求解任意几何域上偏微分方程的多图神经算子(multi-graph neural operator)。该模型由香港科技大学(广州)、北京航空航天大学及其他机构的研究人员提出。模型采用多尺度图、物理图及 GraphFormer 中的动态图注意力机制,在规则或不规则离散化的区域上学习 PDE 的求解算子。本模型包针对 ShapeNet-Car/CarCFD 实验进行了训练。给定三维车身几何和网格节点特征,模型预测车身表面压力及周围气流速度场,用于快速评估空气动力学性能并估算阻力系数。

本仓库根据论文描述和官方配置,通过 OneScience 工作流独立复现 AMG 的 ShapeNet-Car 实验。

论文:利用尺度与物理信息:面向任意几何域上 PDE 的多图神经算子框架

模型描述

AMG 采用编码器、多图处理器和解码器,并以离散网格点坐标和节点特征为输入。局部图捕捉局部高频变化,全局图对长距离空间依赖关系建模,物理图聚合并传播隐含的物理属性。GraphFormer 模块通过动态图注意力实现节点间交互,并在原离散点上输出 PDE 的解。在 ShapeNet-Car/CarCFD 任务中,模型预测包含 32,186 个点的三维非结构化网格上的三个速度分量和压力。

使用场景

使用场景 说明
三维汽车外流场预测 预测复杂车身几何周围的三维速度场及车身表面压力
汽车空气动力学性能评估 利用预测得到的速度场和压力场辅助估算阻力系数并评估空气动力学性能
非结构化网格上的 PDE 学习 针对三维非结构化网格和不规则几何域构建 PDE 代理模型(surrogate model)
计算流体力学(CFD)代理建模 替代部分耗费资源的数值模拟流程,加快车身外形设计和候选设计方案的批量评估

使用指南

1. OneCode

通过 OneCode 在线环境体验面向科学的人工智能(AI4S)智能一键编程。

启动 OneCode 以使用一键 AI4S 编程

2. 手动配置

硬件要求

  • 建议使用 GPU 或 DCU。
  • CPU 可用于导入检查和小规模流程验证,完整训练和推理(inference)速度较慢。
  • DCU 用户必须提前安装 DTK。建议使用 DTK 25.04.2 或更高版本,或使用 OneScience 推荐的适配目标集群的版本。

从 Hugging Face 下载模型包

pip install -U huggingface_hub
hf download OneScience-Group/AMG-ShapeNet-Car --local-dir ./AMG-ShapeNet-Car
cd AMG-ShapeNet-Car

配置运行环境

DCU 环境

# Activate DTK and Conda first
conda create -n onescience311 python=3.11 -y
conda activate onescience311
# Installation with uv is also supported
pip install onescience[cfd-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

GPU 环境

# Activate Conda first
conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
conda activate onescience311
# Installation with uv is also supported
pip install onescience[cfd-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai

训练数据

OneScience 社区在 Hugging Face 上提供 ShapeNetCar 训练数据。使用以下命令下载,再更新 config/config.yaml 中的 data.root,使其指向下载的 preprocessed_data 目录。

hf download OneScience-Group/ShapeNetCar --repo-type dataset --local-dir ./data

数据集包含 889 个三维汽车外流场样本,分为 param0 至 param8 共九个分片。其中包含 690 个训练样本、99 个验证样本和 100 个测试样本。每个样本包含 32,186 个非结构化网格点及以下文件。

  • x.npy 是形状为 (32186, 7) 的节点输入特征。AMG 使用索引 [3, 4, 5, 6] 处的四项特征
  • y.npy 是形状为 (32186, 4) 的计算流体力学真值解,依次包含三个速度分量和压力
  • pos.npy 是形状为 (32186, 3) 的三维网格点坐标
  • surf.npy 是形状为 (32186,) 的车身表面节点掩码
  • edge_index.npy 是形状为 (2, E) 的非结构化网格边连接关系

训练

单设备训练

  • 从 config/config.yaml 的 data、model 和 training 部分读取训练参数。
  • 默认配置遵循论文,训练 500 轮。添加 --smoke 可进行最小规模的端到端测试。
  • 训练前请将 data.root 设为 ShapeNetCar 数据集的 preprocessed_data 目录。
  • 如需使用双设备八小时配置,请使用 --profile fast_8h_2dcu。
python scripts/train.py

多设备训练

torchrun --standalone --nproc_per_node=<num_GPUs> scripts/train.py

双设备八小时训练配置

torchrun --standalone --nproc_per_node=2 scripts/train.py --profile fast_8h_2dcu

训练报告给出训练损失、验证集压力相对 L2 误差和验证集速度相对 L2 误差。按验证集相对 L2 误差的均值选择最佳模型权重(检查点)(checkpoint),并保存到以下位置。

./weight/best_model.pt

模型权重

weight/ 目录包含 best_model.pt,即此次复现 ShapeNet-Car/CarCFD 实验获得的最佳 AMG 模型权重(检查点)。该模型权重可直接加载以进行推理。

推理

python scripts/inference.py

预测结果、逐样本指标和汇总指标保存在 results/ 下。

评估与可视化

python scripts/result.py

评估报告、论文指标对比图、训练曲线和流场可视化结果保存在 results/ 下。

OneScience 官方资源

引用与许可证

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train OneScience-Group/AMG-ShapeNet-Car

Paper for OneScience-Group/AMG-ShapeNet-Car