-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[inference] add llama2 support #4898
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
2 commits
Select commit
Hold shift + click to select a range
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
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
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,69 @@ | ||
| import os | ||
|
|
||
| import pytest | ||
| import torch | ||
| from packaging import version | ||
| from transformers import LlamaForCausalLM | ||
| from transformers.models.llama.configuration_llama import LlamaConfig | ||
|
|
||
| import colossalai | ||
| from colossalai.inference.tensor_parallel.engine import TPInferEngine | ||
| from colossalai.logging import disable_existing_loggers | ||
| from colossalai.shardformer import ShardConfig | ||
| from colossalai.testing import clear_cache_before_run, parameterize, rerun_if_address_is_in_use, spawn | ||
|
|
||
| os.environ["TRANSFORMERS_NO_ADVISORY_WARNINGS"] = "true" | ||
| TPSIZE = 2 | ||
| BATCH_SIZE = 8 | ||
| MAX_INPUT_LEN = 12 | ||
| MAX_OUTPUT_LEN = 100 | ||
|
|
||
| CUDA_SUPPORT = version.parse(torch.version.cuda) > version.parse("11.5") | ||
|
|
||
|
|
||
| @parameterize( | ||
| "test_config", | ||
| [ | ||
| { | ||
| "tp_size": TPSIZE, | ||
| } | ||
| ], | ||
| ) | ||
| def run_llama_test(test_config): | ||
| llama_config = LlamaConfig( | ||
| num_hidden_layers=2, num_key_value_heads=8, bos_token_id=0, eos_token_id=1, vocab_size=1200, hidden_size=1024 | ||
| ) | ||
| model = LlamaForCausalLM(llama_config) | ||
| model = model.half() | ||
|
|
||
| shard_config = ShardConfig( | ||
| enable_tensor_parallelism=True if test_config["tp_size"] > 1 else False, inference_only=True | ||
| ) | ||
| infer_engine = TPInferEngine(model, shard_config, BATCH_SIZE, MAX_INPUT_LEN, MAX_OUTPUT_LEN) | ||
| generate_kwargs = dict(max_new_tokens=MAX_OUTPUT_LEN, do_sample=False) | ||
|
|
||
| input_tokens = { | ||
| "input_ids": torch.randint(1, 1000, (BATCH_SIZE, MAX_INPUT_LEN), device="cuda"), | ||
| "attention_mask": torch.ones((BATCH_SIZE, MAX_INPUT_LEN), device="cuda"), | ||
| } | ||
| outputs = infer_engine.generate(input_tokens, **generate_kwargs) | ||
|
|
||
| assert outputs is not None | ||
|
|
||
|
|
||
| def check_llama(rank, world_size, port): | ||
| disable_existing_loggers() | ||
| colossalai.launch(config={}, rank=rank, world_size=world_size, host="localhost", port=port, backend="nccl") | ||
| run_llama_test() | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not CUDA_SUPPORT, reason="kv-cache manager engine requires cuda version to be higher than 11.5") | ||
| @pytest.mark.dist | ||
| @rerun_if_address_is_in_use() | ||
| @clear_cache_before_run() | ||
| def test_llama(): | ||
| spawn(check_llama, TPSIZE) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_llama() |
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.