https://github.com/mattjesc/ptq-meshgraphnet-nvidia-modulus
Post-Training Quantization for MeshGraphNet Physics-Based ML Model: Cardiovascular Flow Simulation Implementation
https://github.com/mattjesc/ptq-meshgraphnet-nvidia-modulus
ai deep-learning deeplearning nvidia nvidia-cuda nvidia-modulus quantization
Last synced: 3 months ago
JSON representation
Post-Training Quantization for MeshGraphNet Physics-Based ML Model: Cardiovascular Flow Simulation Implementation
- Host: GitHub
- URL: https://github.com/mattjesc/ptq-meshgraphnet-nvidia-modulus
- Owner: Mattjesc
- Created: 2024-07-12T09:28:26.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-07-12T12:00:36.000Z (11 months ago)
- Last Synced: 2025-01-18T04:41:40.764Z (5 months ago)
- Topics: ai, deep-learning, deeplearning, nvidia, nvidia-cuda, nvidia-modulus, quantization
- Language: Python
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Post-Training Quantization for MeshGraphNet using NVIDIA Modulus: Cardiovascular Flow Simulation Implementation
## Overview
This project explores the application of post-training quantization (PTQ) to the MeshGraphNet model for simulating cardiovascular flow. The goal is to reduce computational demands, enabling deployment on resource-limited devices without significant loss of accuracy. The study details the quantization process, evaluates performance, and compares the quantized model with the original.
## Prerequisites
1. **Clone the NVIDIA Modulus Repository**:
Follow the instructions provided in the NVIDIA Modulus repository to set up the Modulus framework:
- [NVIDIA Modulus Repository](https://github.com/NVIDIA/modulus)
- Refer to the README in the Modulus repo for detailed setup instructions.2. **Prepare the Bloodflow Example**:
Navigate to the `examples/healthcare/bloodflow_1d_mgn` directory in the Modulus repository and prepare the example as per the instructions provided in the respective README file.## Adding Quantized Files
After setting up the NVIDIA Modulus repository and preparing the bloodflow example, add the quantized files from this project to the `examples/healthcare/bloodflow_1d_mgn` directory:
1. **Copy Quantized Files**:
Copy the `train_quantized.py` and `inference_quantized.py` files to the `examples/healthcare/bloodflow_1d_mgn` directory.## Workflow
1. **Run `train.py`**: This script trains the original MeshGraphNet model.
```sh
python train.py
```2. **Run `inference.py`**: This script performs inference using the trained original model and generates output graphs.
```sh
python inference.py
```3. **Run `train_quantized.py`**: This script applies post-training quantization to the MeshGraphNet model.
```sh
python train_quantized.py
```4. **Run `inference_quantized.py`**: This script performs inference using the quantized model and generates output graphs.
```sh
python inference_quantized.py
```5. **Compare Results**: Compare the results of `pressure.png` and `flowrate.png` from the original model with `pressure_quantized.png` and `flowrate_quantized.png` from the quantized model.
## Example Results
| Metric | Original Model | PTQ Model |
|-----------------------------|----------------|-------------|
| Relative error in pressure | 0.83% | 17.91% |
| Relative error in flow rate | 4.00% | 33.35% |
| Rollout time | 0.653 seconds | 0.535 seconds |Figure 1: Original Model Rollout and Relative Error Values

Figure 2: Quantized (PTQ) Model Rollout and Relative Error Values

Figure 3: Original Model Pressure Graph

Figure 4: Quantized (PTQ) Model Pressure Graph

Figure 5: Original Model Flow Rate Graph

Figure 6: Quantized (PTQ) Model Flow Rate Graph

## Justifications and Explanations
### Why Quantize Using PTQ?
Post-training quantization reduces the model size and memory usage, making it feasible to run large models on resource-limited hardware. PTQ specifically optimizes models for efficient inference, with the trade-off between computational efficiency and accuracy.
### Hardware Considerations
The quantization process and model evaluations are performed on a single RTX 3090 GPU. Different hardware setups, particularly variations in CPU capabilities, may yield varying outcomes in terms of training/inference speed and performance.
## Acknowledgements
Special thanks to:
- [Authors and Contributors](https://arxiv.org/abs/2010.03409) of the MeshGraphNet model and the underlying datasets.
- [NVIDIA Modulus Team](https://developer.nvidia.com/modulus) for their framework and support.
- [Vascular Model Repository](https://vascularmodel.com/) for providing the dataset.## References
- [Learning Mesh-Based Simulation with Graph Networks](https://arxiv.org/abs/2010.03409)
- [PD-Quant: Post-Training Quantization based on Prediction Difference Metric](https://arxiv.org/abs/2212.07048)
- [Recipes for Post-Training Quantization of Deep Neural Networks](https://arxiv.org/abs/2007.00893)## Citation
```yaml
cff-version: 1.2.0
message: If you use this software, please cite it as below.
title: NVIDIA Modulus
version: 0.6.0
authors:
- family-names: NVIDIA Modulus Team
url: https://github.com/NVIDIA/modulus/tree/main