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

jit model init #832

Merged
merged 1 commit into from Jul 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions netket/vqs/mc_state.py
Expand Up @@ -49,7 +49,14 @@ def compute_chain_length(n_chains, n_samples):


@partial(jax.jit, static_argnums=0)
def apply(fun, *args):
def jit_evaluate(fun: Callable, *args):
"""
call `fun(*args)` inside of a `jax.jit` frame.

Args:
fun: the hashable callable to be evaluated.
args: the arguments to the function.
"""
return fun(*args)


Expand Down Expand Up @@ -229,7 +236,7 @@ def init(self, seed=None, dtype=None):

dummy_input = jnp.zeros((1, self.hilbert.size), dtype=dtype)

variables = self._init_fun({"params": key}, dummy_input)
variables = jit_evaluate(self._init_fun, {"params": key}, dummy_input)
self.variables = variables

@property
Expand Down Expand Up @@ -434,7 +441,7 @@ def log_value(self, σ: jnp.ndarray) -> jnp.ndarray:

Given a batch of inputs (Nb, N), returns a batch of outputs (Nb,).
"""
return apply(self._apply_fun, self.variables, σ)
return jit_evaluate(self._apply_fun, self.variables, σ)

@deprecated("Use MCState.log_value(σ) instead.")
def evaluate(self, σ: jnp.ndarray) -> jnp.ndarray:
Expand Down