code: def test_hk_jit(self, module_fn: ModuleFn, shape, dtype, init):
      rng = jax.random.PRNGKey(42)
      if jnp.issubdtype(dtype, jnp.integer):
          x = jax.random.randint(rng, shape, 0, np.prod(shape), dtype)
      else:
          x = jax.random.uniform(rng, shape, dtype)
  
      def g(x, jit=False):
          mod = module_fn()
          if jit:
              mod = stateful.jit(mod)
          return mod(x)
  
      f = hk.transform_with_state(g)
  
      assert_allclose = functools.partial(
          np.testing.assert_allclose, atol=1e-4
      )
  
      # NOTE: We shard init/apply tests since some modules are expensive to jit
      # (e.g. ResNet50 takes ~60s to compile and we compile it twice per test).
      if init:
          jax.tree_util.tree_map(
              assert_allclose,
              jax.jit(f.init)(rng, x),
              f.init(rng, x, jit=True),
          )
  
      else:
          params, state = f.init(rng, x)
          jax.tree_util.tree_map(
              assert_allclose,
              jax.jit(f.apply)(params, state, rng, x),
              f.apply(params, state, rng, x, jit=True),
          )
  
file_path: dm-haiku/haiku/_src/integration/hk_transforms_test.py
imports: import functools
  from absl.testing import absltest
  from absl.testing import parameterized
  import haiku
  from haiku._src import stateful
  from haiku._src import test_utils
  from haiku._src.integration import descriptors
  import jax
  import jax.numpy
  import numpy
label_desc: Use image node_id 1 for calling the HaikuTransformsTest obj's underlying member method code with example usage: obj.test_hk_jit(module_fn, shape, dtype, init) and returns: mod