Skip to content

Reject KV head counts that cannot be sharded across the tensor-parallel mesh. - #4811

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_961244739
Open

Reject KV head counts that cannot be sharded across the tensor-parallel mesh.#4811
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_961244739

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Reject KV head counts that cannot be sharded across the tensor-parallel mesh.

Attention heads are atomic under tensor parallelism, so the per-layer KV head
count has to be divisible by the combined size of the mesh axes that
logical_axis_rules maps the kv_heads logical axis onto (by default tensor x
tensor_sequence x autoregressive).

Previously an over-sharded mesh -- for example gemma4-26b, whose global
attention layers use global_num_kv_heads: 2, with ici_tensor_parallelism=4
-- failed much later with an opaque XLA divisibility error, or silently left the
key/value projection unsharded. Attention.init_kv_w now raises a ValueError
naming the head count, the shard count, the mesh axes responsible, and how to
fix it.

…el mesh.

Attention heads are atomic under tensor parallelism, so the per-layer KV head
count has to be divisible by the combined size of the mesh axes that
`logical_axis_rules` maps the `kv_heads` logical axis onto (by default tensor x
tensor_sequence x autoregressive).

Previously an over-sharded mesh -- for example gemma4-26b, whose global
attention layers use `global_num_kv_heads: 2`, with `ici_tensor_parallelism=4`
-- failed much later with an opaque XLA divisibility error, or silently left the
key/value projection unsharded. `Attention.init_kv_w` now raises a `ValueError`
naming the head count, the shard count, the mesh axes responsible, and how to
fix it.

PiperOrigin-RevId: 961244739
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants