31
31
from _test_utils .torch_quantization .quant_utils import get_model_size
32
32
from _test_utils .torch_quantization .quantize_common import (
33
33
auto_quantize_helper ,
34
- tensor_parallel_test_helper ,
35
- data_parallel_test_helper ,
36
34
context_parallel_test_helper ,
35
+ data_parallel_test_helper ,
37
36
data_tensor_context_parallel_test_helper ,
37
+ tensor_parallel_test_helper ,
38
38
)
39
39
from packaging .version import Version
40
40
43
43
import megatron .core
44
44
from megatron .core .parallel_state import (
45
45
destroy_model_parallel ,
46
- get_data_parallel_group ,
47
46
get_context_parallel_group ,
47
+ get_data_parallel_group ,
48
48
get_tensor_model_parallel_group ,
49
49
)
50
50
from megatron .core .tensor_parallel .layers import ColumnParallelLinear , RowParallelLinear
@@ -95,14 +95,13 @@ def test_convert_megatron_parallel_linear(distributed_setup_size_1):
95
95
# Clean up since this is not a spawned process
96
96
destroy_model_parallel ()
97
97
98
+
98
99
# 1. Tensor Parallel Test
99
100
def _test_tensor_parallel_helper (config , rank , size ):
100
101
initialize_for_megatron (tensor_model_parallel_size = 2 , seed = SEED )
101
102
model = MegatronModel (tp_size = size ).cuda ()
102
103
103
- tensor_parallel_test_helper (
104
- model , config , get_tensor_model_parallel_group ()
105
- )
104
+ tensor_parallel_test_helper (model , config , get_tensor_model_parallel_group ())
106
105
107
106
108
107
@pytest .mark .parametrize (
@@ -122,15 +121,14 @@ def test_tensor_parallel(need_2_gpus, config):
122
121
size = 2 , job = partial (_test_tensor_parallel_helper , config ), backend = "nccl"
123
122
)
124
123
124
+
125
125
# 2. Data Parallel Test
126
126
def _test_data_parallel_helper (config , rank , size ):
127
127
# TODO does this model automatically get copied to both DP ranks?
128
128
initialize_for_megatron (seed = SEED )
129
129
model = MegatronModel ().cuda ()
130
130
131
- data_parallel_test_helper (
132
- model , config , get_data_parallel_group ()
133
- )
131
+ data_parallel_test_helper (model , config , get_data_parallel_group ())
134
132
135
133
136
134
@pytest .mark .parametrize (
@@ -146,18 +144,16 @@ def _test_data_parallel_helper(config, rank, size):
146
144
],
147
145
)
148
146
def test_data_parallel (need_2_gpus , config ):
149
- spawn_multiprocess_job (
150
- size = 2 , job = partial (_test_data_parallel_helper , config ), backend = "nccl"
151
- )
147
+ spawn_multiprocess_job (size = 2 , job = partial (_test_data_parallel_helper , config ), backend = "nccl" )
148
+
152
149
153
150
# 3. Context Parallel Test
154
151
def _test_context_parallel_helper (config , rank , size ):
155
152
initialize_for_megatron (context_parallel_size = size , seed = SEED )
156
153
model = MegatronModel (cp_size = size ).cuda ()
157
154
158
- context_parallel_test_helper (
159
- model , config , get_context_parallel_group ()
160
- )
155
+ context_parallel_test_helper (model , config , get_context_parallel_group ())
156
+
161
157
162
158
@pytest .mark .parametrize (
163
159
"config" ,
@@ -176,15 +172,21 @@ def test_context_parallel(need_2_gpus, config):
176
172
size = 2 , job = partial (_test_context_parallel_helper , config ), backend = "nccl"
177
173
)
178
174
175
+
179
176
# 4. DP=2 + TP=2 + CP=2 Test (on 2*2*2=8 GPUs)
180
177
def _test_data_tensor_context_parallel_helper (config , rank , size ):
181
178
initialize_for_megatron (tensor_model_parallel_size = 2 , context_parallel_size = 2 , seed = SEED )
182
179
model = MegatronModel (tp_size = 2 , cp_size = 2 ).cuda ()
183
180
184
181
data_tensor_context_parallel_test_helper (
185
- model , config , get_data_parallel_group (), get_tensor_model_parallel_group (), get_context_parallel_group ()
182
+ model ,
183
+ config ,
184
+ get_data_parallel_group (),
185
+ get_tensor_model_parallel_group (),
186
+ get_context_parallel_group (),
186
187
)
187
188
189
+
188
190
@pytest .mark .parametrize (
189
191
"config" ,
190
192
[
@@ -199,9 +201,10 @@ def _test_data_tensor_context_parallel_helper(config, rank, size):
199
201
)
200
202
def test_data_tensor_context_parallel (need_8_gpus , config ):
201
203
spawn_multiprocess_job (
202
- size = 8 , job = partial (_test_data_tensor_context_parallel_helper , config ), backend = "nccl"
204
+ size = 8 , job = partial (_test_data_tensor_context_parallel_helper , config ), backend = "nccl"
203
205
)
204
206
207
+
205
208
def _gpt_model_provider (tp_size : int , hidden_size = 256 , vocab_size = 64 , meta_device = False ):
206
209
"""Build the model."""
207
210
0 commit comments