Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nnx] add PrefixMapping #4278

Merged
merged 1 commit into from
Oct 16, 2024
Merged

[nnx] add PrefixMapping #4278

merged 1 commit into from
Oct 16, 2024

Conversation

cgarciae
Copy link
Collaborator

@cgarciae cgarciae commented Oct 9, 2024

What does this PR do?

Adds the PrefixMapping API to allow different "Lift Symbols" to result in the same consistent aliasing by checking the value each Variable resolves to at runtime. For example, the following code would previously be treated as inconsistent as m is passed the prefixes 0, sa1, and sa2 in in_axes, and these prefixes are not the same value. However, now this program is accepted as its evaluated that the kernel and bias Variables on m are being vectorized in axes 0 by all arguments 0, sa1, and sa2, resulting in a consistent aliasing.

m = nnx.Linear(3, 3, rngs=nnx.Rngs(0))

sa1 = nnx.StateAxes({...: 0})
sa2 = nnx.StateAxes({nnx.Param: 0})
@nnx.vmap(in_axes=(0, sa1, sa2))
def f(m1, m2, m3):
  pass

f(m, m, m)

@copybara-service copybara-service bot merged commit 39565d3 into main Oct 16, 2024
18 checks passed
@copybara-service copybara-service bot deleted the prefix-mapping branch October 16, 2024 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant