-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Feature] support sequence parallelism using compilation pass #16155
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 16 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9f4dd67
add reduce scatter op and register all gather
cascade812 09caae6
replace all reduce with reduce scatter and all gather
cascade812 84f4360
match first embedding
cascade812 165216d
update embedding replace pattern
cascade812 4318d65
compile graph only for specific shapes
cascade812 abd2953
clean code
cascade812 ca7fcb1
add test and rename
cascade812 ffb2e24
address comments
cascade812 4695110
update
cascade812 662e698
pass in dtype and device
cascade812 f60a871
Merge branch 'main' into sp_pass
tlrmchlsmth 9a72e10
enable rms_norm automatically if enable_sequence_parallelism=True
cascade812 552857c
add test for sq pass
cascade812 629e942
fix failed tests
cascade812 1a60865
fix failed tests
cascade812 0736045
fix failed tests
cascade812 534af36
address comments
cascade812 c16a197
minor fix
cascade812 82527a1
update test
cascade812 5b12ce5
test FixFunctionalizationPass with SequenceParallelismPass
cascade812 230ee3c
remove redundant code
cascade812 57d684d
Merge remote-tracking branch 'origin' into sp_pass
cascade812 8dc0422
remove the singleton pattern to support two LLM instances.
cascade812 b251ad5
nit
cascade812 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,100 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import os | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import torch | ||
|
||
from vllm import LLM, SamplingParams | ||
from vllm.config import CompilationConfig | ||
|
||
ALL_REDUCE_OP = "torch.ops.vllm.all_reduce.default" | ||
ALL_GATHER_OP = "torch.ops.vllm.all_gather.default" | ||
REDUCE_SCATTER_OP = "torch.ops.vllm.reduce_scatter.default" | ||
|
||
|
||
def count_comm_ops(graph_path): | ||
all_reduce_cnt = 0 | ||
all_gather_cnt = 0 | ||
reduce_scatter_cnt = 0 | ||
try: | ||
with open(graph_path) as f: | ||
for line in f: | ||
if ALL_REDUCE_OP in line: | ||
all_reduce_cnt += 1 | ||
if ALL_GATHER_OP in line: | ||
all_gather_cnt += 1 | ||
if REDUCE_SCATTER_OP in line: | ||
reduce_scatter_cnt += 1 | ||
except FileNotFoundError: | ||
print(f"Error: File '{graph_path}' not found.") | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
return all_reduce_cnt, all_gather_cnt, reduce_scatter_cnt | ||
|
||
|
||
def test_sequence_parallelism_compilation(): | ||
temp_dir = tempfile.mkdtemp() | ||
|
||
config = CompilationConfig( | ||
level=3, | ||
custom_ops=["+rms_norm"], | ||
compile_sizes=[4, 8], | ||
splitting_ops=[], | ||
) | ||
config.pass_config.enable_sequence_parallelism = True | ||
config.pass_config.dump_graph_dir = Path(temp_dir) | ||
config.pass_config.dump_graph_stages = \ | ||
cascade812 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
["before_sequence_parallelism_pass", "after_sequence_parallelism_pass"] | ||
|
||
sampling_params = SamplingParams(temperature=0, ) | ||
|
||
llm = LLM(model="unsloth/Llama-3.2-1B-Instruct", | ||
enforce_eager=False, | ||
tensor_parallel_size=2, | ||
dtype=torch.float16, | ||
max_num_batched_tokens=2048, | ||
compilation_config=config) | ||
|
||
prompts = [ | ||
"Can you calculate 19 + 20?", "How to make a cake?", | ||
"How old a baby can start to try solid food?", | ||
"What's pros and cons of using a pacifier for baby?" | ||
] | ||
|
||
answers = [ | ||
" I'll let you know if you're correct", " A step-by-step guide", | ||
" Most pediatricians recommend ", " The American Academy of Pediatrics" | ||
] | ||
|
||
outputs = llm.generate(prompts, sampling_params) | ||
for output, answer in zip(outputs, answers): | ||
cascade812 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
prompt = output.prompt | ||
generated_text = output.outputs[0].text | ||
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") | ||
assert generated_text.startswith(answer) | ||
|
||
before_graph = os.path.join(temp_dir, | ||
"before_sequence_parallelism_pass-0.py") | ||
c1, c2, c3 = count_comm_ops(before_graph) | ||
assert c1 > 0, "Expected all_reduce ops, but found 0 before \ | ||
apply sequence parallelism pass" | ||
assert c2 == 0, f"Expected 0 all_gather ops, but found {c2} before" + \ | ||
"apply sequence parallelism pass" | ||
assert c3 == 0, f"Expected 0 reduce_scatter ops, but found {c3} before" + \ | ||
"apply sequence parallelism pass" | ||
|
||
after_graph = os.path.join(temp_dir, | ||
"after_sequence_parallelism_pass-0.py") | ||
c1, c2, c3 = count_comm_ops(after_graph) | ||
|
||
assert c1 == 0, f"Expected 0 all_reduce ops, but found {c1} after" + \ | ||
"apply sequence parallelism pass" | ||
assert c2 > 0, "Expected all_gather ops, but found 0 in after" + \ | ||
"apply sequence parallelism pass" | ||
assert c3 > 0, "Expected 0 reduce_scatter ops, but found 0 after \ | ||
apply sequence parallelism pass" | ||
|
||
assert c2 == c3, f"Expected all_gather ops and reduce_scatter ops to be \ | ||
equal, but found {c2} and {c3} after apply sequence parallelism pass" |
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
Oops, something went wrong.
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.