Skip to content

Commit 869636c

Browse files
committed
modify the README for ML
1 parent f4f6af4 commit 869636c

1 file changed

Lines changed: 70 additions & 17 deletions

File tree

Exec/README_md.pytorch

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,89 @@
1-
# PyTorch (libtorch) Download and Setup
1+
# README_pytorch.md
2+
## Running a MagneX / AMReX Application with a PyTorch Model (LibTorch + TorchScript)
23

3-
This guide downloads the libtorch CUDA 11.8 C++ distribution and unzips it in the same directory that contains `MagneX`, then renames the extracted folder to `libtorch_cuda`.
4+
This guide explains how to run an AMReX-based application (e.g., MagneX) that evaluates a pre-trained PyTorch model using the LibTorch C++ API.
45

5-
## Steps
6+
---
67

7-
1. Change to the parent directory of `MagneX`:
8+
## Overview
9+
10+
The typical workflow is:
11+
12+
1. Initialize an AMReX `MultiFab` with input data (e.g., different `dt` values).
13+
2. Copy the `MultiFab` data into a `torch::Tensor`.
14+
3. Load a TorchScript model (`model.pt`).
15+
4. Run inference on CPU or GPU.
16+
5. Copy the model outputs back into a `MultiFab`.
17+
6. Write AMReX plotfiles for visualization.
18+
19+
The model **must** be exported as TorchScript (`model.pt`).
20+
Do not use a Python-only `.pth` checkpoint.
21+
22+
---
23+
24+
## Requirements
25+
26+
- MagneX (or another AMReX-based application)
27+
- A TorchScript model file:
28+
```
29+
model.pt
30+
```
31+
- LibTorch (CUDA build recommended for GPU runs)
32+
- CUDA version tested: **13.0**
33+
- LibTorch version tested: **2.9.1 + cu126**
34+
35+
---
36+
37+
## Directory Layout (Recommended)
38+
39+
Place LibTorch in the same parent directory as MagneX:
840

9-
```bash
10-
cd <MAGNEX_PARENT_DIR>
1141
```
42+
/path/to/work/
43+
MagneX/
44+
libtorch_cuda/
45+
```
46+
47+
---
48+
49+
## Step 1: Download LibTorch (CUDA cu126)
1250

13-
2. Download the libtorch archive with `wget`:
51+
From your working directory:
1452

1553
```bash
16-
wget https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.7.1%2Bcu118.zip
54+
wget https://download.pytorch.org/libtorch/cu126/libtorch-shared-with-deps-2.9.1%2Bcu126.zip
55+
unzip libtorch-shared-with-deps-2.9.1+cu126.zip
56+
mv libtorch libtorch_cuda
1757
```
1858

19-
3. Unzip the archive in the same directory:
59+
This creates:
60+
61+
```
62+
libtorch_cuda/
63+
```
64+
65+
If needed, adjust your build system so it can find:
2066

21-
```bash
22-
unzip libtorch-cxx11-abi-shared-with-deps-2.7.1+cu118.zip
2367
```
68+
libtorch_cuda/include
69+
libtorch_cuda/lib
70+
```
71+
72+
---
73+
74+
## Step 2: Build MagneX with CUDA + ML Enabled
2475

25-
4. Rename the extracted folder to `libtorch_cuda`:
76+
Go to your MagneX directory:
2677

2778
```bash
28-
mv libtorch libtorch_cuda
79+
cd /path/to/work/MagneX/Exec
80+
make -j4 USE_CUDA=TRUE USE_ML=TRUE
2981
```
3082

31-
## Result
83+
This should produce an executable similar to:
3284

33-
After the steps above, you should have:
85+
```
86+
main2d.gnu.MPI.CUDA.ex
87+
```
3488

35-
- `<MAGNEX_PARENT_DIR>/MagneX`
36-
- `<MAGNEX_PARENT_DIR>/pytorch_cuda`
89+
The exact name depends on compiler and MPI configuration.

0 commit comments

Comments
 (0)