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

Internal #314

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions haiku/_src/lift_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,27 @@ def f():
ValueError, "must be used within the same call to init/apply"):
f.init(None)

def test_transparent_lift(self):
@parameterized.parameters(
(True,), # passes, previous test
(False,), # fails
)
def test_transparent_lift(self, inner_module_instantiated_inside_transform):
class OuterModule(module.Module):

def __call__(self, x):
x += base.get_parameter("a", shape=[10, 10], init=jnp.zeros)

def inner_fn(x):
return InnerModule(name="inner")(x)
if inner_module_instantiated_inside_transform:
# These weights will end up being called "outer/inner", ok!
def inner_fn(x):
return InnerModule(name="inner")(x)
else:
inner_module = InnerModule(name="inner")
# These weights will end up being called "outer/outer/inner",
# causing the test to fail. I would be very surprised if this is
# desider behavior.
def inner_fn(x):
return inner_module(x)

inner_transformed = transform.transform(inner_fn)
inner_params = lift.transparent_lift(inner_transformed.init)(
Expand Down