Skip to content

feat: Replace num_replicate_kv_heads with boolean replicate_kv_heads flag - #1212

Open
quic-dhirajku wants to merge 2 commits into
quic:mainfrom
quic-dhirajku:boolean_replicate_kv
Open

feat: Replace num_replicate_kv_heads with boolean replicate_kv_heads flag#1212
quic-dhirajku wants to merge 2 commits into
quic:mainfrom
quic-dhirajku:boolean_replicate_kv

Conversation

@quic-dhirajku

Copy link
Copy Markdown
Contributor
  • Replace user-facing num_replicate_kv_heads int param in qaic_configwith a boolean replicate_kv_heads flag; value computation is now fully internal and never exposed to the user.
  • maybe_apply_replicate_kv_transform reads only replicate_kv_headsfrom qaic_config; computed repeat factor is kept in hash_params and never written back into qaic_config.
  • Resolve model_config.text_config before calling calculate_num_replicate_kv_heads so VLM top-level configs correctly surface text-side head counts.

Comment on lines +1618 to +1619
num_replicate_kv_heads = self.lang_model.hash_params.get("num_replicate_kv_heads", 1)
offload_pt_weights = num_replicate_kv_heads <= 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not required.

Comment on lines +136 to +139
num_replicate_kv_heads = calculate_num_replicate_kv_heads(
num_devices=num_devices,
text_model_config=effective_config,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update this logic such that, we replicate only when num_devices>num_kv_heads and num_devices%num_kv_heads==0

@quic-dhirajku
quic-dhirajku force-pushed the boolean_replicate_kv branch 2 times, most recently from d6773e0 to ae4f304 Compare July 27, 2026 10:04
…flag

  - Replace user-facing num_replicate_kv_heads int param in qaic_configwith a boolean replicate_kv_heads flag; value computation is now fully internal and never exposed to the user.
  - maybe_apply_replicate_kv_transform reads only replicate_kv_headsfrom qaic_config; computed repeat factor is kept in hash_params and never written back into qaic_config.
  - Resolve model_config.text_config before calling calculate_num_replicate_kv_heads so VLM top-level configs correctly surface text-side head counts.

Signed-off-by: Dhiraj Kumar Sah <dhirajku@qti.qualcomm.com>
- Rewrite calculate_num_replicate_kv_heads to find the smallest repeat K
  such that new_kv_heads = num_kv_heads * K >= num_devices, satisfying
  new_kv_heads % num_devices == 0 and num_attention_heads % new_kv_heads == 0
- Return None when replication is not applicable (MHA or unachievable)
- Update unit tests to reflect new minimum-repeat semantics and correct
  expected values for MQA and MHA cases

Signed-off-by: Dhiraj Kumar Sah <dhirajku@qti.qualcomm.com>
@quic-dhirajku
quic-dhirajku force-pushed the boolean_replicate_kv branch from ae4f304 to 4842a61 Compare July 28, 2026 08:47
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.

2 participants