-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple test in case for Flax modules
- Loading branch information
1 parent
55dac85
commit af22c1b
Showing
1 changed file
with
32 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import jax.numpy as jnp | ||
import pytest | ||
from flax import nnx | ||
from jax import Array, vmap | ||
|
||
from tjax.dataclasses import DataClassModule | ||
|
||
try: | ||
from flax import nnx | ||
except ImportError: | ||
pytest.skip("Skipping NNX graph test", allow_module_level=True) | ||
|
||
|
||
@pytest.mark.skip | ||
def test_dataclass_module() -> None: | ||
class SomeModule(nnx.Module): | ||
def __init__(self, epsilon: Array): | ||
super().__init__() | ||
self.epsilon = epsilon | ||
|
||
class SomeDataclassModule(DataClassModule): | ||
def __init__(self, rngs: nnx.Rngs) -> None: | ||
super().__init__(rngs=rngs) | ||
self.sm = SomeModule(jnp.zeros(1)) | ||
|
||
def f(m: SomeDataclassModule, x: Array) -> None: | ||
pass | ||
|
||
rngs = nnx.Rngs() | ||
module = SomeDataclassModule(rngs) | ||
z = jnp.zeros(10) | ||
vmap(f, in_axes=(None, 0))(module, z) |