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

[WIP] call backend JAX bindings #74

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

[WIP] call backend JAX bindings #74

wants to merge 5 commits into from

Conversation

mariogeiger
Copy link
Collaborator

import jax
import jax.numpy as jnp
import numpy as np
from jax.experimental.mosaic.gpu import profiler

import cuequivariance as cue
import cuequivariance_jax as cuex
import logging

jax.config.update("jax_enable_x64", True)
logging.basicConfig(level=logging.INFO)

e = (
    cue.descriptors.channelwise_tensor_product(
        128 * cue.Irreps(cue.O3, "0e + 1o + 2e"),
        cue.Irreps(cue.O3, "0e + 1o + 2e + 3o"),
        128 * cue.Irreps(cue.O3, "0e + 1o + 2e"),
    )
    .squeeze_modes()
    .flatten_coefficient_modes()
)

dtype = jnp.float32
dtype_math = jnp.float32
batch_size = 20_000

inputs = [
    cuex.randn(jax.random.key(i), rep, (batch_size,), dtype)
    for i, rep in enumerate(e.inputs)
]


def foo(use_custom_kernels: bool):
    return cuex.equivariant_tensor_product(
        e, use_custom_kernels=use_custom_kernels, dtype_math=dtype_math
    )


output_custom, runtime_custom = profiler.measure(foo(True), mode="cupti")(*inputs)
print(f"Runtime: {runtime_custom:.3f} ms")

output_xla, runtime_xla = profiler.measure(foo(False), mode="cupti")(*inputs)
print(f"Runtime: {runtime_xla:.3f} ms")
Runtime: 0.759 ms
Runtime: 1.164 ms

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