(self, data, **layer_kwargs)
| 4523 | # [batch, length, dim]. |
| 4524 | output = self.stack(data, **layer_kwargs) |
| 4525 | x = output.data |
| 4526 | x_mean = jnp.mean(x, axis=1, keepdims=True) |
| 4527 | # [batch, length]. |
| 4528 | x_var = jnp.sum((x - x_mean) ** 2, axis=-1) |
| 4529 | loss = jnp.mean(x_var) |
| 4530 | if cfg.output_self_attention_kv_state: |
| 4531 | return loss, {"mean": x_mean, "self_attention_kv_state": output.self_attention_kv_state} |
| 4532 | return loss, {"mean": x_mean} |
| 4533 | |
| 4534 | |
| 4535 | def _recursive_stack(inputs: Nested[Tensor], axis=0): |
| 4536 | def stack(*xs): |
| 4537 | return jnp.stack(xs, axis=axis) |
| 4538 | |
| 4539 | return {"layer": utils.vectorized_tree_map(stack, *inputs.values())} |
| 4540 |
no outgoing calls
no test coverage detected