Skip to content

Commit 7b4c2a5

Browse files
Augustin-Zidekcopybara-github
authored andcommitted
Use less memory in the OuterProductMean
* Uses significantly less RAM (256 -> 72 MB for 1024-token input). Inspired by #674, thank you very much for the suggestion @mooreneural. PiperOrigin-RevId: 941052434 Change-Id: I0f1cfa6a16f7f2da4371a0c0c53642ef26b1328c
1 parent 37bff5f commit 7b4c2a5

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/alphafold3/model/network/modules.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,8 @@ def compute_chunk(left_act):
402402
# Make sure that the 'b' dimension is the most minor batch like dimension
403403
# so it will be treated as the real batch by XLA (both during the forward
404404
# and the backward pass)
405-
left_act = jnp.transpose(left_act, [0, 2, 1])
406-
act = jnp.einsum('acb,ade->dceb', left_act, right_act)
407-
act = jnp.einsum('dceb,cef->dbf', act, output_w) + output_b
408-
return jnp.transpose(act, [1, 0, 2])
405+
out = jnp.einsum('abc,ade,cef->bdf', left_act, right_act, output_w)
406+
return out + output_b
409407

410408
act = mapping.inference_subbatch(
411409
compute_chunk,

0 commit comments

Comments
 (0)