-
Notifications
You must be signed in to change notification settings - Fork 200
Sync amax & AWQ-Lite act_scale in context parallel/data parallel [OMNIML-2813] #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
f17131f
42519cc
264adbb
7cbe5b9
1f7d17e
71a9f7a
d02365c
5a572da
fc0bb88
95da832
34c11ef
10e3e2b
9f0691f
fa8f4c8
d1fac44
22b8b73
ca7c0e8
3f857a3
93bfd52
6761109
291cfa3
a106dd9
50000dd
2664563
440ca48
2e8ef58
5cb380c
afe6f34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||
| import megatron.core.tensor_parallel.layers as megatron_parallel | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import megatron.core.transformer.mlp as megatron_mlp | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import torch | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.core.parallel_state import get_data_parallel_group | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.core.tensor_parallel.mappings import gather_from_sequence_parallel_region | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.core.transformer import MegatronModule | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from megatron.core.transformer.utils import make_sharded_tensors_for_checkpoint | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -217,9 +218,15 @@ class _MegatronParallelLinear(_ParallelLinear): | |||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _setup(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| data_parallel_group = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| data_parallel_group = get_data_parallel_group(with_context_parallel=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except AssertionError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| data_parallel_group = get_data_parallel_group() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.parallel_state = ParallelState( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| getattr(mcore_parallel, "get_expert_data_parallel_group", "get_data_parallel_group")(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| data_parallel_group, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| mcore_parallel.get_tensor_model_parallel_group(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| mcore_parallel.get_context_parallel_group(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
224
to
233
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard
Something along these lines keeps the DP-only path working: - self.parallel_state = ParallelState(
- data_parallel_group,
- mcore_parallel.get_tensor_model_parallel_group(),
- mcore_parallel.get_context_parallel_group(),
- )
+ try:
+ context_parallel_group = mcore_parallel.get_context_parallel_group()
+ except AssertionError:
+ context_parallel_group = -1
+ self.parallel_state = ParallelState(
+ data_parallel_group,
+ mcore_parallel.get_tensor_model_parallel_group(),
+ context_parallel_group,
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| super()._setup() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we dont need separate methods |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as https://github.com/NVIDIA/TensorRT-Model-Optimizer/pull/359/files#r2410523895 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,9 @@ | |
| from _test_utils.torch_quantization.quant_utils import get_model_size | ||
| from _test_utils.torch_quantization.quantize_common import ( | ||
| auto_quantize_helper, | ||
| context_parallel_test_helper, | ||
| data_parallel_test_helper, | ||
| data_tensor_context_parallel_test_helper, | ||
| tensor_parallel_test_helper, | ||
| ) | ||
| from packaging.version import Version | ||
|
|
@@ -40,6 +43,7 @@ | |
| import megatron.core | ||
| from megatron.core.parallel_state import ( | ||
| destroy_model_parallel, | ||
| get_context_parallel_group, | ||
| get_data_parallel_group, | ||
| get_tensor_model_parallel_group, | ||
| ) | ||
|
|
@@ -92,13 +96,12 @@ def test_convert_megatron_parallel_linear(distributed_setup_size_1): | |
| destroy_model_parallel() | ||
|
|
||
|
|
||
| # 1. Tensor Parallel Test | ||
| def _test_tensor_parallel_helper(config, rank, size): | ||
| initialize_for_megatron(tensor_model_parallel_size=2, seed=SEED) | ||
| model = MegatronModel(size).cuda() | ||
| model = MegatronModel(tp_size=size).cuda() | ||
|
|
||
| tensor_parallel_test_helper( | ||
| model, config, get_tensor_model_parallel_group(), get_data_parallel_group() | ||
| ) | ||
| tensor_parallel_test_helper(model, config, get_tensor_model_parallel_group()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
|
|
@@ -119,6 +122,89 @@ def test_tensor_parallel(need_2_gpus, config): | |
| ) | ||
|
|
||
|
|
||
| # 2. Data Parallel Test | ||
| def _test_data_parallel_helper(config, rank, size): | ||
| # TODO does this model automatically get copied to both DP ranks? | ||
| initialize_for_megatron(seed=SEED) | ||
| model = MegatronModel().cuda() | ||
|
|
||
| data_parallel_test_helper(model, config, get_data_parallel_group()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "config", | ||
| [ | ||
| mtq.INT8_DEFAULT_CFG, | ||
| mtq.FP8_DEFAULT_CFG, | ||
| mtq.W4A8_AWQ_BETA_CFG, | ||
| mtq.INT8_SMOOTHQUANT_CFG, | ||
| mtq.INT4_BLOCKWISE_WEIGHT_ONLY_CFG, | ||
| mtq.INT4_AWQ_CFG, | ||
| mtq.NVFP4_DEFAULT_CFG, | ||
| ], | ||
| ) | ||
| def test_data_parallel(need_2_gpus, config): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For data parallel and context parallel, do we really need to test all configs? Or testing one sufficient given that we have extensive tensor parallel tests? |
||
| spawn_multiprocess_job(size=2, job=partial(_test_data_parallel_helper, config), backend="nccl") | ||
|
|
||
|
|
||
| # 3. Context Parallel Test | ||
| def _test_context_parallel_helper(config, rank, size): | ||
| initialize_for_megatron(context_parallel_size=size, seed=SEED) | ||
| model = MegatronModel(cp_size=size).cuda() | ||
|
|
||
| context_parallel_test_helper(model, config, get_context_parallel_group()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "config", | ||
| [ | ||
| mtq.INT8_DEFAULT_CFG, | ||
| mtq.FP8_DEFAULT_CFG, | ||
| mtq.W4A8_AWQ_BETA_CFG, | ||
| mtq.INT8_SMOOTHQUANT_CFG, | ||
| mtq.INT4_BLOCKWISE_WEIGHT_ONLY_CFG, | ||
| mtq.INT4_AWQ_CFG, | ||
| mtq.NVFP4_DEFAULT_CFG, | ||
| ], | ||
| ) | ||
| def test_context_parallel(need_2_gpus, config): | ||
| spawn_multiprocess_job( | ||
| size=2, job=partial(_test_context_parallel_helper, config), backend="nccl" | ||
| ) | ||
|
|
||
|
|
||
| # 4. DP=2 + TP=2 + CP=2 Test (on 2*2*2=8 GPUs) | ||
| def _test_data_tensor_context_parallel_helper(config, rank, size): | ||
| initialize_for_megatron(tensor_model_parallel_size=2, context_parallel_size=2, seed=SEED) | ||
| model = MegatronModel(tp_size=2, cp_size=2).cuda() | ||
|
|
||
| data_tensor_context_parallel_test_helper( | ||
| model, | ||
| config, | ||
| get_data_parallel_group(), | ||
| get_tensor_model_parallel_group(), | ||
| get_context_parallel_group(), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "config", | ||
| [ | ||
| mtq.INT8_DEFAULT_CFG, | ||
| mtq.FP8_DEFAULT_CFG, | ||
| mtq.W4A8_AWQ_BETA_CFG, | ||
| mtq.INT8_SMOOTHQUANT_CFG, | ||
| mtq.INT4_BLOCKWISE_WEIGHT_ONLY_CFG, | ||
| mtq.INT4_AWQ_CFG, | ||
| mtq.NVFP4_DEFAULT_CFG, | ||
| ], | ||
| ) | ||
| def test_data_tensor_context_parallel(need_8_gpus, config): | ||
| spawn_multiprocess_job( | ||
| size=8, job=partial(_test_data_tensor_context_parallel_helper, config), backend="nccl" | ||
| ) | ||
|
|
||
|
|
||
| def _gpt_model_provider(tp_size: int, hidden_size=256, vocab_size=64, meta_device=False): | ||
| """Build the model.""" | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.