(self, batch_size, max_length)
| 141 | super().__init__(config, module, input_shape=input_shape, seed=seed, dtype=dtype, _do_init=_do_init) |
| 142 | |
| 143 | def init_cache(self, batch_size, max_length): |
| 144 | # init input variables to retrieve cache |
| 145 | input_ids = jnp.ones((batch_size, max_length)) |
| 146 | attention_mask = jnp.ones_like(input_ids) |
| 147 | segment_ids = jnp.zeros_like(input_ids) |
| 148 | position_ids = jnp.broadcast_to(jnp.arange(jnp.atleast_2d(input_ids).shape[-1]), input_ids.shape) |
| 149 | vision_masks = jnp.ones((batch_size, max_length), dtype=bool) |
| 150 | |
| 151 | init_variables = self.module.init( |
| 152 | jax.random.PRNGKey(0), input_ids, vision_masks, attention_mask, segment_ids, position_ids, return_dict=False, init_cache=True |
| 153 | ) |
| 154 | return init_variables["cache"] |
| 155 | |
| 156 | def init_weights(self, rng, input_shape, params=None): |
| 157 | # init input tensors |
no outgoing calls
no test coverage detected