Skip to content

Commit 9ea0fdc

Browse files
molly-smithjeffra
andauthored
Assert mp_size is factor of model dimensions (deepspeedai#2891)
Co-authored-by: Jeff Rasley <[email protected]>
1 parent 4e06862 commit 9ea0fdc

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎.github/workflows/amd.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18-
unit-tests:
18+
amd-tests:
1919
# The type of runner that the job will run on
2020
runs-on: [self-hosted, amd]
2121

‎deepspeed/module_inject/replace_module.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,20 +464,28 @@ def _slice_embedding(child, name, conv_linear_layer):
464464

465465
def update_mp_params(child):
466466
if hasattr(child, 'n_heads'):
467+
assert child.n_heads%mp_size == 0, "n_heads ({}) must be divisible by mp_size ({})".format(child.n_heads, mp_size)
467468
child.n_heads = child.n_heads // mp_size
468469
if hasattr(child, 'inner_dim'):
470+
assert child.inner_dim%mp_size == 0, "inner_dim ({}) must be divisible by mp_size ({})".format(child.inner_dim, mp_size)
469471
child.inner_dim = child.inner_dim // mp_size
470472
if hasattr(child, 'num_heads'):
473+
assert child.num_heads%mp_size == 0, "num_heads ({}) must be divisible by mp_size ({})".format(child.num_heads, mp_size)
471474
child.num_heads = child.num_heads // mp_size
472475
if hasattr(child, 'num_attention_heads'):
476+
assert child.num_attention_heads%mp_size == 0, "num_attention_heads ({}) must be divisible by mp_size ({})".format(child.num_attention_heads, mp_size)
473477
child.num_attention_heads = child.num_attention_heads // mp_size
474478
if hasattr(child, 'num_attn_heads'):
479+
assert child.num_attn_heads%mp_size == 0, "num_attn_heads ({}) must be divisible by mp_size ({})".format(child.num_attn_heads, mp_size)
475480
child.num_attn_heads = child.num_attn_heads // mp_size
476481
if hasattr(child, 'all_head_size'):
482+
assert child.all_head_size%mp_size == 0, "all_head_size ({}) must be divisible by mp_size ({})".format(child.all_head_size, mp_size)
477483
child.all_head_size = child.all_head_size // mp_size
478484
if hasattr(child, 'embed_dim'):
485+
assert child.embed_dim%mp_size == 0, "embed_dim must ({}) be divisible by mp_size ({})".format(child.embed_dim, mp_size)
479486
child.embed_dim = child.embed_dim // mp_size
480487
if hasattr(child, 'hidden_size'):
488+
assert child.hidden_size%mp_size == 0, "hidden_size ({}) must be divisible by mp_size ({})".format(child.hidden_size, mp_size)
481489
child.hidden_size = child.hidden_size // mp_size
482490

483491
conv_linear_layer = False

0 commit comments

Comments
 (0)