Skip to content

Commit 1297065

Browse files
committed
lint
Signed-off-by: wdykas <wdykas@nvidia.com>
1 parent b3e1bd8 commit 1297065

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

‎megatron/core/inference/shards.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def build_inference_pg_collection(
7575

7676
# Expert DP size (world = expt_tp * ep * expt_dp * pp)
7777
expt_dp_size = world_size // (expt_tp_size * ep_size * pp_size)
78-
assert expt_dp_size >= 1 and (
79-
expt_tp_size * ep_size * expt_dp_size * pp_size
80-
) == world_size, (
78+
assert expt_dp_size >= 1 and (expt_tp_size * ep_size * expt_dp_size * pp_size) == world_size, (
8179
f"World size ({world_size}) must be divisible by expt_tp*ep*pp "
8280
f"({expt_tp_size * ep_size * pp_size})"
8381
)
@@ -86,15 +84,11 @@ def build_inference_pg_collection(
8684

8785
if use_tp_pp_dp_mapping:
8886
decoder_grid = HyperCommGrid(
89-
[tp_size, cp_size, pp_size, dp_size],
90-
["tp", "cp", "pp", "dp"],
91-
rank_offset=rank_offset,
87+
[tp_size, cp_size, pp_size, dp_size], ["tp", "cp", "pp", "dp"], rank_offset=rank_offset
9288
)
9389
else:
9490
decoder_grid = HyperCommGrid(
95-
[tp_size, cp_size, dp_size, pp_size],
96-
["tp", "cp", "dp", "pp"],
97-
rank_offset=rank_offset,
91+
[tp_size, cp_size, dp_size, pp_size], ["tp", "cp", "dp", "pp"], rank_offset=rank_offset
9892
)
9993

10094
tp_group = decoder_grid.create_pg("tp")

‎tests/unit_tests/inference/test_inference_shards.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313

1414
def test_shard_spec_objects_match_string_parsing():
15-
objs = [InferenceShardSpec(tp=2, role="prefill"),
16-
InferenceShardSpec(tp=1, dp=2, role="decode")]
15+
objs = [InferenceShardSpec(tp=2, role="prefill"), InferenceShardSpec(tp=1, dp=2, role="decode")]
1716
assert normalize_shard_specs(objs, 4) == parse_inference_shards_spec(
1817
"tp=2,role=prefill+tp=1,dp=2,role=decode", 4
1918
)
@@ -34,7 +33,14 @@ def test_parse_defaults_and_dp_and_role():
3433
assert specs[0] == InferenceShardSpec(tp=2, role="prefill")
3534
assert specs[1] == InferenceShardSpec(tp=1, dp=2, role="decode")
3635
# dict form (serialization / external consumers) carries the resolved keys.
37-
assert specs[0].to_dict() == {"tp": 2, "pp": 1, "ep": 1, "dp": 1, "expt_tp": 2, "role": "prefill"}
36+
assert specs[0].to_dict() == {
37+
"tp": 2,
38+
"pp": 1,
39+
"ep": 1,
40+
"dp": 1,
41+
"expt_tp": 2,
42+
"role": "prefill",
43+
}
3844

3945

4046
def test_parse_partitions_world_with_dp():
@@ -60,7 +66,9 @@ def test_plus_and_semicolon_separators_equivalent():
6066
def test_cp_accepted_only_when_one():
6167
# cp is a recognized key (clear error, not "unknown key") but must be 1:
6268
# inference shards don't context-parallelize.
63-
assert parse_inference_shards_spec("tp=2,cp=1", world_size=2) == [InferenceShardSpec(tp=2, cp=1)]
69+
assert parse_inference_shards_spec("tp=2,cp=1", world_size=2) == [
70+
InferenceShardSpec(tp=2, cp=1)
71+
]
6472
with pytest.raises(ValueError):
6573
InferenceShardSpec(tp=1, cp=2)
6674
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)