Skip to content

Commit 8b3e58a

Browse files
authored
Fix AMD wave barrier in HIP kernels; add NequIP-OAM-L test problems (#217)
1 parent 2054bc5 commit 8b3e58a

5 files changed

Lines changed: 73 additions & 3 deletions

File tree

openequivariance/openequivariance/benchmark/problems.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,56 @@ def __init__(
196196
)
197197

198198

199+
class NequIPTPP(TPProblem):
200+
"""
201+
Taken from nequip.nn.interaction_block.InteractionBlock:
202+
https://github.com/mir-group/nequip/blob/27d9d2182da918ab7be0017d8300e53278f5e00e/nequip/nn/interaction_block.py#L89-L116
203+
"""
204+
205+
def __init__(
206+
self,
207+
feature_irreps_in: Irreps,
208+
irreps_edge_attr: Irreps,
209+
feature_irreps_out: Irreps,
210+
label: Optional[str] = None,
211+
irrep_dtype=np.float32,
212+
weight_dtype=np.float32,
213+
):
214+
feature_irreps_in = Irreps(feature_irreps_in)
215+
irreps_edge_attr = Irreps(irreps_edge_attr)
216+
feature_irreps_out = Irreps(feature_irreps_out)
217+
218+
irreps_mid = []
219+
instructions = []
220+
for i, (mul, ir_in) in enumerate(feature_irreps_in):
221+
for j, (_, ir_edge) in enumerate(irreps_edge_attr):
222+
for ir_out in ir_in * ir_edge:
223+
if ir_out in feature_irreps_out:
224+
k = len(irreps_mid)
225+
irreps_mid.append((mul, ir_out))
226+
instructions.append((i, j, k, "uvu", True))
227+
228+
irreps_mid = Irreps(irreps_mid)
229+
irreps_mid, p, _ = irreps_mid.sort()
230+
231+
instructions = [
232+
(i_in1, i_in2, p[i_out], mode, train)
233+
for i_in1, i_in2, i_out, mode, train in instructions
234+
]
235+
236+
super().__init__(
237+
feature_irreps_in,
238+
irreps_edge_attr,
239+
irreps_mid,
240+
instructions,
241+
internal_weights=False,
242+
shared_weights=False,
243+
label=label,
244+
irrep_dtype=irrep_dtype,
245+
weight_dtype=weight_dtype,
246+
)
247+
248+
199249
FCTPP = FullyConnectedTPProblem
200250
CTPP = ChannelwiseTPP
201251

@@ -347,6 +397,17 @@ def nequip_problems():
347397
]
348398

349399

400+
# https://github.com/mir-group/nequip/blob/27d9d2182da918ab7be0017d8300e53278f5e00e/nequip/model/nequip_models.py#L30-L58
401+
def nequip_oam_problems():
402+
sh = "1x0e+1x1o+1x2e+1x3o"
403+
hidden = "128x0e+64x1o+32x2e+32x3o"
404+
return [
405+
NequIPTPP("32x0e", sh, hidden, "nequip-oam-l-first-layer"),
406+
NequIPTPP(hidden, sh, hidden, "nequip-oam-l-main-layers"),
407+
NequIPTPP(hidden, sh, "128x0e", "nequip-oam-l-last-layer"),
408+
]
409+
410+
350411
# https://github.com/atomicarchitects/nequix/blob/main/configs/nequix-mp-1.yml
351412
def nequix_problems():
352413
return [

openequivariance/openequivariance/templates/jinja_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ def get_jinja_environment(is_hip=False):
2626
env.globals["enumerate"] = enumerate
2727

2828
env.globals["is_hip"] = is_hip
29-
env.globals["syncwarp"] = "__threadfence_block()" if is_hip else "__syncwarp()"
29+
env.globals["syncwarp"] = (
30+
'__builtin_amdgcn_fence(__ATOMIC_RELEASE, "wavefront");__builtin_amdgcn_wave_barrier();__builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "wavefront");'
31+
if is_hip
32+
else "__syncwarp()"
33+
)
3034
env.globals["atomic_add"] = "unsafeAtomicAdd" if is_hip else "atomicAdd"
3135

3236
if is_hip:

openequivariance/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ dev = [
5656
"pytest",
5757
"pytest-check",
5858
"pytest-subtests",
59-
"mace-torch",
6059
"torch_geometric",
6160
"cmake"
6261
]

tests/batch_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
diffdock_problems,
1515
e3nn_torch_tetris_poly_problems,
1616
mace_problems,
17+
nequip_oam_problems,
1718
nequip_problems,
1819
)
1920
from pytest_check import check
@@ -131,6 +132,7 @@ class TestProductionModels(TPCorrectness):
131132
production_model_tpps = (
132133
mace_problems()
133134
+ nequip_problems()
135+
+ nequip_oam_problems()
134136
+ e3nn_torch_tetris_poly_problems()
135137
+ diffdock_problems()
136138
)

tests/conv_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
mace_problems,
2020
diffdock_problems,
2121
e3tools_problems,
22+
nequip_oam_problems,
2223
)
2324

2425

@@ -172,7 +173,10 @@ def test_tp_triple_bwd(self, conv_object, graph, with_jax):
172173

173174
class TestProductionModels(ConvCorrectness):
174175
production_model_tpps = (
175-
mace_problems() + diffdock_problems() + [e3tools_problems()[0]]
176+
mace_problems()
177+
+ diffdock_problems()
178+
+ [e3tools_problems()[0]]
179+
+ nequip_oam_problems()
176180
)
177181

178182
@pytest.fixture(params=production_model_tpps, ids=lambda x: x.label, scope="class")

0 commit comments

Comments
 (0)