mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
fix vllm gen cfg & set default to llm-ppl (#658)
* fix vllm gen cfg & set default to llm-ppl * fix code style * reset llm_framework default value * fix pre-commit --------- Co-authored-by: suluyan.sly <suluyan.sly@alibaba-inc.com>
This commit is contained in:
@@ -42,6 +42,24 @@ class Vllm(InferFramework):
|
||||
The string batch or the token list batch to input to the model.
|
||||
kwargs: Sampling parameters.
|
||||
"""
|
||||
|
||||
# convert hf generate config to vllm
|
||||
do_sample = kwargs.pop('do_sample', None)
|
||||
num_beam = kwargs.pop('num_beam', 1)
|
||||
max_length = kwargs.pop('max_length', None)
|
||||
max_new_tokens = kwargs.pop('max_new_tokens', None)
|
||||
|
||||
# for vllm, default to do_sample/greedy(depends on temperature).
|
||||
# for hf, do_sample=false, num_beam=1 -> greedy(default)
|
||||
# do_sample=ture, num_beam=1 -> sample
|
||||
# do_sample=false, num_beam>1 -> beam_search
|
||||
if not do_sample and num_beam > 1:
|
||||
kwargs['use_beam_search'] = True
|
||||
if max_length:
|
||||
kwargs['max_tokens'] = max_length - len(prompts[0])
|
||||
if max_new_tokens:
|
||||
kwargs['max_tokens'] = max_new_tokens
|
||||
|
||||
from vllm import SamplingParams
|
||||
sampling_params = SamplingParams(**kwargs)
|
||||
if isinstance(prompts[0], str):
|
||||
|
||||
@@ -104,12 +104,20 @@ class LLMPipeline(Pipeline):
|
||||
|
||||
if isinstance(model, str) and is_official_hub_path(model):
|
||||
logger.info(f'initiate model from location {model}.')
|
||||
if self.llm_framework is not None:
|
||||
if self.llm_framework:
|
||||
model_dir = model if os.path.exists(
|
||||
model) else snapshot_download(model)
|
||||
return self._wrap_infer_framework(model_dir,
|
||||
self.llm_framework)
|
||||
elif is_model(model):
|
||||
try:
|
||||
model = self._wrap_infer_framework(model_dir,
|
||||
self.llm_framework)
|
||||
logger.info(f'initiate model with {framework}.')
|
||||
return model
|
||||
except Exception as e:
|
||||
self.llm_framework = None
|
||||
logger.warning(
|
||||
f'Cannot using llm_framework with {model}, '
|
||||
f'ignoring llm_framework={self.llm_framework} : {e}')
|
||||
if is_model(model):
|
||||
return Model.from_pretrained(
|
||||
model,
|
||||
invoked_by=Invoke.PIPELINE,
|
||||
|
||||
Reference in New Issue
Block a user