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

Add multi-vector channel version #1

Open
smsharma opened this issue Jun 5, 2023 · 0 comments
Open

Add multi-vector channel version #1

smsharma opened this issue Jun 5, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@smsharma
Copy link
Owner

smsharma commented Jun 5, 2023

Based on a talk by Dan Levy (Mila) at the Cosmic Connections conference.

Sketch of code:

from einops import repeat, rearrange
import jax.numpy as jnp

n_channels = 5
X_i = repeat(x_i, "n d -> n d c", c=n_channels)
X_j = repeat(x_j, "n d -> n d c", c=n_channels)
D_ij2 = jnp.sum((X_i - X_j) ** 2, axis=1, keepdims=True)
Phi_e = MLP([d_hidden] * (n_layers), activation=activation, activate_final=True)
Phi_x_last_layer = nn.Dense(n_channels * n_channels, use_bias=False, kernel_init=jax.nn.initializers.variance_scaling(scale=1e-3, mode="fan_in", distribution="truncated_normal"))
D_ij2 = jax.vmap(fourier_features, in_axes=(2), out_axes=(2))(D_ij2) if use_fourier_features else D_ij2  # FF
D_ij2 = D_ij2.reshape(D_ij2.shape[0], -1)  # Flatten
message_scalars = jnp.concatenate([D_ij2, concats], axis=-1)
m_ij = Phi_e(message_scalars)
trans = Phi_x_last_layer(phi_x(m_ij))
trans = rearrange(trans, "n (c1 c2) -> n c1 c2", c1=n_channels, c2=n_channels)
out = jnp.matmul((X_i - X_j), trans)  # n_dim x n_channels
@smsharma smsharma added the enhancement New feature or request label Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant