-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add explicit comms to model fwd pass
- Loading branch information
Showing
8 changed files
with
207 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
test: | ||
embedding_dim: 64 | ||
vocab_size: 256 | ||
num_head: 4 | ||
num_head: 8 | ||
block_size: 32 | ||
dropout: 0.0 | ||
N: 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
From https://github.com/kingoflolz/mesh-transformer-jax/blob/master/mesh_transformer/util.py#L99 | ||
""" | ||
import jax | ||
|
||
|
||
@jax.custom_vjp | ||
def f_psum(x): | ||
return x | ||
|
||
|
||
def f_psum_fwd(x): | ||
return f_psum(x), None | ||
|
||
|
||
def f_psum_bwd(_, g): | ||
return (jax.lax.psum(g, "mp"),) | ||
|
||
|
||
f_psum.defvjp(f_psum_fwd, f_psum_bwd) | ||
|
||
|
||
# identity in forward pass, pmean in backward | ||
@jax.custom_vjp | ||
def f_pmean(x): | ||
return x | ||
|
||
|
||
def f_pmean_fwd(x): | ||
return f_psum(x), None | ||
|
||
|
||
def f_pmean_bwd(_, g): | ||
return (jax.lax.pmean(g, "mp"),) | ||
|
||
|
||
f_pmean.defvjp(f_pmean_fwd, f_pmean_bwd) | ||
|
||
|
||
# psum in forward pass, identity in backward | ||
@jax.custom_vjp | ||
def g_psum(x): | ||
return jax.lax.psum(x, "mp") | ||
|
||
|
||
def g_psum_fwd(x): | ||
return g_psum(x), None | ||
|
||
|
||
def g_psum_bwd(_, g): | ||
return (g,) | ||
|
||
|
||
g_psum.defvjp(g_psum_fwd, g_psum_bwd) |
Oops, something went wrong.