Skip to content
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

[Model] MLPSpeculator speculative decoding support #4947

Merged
merged 42 commits into from
Jun 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
efb0599
initial commit of mlp_speculator and hidden_states_worker to support …
JRosenkranz May 20, 2024
7a8eeff
Merge branch 'main' into mlp_speculator
JRosenkranz May 20, 2024
667ef88
removed fms_extras import
JRosenkranz May 20, 2024
d534ef2
updated with a working non-batch version - a lot hardcoded
JRosenkranz May 21, 2024
17541b6
updated experimental with working version - eager
JRosenkranz May 22, 2024
ac5a1da
fixed bug with speculator outputs
JRosenkranz May 22, 2024
6ba9a1e
removed comments; swapped to sampling in the example
JRosenkranz May 22, 2024
cb3aacf
Introduce MLPSpeculatorWorker and corresponding refactor
tdoublep May 27, 2024
bf2f102
Fix some issues with correctness + simplify API a bit
tdoublep May 27, 2024
6af4629
Merge remote-tracking branch 'refs/remotes/origin/main' into mlp_spec…
njhill May 31, 2024
e0309a6
Fix typing and formatting
njhill May 31, 2024
abd42e7
Merge remote-tracking branch 'refs/remotes/origin/main' into mlp_spec…
njhill Jun 1, 2024
314f2ae
Merge remote-tracking branch 'refs/remotes/origin/main' into mlp_spec…
njhill Jun 5, 2024
9dd1c50
Remove separate MLPSpeculatorModelRunner and other cleanup
njhill Jun 5, 2024
0d43097
Use sample_len in mlp_speculator
njhill Jun 5, 2024
9dd1608
Some more rework/simplification, still in progress
njhill Jun 6, 2024
ea677bd
Config cleanup
njhill Jun 7, 2024
b39c94f
Ignore weird mypi error only happening in CI
njhill Jun 7, 2024
ab96c2a
Try again to ignore weird ruff error
njhill Jun 7, 2024
e9af7e5
Try to ignore both ruff and mypy errs
njhill Jun 7, 2024
30dc5e6
yapf
njhill Jun 7, 2024
3a61052
Fix leftover HiddenStatesWorker references
njhill Jun 7, 2024
cc05972
Merge remote-tracking branch 'refs/remotes/origin/main' into mlp_spec…
njhill Jun 7, 2024
693974e
Fix AutoConfig import, mlp spec worker docstring
njhill Jun 7, 2024
f1bafba
Some cleanup/simplification
njhill Jun 7, 2024
455b9a9
Rework handling of accepted tokens
njhill Jun 7, 2024
e583ae9
Filter hidden states in Top1Proposer when needed
njhill Jun 9, 2024
7bff0d1
Enable bonus token
njhill Jun 9, 2024
3d04037
Merge remote-tracking branch 'refs/remotes/origin/main' into mlp_spec…
njhill Jun 9, 2024
bea97d7
Merge remote-tracking branch 'refs/remotes/origin/main' into mlp_spec…
njhill Jun 11, 2024
3012553
Move hidden state logic to separate class
njhill Jun 11, 2024
b116e02
Default num_speculative_tokens based on speculator model config
njhill Jun 15, 2024
e7742e7
Move offline_inference example to separate file
njhill Jun 15, 2024
ee83331
Merge remote-tracking branch 'refs/remotes/origin/main' into mlp_spec…
njhill Jun 15, 2024
444a709
ruff
njhill Jun 15, 2024
bb9fd32
Add comment per review
njhill Jun 15, 2024
fcc6606
Some simplification to MLPSpeculatorWorker._prepare_input_tensors
njhill Jun 15, 2024
ffc0bcf
Merge remote-tracking branch 'refs/remotes/origin/main' into mlp_spec…
njhill Jun 17, 2024
f3dc40a
Add check for TP == 1; TP support will be a fast-follow
njhill Jun 17, 2024
1b7e305
Fix test import
njhill Jun 17, 2024
46ceacd
Revert unrelated commit made by mistake
njhill Jun 17, 2024
d9ce339
Fix test mocks
njhill Jun 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move offline_inference example to separate file
  • Loading branch information
njhill committed Jun 15, 2024
commit e7742e75953702f9f302c3da714ec93fa03fc831
17 changes: 1 addition & 16 deletions examples/offline_inference.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
import time

from vllm import LLM, SamplingParams

template = ("Below is an instruction that describes a task. Write a response "
"that appropriately completes the request.\n\n### Instruction:\n{}"
"\n\n### Response:")

# Sample prompts.
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
prompts = [template.format(prompt) for prompt in prompts]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

# Create an LLM.
llm = LLM(model="ibm-granite/granite-7b-instruct",
use_v2_block_manager=True,
enforce_eager=True,
speculative_model="ibm-granite/granite-7b-instruct-accelerator",
num_speculative_tokens=5)
llm = LLM(model="facebook/opt-125m")
# Generate texts from the prompts. The output is a list of RequestOutput objects
# that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params)
start = time.time()
outputs = llm.generate(prompts, sampling_params)
end = time.time()
print((end - start) / sum([len(o.outputs[0].token_ids) for o in outputs]))
# Print the outputs.
for output in outputs:
prompt = output.prompt
60 changes: 60 additions & 0 deletions examples/offline_inference_mlpspeculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import gc
import time
from typing import List

from vllm import LLM, SamplingParams


def time_generation(llm: LLM, prompts: List[str], sampling_params: SamplingParams):
# Generate texts from the prompts. The output is a list of RequestOutput
# objects that contain the prompt, generated text, and other information.
# Warmup first
llm.generate(prompts, sampling_params)
llm.generate(prompts, sampling_params)
start = time.time()
outputs = llm.generate(prompts, sampling_params)
end = time.time()
print((end - start) / sum([len(o.outputs[0].token_ids) for o in outputs]))
# Print the outputs.
for output in outputs:
generated_text = output.outputs[0].text
print(f"text: {generated_text!r}")


if __name__ == "__main__":

template = (
"Below is an instruction that describes a task. Write a response "
"that appropriately completes the request.\n\n### Instruction:\n{}"
"\n\n### Response:\n")

# Sample prompts.
prompts = [
"Write about the president of the United States.",
]
prompts = [template.format(prompt) for prompt in prompts]
# Create a sampling params object.
sampling_params = SamplingParams(temperature=0.0, max_tokens=200)

# Create an LLM without spec decoding
llm = LLM(
model="meta-llama/Llama-2-13b-chat-hf",
)

print("Without speculation")
time_generation(llm, prompts, sampling_params)

del llm
gc.collect()

# Create an LLM with spec decoding
llm = LLM(
model="meta-llama/Llama-2-13b-chat-hf",
speculative_model="ibm-fms/llama-13b-accelerator",
# These are currently required for MLPSpeculator decoding
use_v2_block_manager=True,
enforce_eager=True,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impressive! It seems MLPSpeculator + w/o cudagraph is still much faster than Original + cudagraph.


print("With speculation")
time_generation(llm, prompts, sampling_params)