MCPcopy Create free account
hub / github.com/apple/axlearn / forward

Method forward

axlearn/common/attention_test.py:4525–4537  ·  view source on GitHub ↗
(self, data, **layer_kwargs)

Source from the content-addressed store, hash-verified

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
4535def _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

Callers 9

test_packingMethod · 0.45
test_rope_embMethod · 0.45
test_rope_emb_no_posMethod · 0.45
test_yarn_emb_basicMethod · 0.45
forwardMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected