Skip to content

Gk/tp strong scaling clean - #60

Merged
lucaslie merged 5 commits into
feat/ad_2025_06_13from
gk/tp_strong_scaling_clean
Jun 14, 2025
Merged

Gk/tp strong scaling clean#60
lucaslie merged 5 commits into
feat/ad_2025_06_13from
gk/tp_strong_scaling_clean

Conversation

@greg-kwasniewski1

@greg-kwasniewski1 greg-kwasniewski1 commented Jun 11, 2025

Copy link
Copy Markdown

[https://github.com/NVIDIA/issues/4308][bug] TP > num_kv_heads fix

Description

Current TP strategy always distributes weight matrix either row-wise or column-wise using the entire WORLD_SIZE. For weight matrices such as w_k of shape [num_kv_heads * head_dim, embd], if TP > num_kv_heads , this results in distributing the individual heads, which leads to incorrect attention computation.

This PR fixes it by passing optional parameter min_local_size, derived from model.config to the column_row_shard logic. Then it calculates maximum number of distributed groups num_groups = world_size * min_local_shape / t.shape[d].
If world_size > max_split_size, then the sharder groups ranks into num_groups groups, each rank in the group
sharing (replicating) the same slice of the weight tensor.

Test Coverage

Added new class GQABlock to test_graph_sharding.py unittest, which explicitly specifies q_proj, k_proj, v_proj, with num_kv_heads < num_heads.

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
Comment thread tensorrt_llm/_torch/auto_deploy/transformations/transform.py Outdated
Comment thread tensorrt_llm/_torch/auto_deploy/transformations/library/sharding.py Outdated
Comment thread tensorrt_llm/_torch/auto_deploy/transformations/library/sharding.py Outdated
Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
@greg-kwasniewski1

Copy link
Copy Markdown
Author

@lucaslie Implemented custom GQA_block in the test_graph_sharding.py. Now everything works nicely.

@greg-kwasniewski1
greg-kwasniewski1 marked this pull request as ready for review June 12, 2025 19:12

@lucaslie lucaslie left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@greg-kwasniewski1 , this looks great. I kicked off a dashboard run with your changes: https://gitlab-master.nvidia.com/ftp/infra/autodeploy-dashboard/-/pipelines/30068368

I think it's worth checking what happens and if all models pass as before. Let's monitor it and see what happens

Nevermind, Let's get it merged and look at the dashboard tomorrow morning after it ran on the feature branch :)

@lucaslie
lucaslie merged commit 2c41e65 into feat/ad_2025_06_13 Jun 14, 2025
lucaslie pushed a commit that referenced this pull request Jun 24, 2025
* Fixed TP strong scaling if TP > num_kv_heads

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>

* Fixed test_graph_sharding. Attention uses simple_shard

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>

* head_dim inferred from the graph directly. Fixed test_graph_sharding.py

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>

* changed GQA block to fit column_row_shard heuristic requirements

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>

* Fixed parameter count

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>

---------

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
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