-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[pipeline] add bloom model pipeline #4210
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8dee68a
bloom policy
CjhHa1 527b517
Merge branch 'feature/pipeline' of github.com:hpcaitech/ColossalAI in…
CjhHa1 9cb3005
llama pipeline forward and tests
CjhHa1 a214414
fix the output and attention_mask
CjhHa1 b625f2f
fix name
CjhHa1 67e6a71
bind argument to policy
CjhHa1 3f62937
finish bloom model
CjhHa1 582cc16
fix conflicts
CjhHa1 054d79a
test shard gpt2
CjhHa1 af807c0
clear cache
CjhHa1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
tests/test_shardformer/test_model/test_shard_bloom_pipeline.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import pytest | ||
| import torch | ||
|
|
||
| import colossalai | ||
| from colossalai.cluster import ProcessGroupMesh | ||
| from colossalai.logging import disable_existing_loggers | ||
| from colossalai.pipeline.stage_manager import PipelineStageManager | ||
| from colossalai.shardformer.policies.base_policy import Policy | ||
| from colossalai.tensor.d_tensor.api import is_customized_distributed_tensor, is_distributed_tensor | ||
| from colossalai.testing import ( | ||
| assert_hf_output_close, | ||
| clear_cache_before_run, | ||
| parameterize, | ||
| rerun_if_address_is_in_use, | ||
| spawn, | ||
| ) | ||
| from tests.kit.model_zoo import model_zoo | ||
| from tests.test_shardformer.test_model._utils import build_model, build_pipeline_model, run_forward | ||
|
|
||
|
|
||
| def check_forward_backward(org_model, sharded_model, data_gen_fn, output_transform_fn, loss_fn): | ||
| # check forward | ||
| pass | ||
|
|
||
|
|
||
| @parameterize('enable_fused_normalization', [False]) | ||
| @parameterize('enable_tensor_parallelism', [False]) | ||
| @parameterize('use_lazy_init', [False]) | ||
| #TODO: merge this into test_shard_bloom | ||
| def run_bloom_test(enable_fused_normalization, enable_tensor_parallelism, use_lazy_init): | ||
| DP_DIM, PP_DIM = 0, 1 | ||
| DP_SIZE, PP_SIZE = 2, 2 | ||
| RANK_TO_COORDINATE = { | ||
| 0: (0, 0), | ||
| 1: (0, 1), | ||
| 2: (1, 0), | ||
| 3: (1, 1), | ||
| } | ||
| PP_RANKS_IN_GROUP = { | ||
| 0: [0, 1], | ||
| 1: [0, 1], | ||
| 2: [2, 3], | ||
| 3: [2, 3], | ||
| } | ||
| pg_mesh = ProcessGroupMesh(DP_SIZE, PP_SIZE) | ||
| stage_manager = PipelineStageManager(pg_mesh, PP_DIM) | ||
|
|
||
| sub_model_zoo = model_zoo.get_sub_registry('transformers_bloom') | ||
| x = torch.randint(0, 1000, (2, 3)).cuda() | ||
| hidden_states = torch.randint(0, 1000, (2, 3, 64)).to(torch.float32).cuda() | ||
| for name, (model_fn, data_gen_fn, output_transform_fn, loss_fn, _) in sub_model_zoo.items(): | ||
| if name == 'transformers_bloom': | ||
| org_model, sharded_model = build_pipeline_model(model_fn, stage_manager, enable_fused_normalization, | ||
| enable_tensor_parallelism, use_lazy_init) | ||
| if stage_manager.stage == 0: | ||
| attention_mask = torch.ones_like(x).cuda() | ||
| output = sharded_model(input_ids=x, attention_mask=attention_mask) | ||
| assert output['hidden_states'].shape == (2, 3, 64) | ||
| else: | ||
| attention_mask = torch.ones((2, 3)).cuda() | ||
| output = sharded_model( | ||
| hidden_states=hidden_states, | ||
| attention_mask=attention_mask, | ||
| ) | ||
| assert output[0].shape == (2, 3, 64) | ||
|
|
||
| torch.cuda.empty_cache() | ||
|
|
||
|
|
||
| def check_bloom(rank, world_size, port): | ||
| disable_existing_loggers() | ||
| colossalai.launch(config={}, rank=rank, world_size=world_size, host='localhost', port=port, backend='nccl') | ||
| run_bloom_test() | ||
|
|
||
|
|
||
| @pytest.mark.dist | ||
| @rerun_if_address_is_in_use() | ||
| @clear_cache_before_run() | ||
| def test_bloom(): | ||
| spawn(check_bloom, 4) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_bloom() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.