Skip to content

Commit

Permalink
fix(enable_qkv_fusion): minor fix for qkv fusion (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
zigzagcai authored Sep 23, 2024
1 parent c5c08de commit f2f8e5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion internlm/model/modules/mha.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def _convert_cu_seqlens_for_qksplited(kwargs: Dict):
def split_fused_wqkv_weight(wqkv, *args, **kwargs): # pylint: disable=W0613
q_dim = kwargs["q_dim"]
kv_dim = kwargs["kv_dim"]
wq, wk, wv = torch.split(wqkv, [q_dim, kv_dim, kv_dim], dim=0)
split_size = [q_dim, kv_dim, kv_dim]
assert (q_dim + 2 * kv_dim) % wqkv.size(0) == 0
divisor = (q_dim + 2 * kv_dim) // wqkv.size(0)
wq, wk, wv = torch.split(wqkv, [x // divisor for x in split_size], dim=0)
return wq, wk, wv


Expand Down
8 changes: 5 additions & 3 deletions internlm/train/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,12 @@ def inject_model_helper(model: Union[nn.Module, nn.ModuleList], inject_info: Opt
for mod in modules:
inject_funcs[mod](_chunk, inject, interactive)

# reset parameters
# reset parameters and move model to device
for _chunk in model:
if inject and reset_params:
_chunk.reset_parameters()
if inject:
if reset_params:
_chunk.reset_parameters()
_chunk.to(get_current_device())

# inject configs
if inject:
Expand Down

0 comments on commit f2f8e5b

Please sign in to comment.