| 344 | |
| 345 | |
| 346 | class FlaxVideoLLaMAForCausalLMModule(nn.Module): |
| 347 | config: VideoLLaMAConfig |
| 348 | dtype: jnp.dtype = jnp.float32 |
| 349 | param_dtype: jnp.dtype=jnp.float32 |
| 350 | precision: Optional[Union[jax.lax.Precision, str]]=None |
| 351 | |
| 352 | def setup(self): |
| 353 | self.transformer = FlaxVideoLLaMAModule(self.config, dtype=self.dtype) |
| 354 | self.vision_head = nn.Dense( |
| 355 | self.config.vision_vocab_size, |
| 356 | dtype=self.dtype, |
| 357 | param_dtype=self.param_dtype, |
| 358 | use_bias=False, |
| 359 | kernel_init=jax.nn.initializers.normal(stddev=self.config.initializer_range), |
| 360 | precision=self.precision, |
| 361 | ) |
| 362 | self.lm_head = nn.Dense( |
| 363 | self.config.vocab_size, |
| 364 | dtype=self.dtype, |
| 365 | param_dtype=self.param_dtype, |
| 366 | use_bias=False, |
| 367 | kernel_init=jax.nn.initializers.normal(stddev=self.config.initializer_range), |
| 368 | precision=self.precision, |
| 369 | ) |
| 370 | |
| 371 | def __call__( |
| 372 | self, |
| 373 | input_ids, |
| 374 | vision_masks, |
| 375 | attention_mask=None, |
| 376 | segment_ids=None, |
| 377 | position_ids=None, |
| 378 | deterministic: bool = True, |
| 379 | init_cache: bool = False, |
| 380 | output_attentions: bool = False, |
| 381 | output_hidden_states: bool = False, |
| 382 | return_dict: bool = True, |
| 383 | ): |
| 384 | batch_size, seq_length = input_ids.shape |
| 385 | if attention_mask is None: |
| 386 | attention_mask = jnp.ones_like(input_ids) |
| 387 | if segment_ids is None: |
| 388 | segment_ids = jnp.zeros_like(input_ids) |
| 389 | if position_ids is None: |
| 390 | position_ids = jnp.broadcast_to( |
| 391 | jnp.clip(jnp.cumsum(attention_mask, axis=-1) - 1, a_min=0), |
| 392 | (batch_size, seq_length) |
| 393 | ) |
| 394 | |
| 395 | |
| 396 | outputs = self.transformer( |
| 397 | input_ids, |
| 398 | vision_masks, |
| 399 | attention_mask, |
| 400 | segment_ids, |
| 401 | position_ids, |
| 402 | deterministic=deterministic, |
| 403 | init_cache=init_cache, |
nothing calls this directly
no outgoing calls
no test coverage detected