(self, x, u, deterministic=True)
| 349 | |
| 350 | @nn.compact |
| 351 | def __call__(self, x, u, deterministic=True): |
| 352 | out = {} |
| 353 | dpr = [ |
| 354 | float(x) for x in np.linspace( |
| 355 | 0, |
| 356 | self.drop_path, |
| 357 | self.depth)] # drop path decay |
| 358 | # Input Encoder |
| 359 | CrossAttnBlockLayer = CrossAttnEncoder1DBlock |
| 360 | if self.remat_policy not in (None, "none"): |
| 361 | logging.info(f"remat policy: {self.remat_policy}") |
| 362 | if self.remat_policy == "minimal": |
| 363 | policy = jax.checkpoint_policies.checkpoint_dots_with_no_batch_dims |
| 364 | else: |
| 365 | policy = None |
| 366 | logging.info(f"activation checkpointing {self.remat_policy}") |
| 367 | CrossAttnBlockLayer = remat( # pylint: disable=invalid-name |
| 368 | CrossAttnEncoder1DBlock, prevent_cse=True, policy=policy, static_argnums=(3,) |
| 369 | ) # "deterministic" is a static argument in CrossAttnEncoder1DBlock |
| 370 | |
| 371 | BlockLayer = Encoder1DBlock |
| 372 | if self.remat_policy not in (None, "none"): |
| 373 | logging.info(f"remat policy: {self.remat_policy}") |
| 374 | if self.remat_policy == "minimal": |
| 375 | policy = jax.checkpoint_policies.checkpoint_dots_with_no_batch_dims |
| 376 | else: |
| 377 | policy = None |
| 378 | logging.info(f"activation checkpointing {self.remat_policy}") |
| 379 | BlockLayer = remat( # pylint: disable=invalid-name |
| 380 | Encoder1DBlock, prevent_cse=True, policy=policy, static_argnums=(1,) |
| 381 | ) # "deterministic" is a static argument in Encoder1DBlock |
| 382 | |
| 383 | for lyr in range(self.depth): |
| 384 | x, out[f"block{lyr:02d}"] = BlockLayer( |
| 385 | name=f"encoderblock_{lyr}", |
| 386 | mlp_dim=self.mlp_dim, |
| 387 | depth=self.depth, |
| 388 | num_heads=self.num_heads, |
| 389 | dropout=self.dropout, |
| 390 | drop_path=dpr[lyr], |
| 391 | casual_mask=self.casual_mask, |
| 392 | use_flash_attn=self.use_flash_attn, |
| 393 | dtype=self.dtype, |
| 394 | param_dtype=self.param_dtype, |
| 395 | mesh=self.mesh |
| 396 | )(x, deterministic) |
| 397 | x, out[f"crossattn_block{lyr:02d}"] = CrossAttnBlockLayer( |
| 398 | name=f"crossattn_encoderblock_{lyr}", |
| 399 | mlp_dim=self.mlp_dim, |
| 400 | depth=self.depth, |
| 401 | num_heads=self.num_heads, |
| 402 | dropout=self.dropout, |
| 403 | drop_path=dpr[lyr], |
| 404 | casual_mask=False, |
| 405 | use_flash_attn=self.use_flash_attn, |
| 406 | dtype=self.dtype, |
| 407 | param_dtype=self.param_dtype, |
| 408 | mesh=self.mesh)(x, u, None, deterministic) |
nothing calls this directly
no outgoing calls
no test coverage detected