-
Notifications
You must be signed in to change notification settings - Fork 276
added vllm lora support. #611
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
haizhou-shi
wants to merge
2
commits into
huggingface:main
Choose a base branch
from
haizhou-shi:main
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 |
---|---|---|
|
@@ -55,6 +55,7 @@ | |
from vllm import LLM, SamplingParams | ||
from vllm.distributed.parallel_state import destroy_distributed_environment, destroy_model_parallel | ||
from vllm.transformers_utils.tokenizer import get_tokenizer | ||
from vllm.lora.request import LoRARequest | ||
|
||
logging.getLogger("vllm").propagate = True | ||
logging.getLogger("vllm").handlers.clear() | ||
|
@@ -93,6 +94,7 @@ class VLLMModelConfig: | |
) | ||
pairwise_tokenization: bool = False # whether to tokenize the context and continuation separately or together. | ||
generation_parameters: GenerationParameters = None # sampling parameters to use for generation | ||
lora_path: str | None = None # path to the LoRA modules | ||
max_num_seqs: int = 128 # maximum number of sequences per iteration; This variable and `max_num_batched_tokens` effectively control the batch size at prefill stage. See https://github.com/vllm-project/vllm/issues/2492 for detailed explaination. | ||
max_num_batched_tokens: int = 2048 # maximum number of tokens per batch | ||
|
||
|
@@ -132,6 +134,12 @@ def __init__( | |
|
||
self.model_info = ModelInfo(model_name=self.model_name, model_sha=self.model_sha) | ||
self.pairwise_tokenization = config.pairwise_tokenization | ||
|
||
# enable LoRA if lora_path is provided | ||
if config.lora_path is not None: | ||
self.lora_request = LoRARequest("default", 1, config.lora_path) | ||
else: | ||
self.lora_request = None | ||
|
||
@property | ||
def tokenizer(self): | ||
|
@@ -183,6 +191,8 @@ def _create_auto_model(self, config: VLLMModelConfig, env_config: EnvConfig) -> | |
"max_model_len": self._max_length, | ||
"swap_space": 4, | ||
"seed": int(config.seed), | ||
"enable_lora": config.lora_path is not None, | ||
"seed": int(config.seed), | ||
"max_num_seqs": int(config.max_num_seqs), | ||
"max_num_batched_tokens": int(config.max_num_batched_tokens), | ||
} | ||
|
@@ -342,10 +352,14 @@ def _generate( | |
# but then tensor_parallel breaks | ||
# Hynek: With the newest vllm, it actually breaks when tensor_parallel_size == 1 and num_gpus not set, | ||
# as VLLM complains about no GPUs available. | ||
# Haizhou: didn't test lora with data_parallel_size > 1 | ||
@ray.remote(num_gpus=1 if self.tensor_parallel_size == 1 else None) | ||
def run_inference_one_model(model_args: dict, sampling_params: SamplingParams, requests): | ||
llm = LLM(**model_args) | ||
return llm.generate(prompt_token_ids=requests, sampling_params=sampling_params) | ||
if self.lora_request is not None: | ||
return llm.generate(prompt_token_ids=requests, sampling_params=sampling_params, lora_request=self.lora_request) | ||
else: | ||
return llm.generate(prompt_token_ids=requests, sampling_params=sampling_params) | ||
|
||
# dispatch requests to all self.data_parallel_size workers, in interleaved fashion | ||
# interleaved important to balance context lengths across workers | ||
|
@@ -362,11 +376,19 @@ def run_inference_one_model(model_args: dict, sampling_params: SamplingParams, r | |
if x is not None | ||
] | ||
else: | ||
outputs = self.model.generate( | ||
prompt_token_ids=inputs, | ||
sampling_params=sampling_params, | ||
use_tqdm=True, | ||
) | ||
if self.lora_request is not None: | ||
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. same as above |
||
outputs = self.model.generate( | ||
prompt_token_ids=inputs, | ||
sampling_params=sampling_params, | ||
lora_request=self.lora_request, | ||
use_tqdm=True, | ||
) | ||
else: | ||
outputs = self.model.generate( | ||
prompt_token_ids=inputs, | ||
sampling_params=sampling_params, | ||
use_tqdm=True, | ||
) | ||
|
||
return outputs | ||
|
||
|
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.
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.
does passing
lora_request=None
results in a failure ? If not, we do not need theif
statement