-
Notifications
You must be signed in to change notification settings - Fork 50
Adding vllm speculative decoding example #317
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
Open
htrivedi99
wants to merge
2
commits into
main
Choose a base branch
from
het/vllm-spec-dec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This base image is required for developer build of vLLM | ||
base_image: | ||
image: nvcr.io/nvidia/pytorch:23.11-py3 | ||
python_executable_path: /usr/bin/python3 | ||
build_commands: [] | ||
environment_variables: | ||
HF_TOKEN: "" | ||
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. why here over secrets? 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. vLLM reads only this specific environment variable for the access token. It doesn't work with secrets |
||
external_package_dirs: [] | ||
model_metadata: | ||
main_model: meta-llama/Meta-Llama-3-8B-Instruct | ||
assistant_model: ibm-fms/llama3-8b-accelerator | ||
tensor_parallel: 1 | ||
max_num_seqs: 16 | ||
model_name: vLLM Speculative Decoding | ||
requirements: | ||
- git+https://github.com/vllm-project/vllm@9def10664e8b54dcc5c6114f2895bc9e712bf182 | ||
resources: | ||
accelerator: A100 | ||
use_gpu: true | ||
system_packages: | ||
- python3.10-venv | ||
runtime: | ||
predict_concurrency: 128 |
Empty file.
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,65 @@ | ||
import logging | ||
import subprocess | ||
import uuid | ||
|
||
from vllm import SamplingParams | ||
from vllm.engine.arg_utils import AsyncEngineArgs | ||
from vllm.engine.async_llm_engine import AsyncLLMEngine | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Model: | ||
def __init__(self, **kwargs): | ||
self._config = kwargs["config"] | ||
self.model = None | ||
self.llm_engine = None | ||
self.model_args = None | ||
|
||
num_gpus = self._config["model_metadata"]["tensor_parallel"] | ||
logger.info(f"num GPUs ray: {num_gpus}") | ||
command = f"ray start --head --num-gpus={num_gpus}" | ||
subprocess.check_output(command, shell=True, text=True) | ||
|
||
def load(self): | ||
model_metadata = self._config["model_metadata"] | ||
logger.info(f"main model: {model_metadata['main_model']}") | ||
logger.info(f"assistant model: {model_metadata['assistant_model']}") | ||
logger.info(f"tensor parallelism: {model_metadata['tensor_parallel']}") | ||
logger.info(f"max num seqs: {model_metadata['max_num_seqs']}") | ||
|
||
self.model_args = AsyncEngineArgs( | ||
model=model_metadata["main_model"], | ||
speculative_model=model_metadata["assistant_model"], | ||
trust_remote_code=True, | ||
tensor_parallel_size=model_metadata["tensor_parallel"], | ||
max_num_seqs=model_metadata["max_num_seqs"], | ||
dtype="half", | ||
use_v2_block_manager=True, | ||
enforce_eager=True, | ||
) | ||
self.llm_engine = AsyncLLMEngine.from_engine_args(self.model_args) | ||
|
||
async def predict(self, model_input): | ||
prompt = model_input.pop("prompt") | ||
stream = model_input.pop("stream", True) | ||
|
||
sampling_params = SamplingParams(**model_input) | ||
idx = str(uuid.uuid4().hex) | ||
vllm_generator = self.llm_engine.generate(prompt, sampling_params, idx) | ||
|
||
async def generator(): | ||
full_text = "" | ||
async for output in vllm_generator: | ||
text = output.outputs[0].text | ||
delta = text[len(full_text) :] | ||
full_text = text | ||
yield delta | ||
|
||
if stream: | ||
return generator() | ||
else: | ||
full_text = "" | ||
async for delta in generator(): | ||
full_text += delta | ||
return {"text": full_text} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just cuious why we need this base image? Can you add a cooment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this base image the build does not succeed. The baseten base image does not have
nvcc
, which is required for the developer build of vLLM.