Args: model (str): The path to the model. It could be one of the following options: - i) A local directory path of a turbomind model which is converted by `lmdeploy convert` command or download from ii) and
(
model,
prompt,
system_prompt=None,
history_messages=[],
chat_template=None,
model_format="hf",
quant_policy=0,
**kwargs,
)
| 354 | |
| 355 | |
| 356 | async def lmdeploy_model_if_cache( |
| 357 | model, |
| 358 | prompt, |
| 359 | system_prompt=None, |
| 360 | history_messages=[], |
| 361 | chat_template=None, |
| 362 | model_format="hf", |
| 363 | quant_policy=0, |
| 364 | **kwargs, |
| 365 | ) -> str: |
| 366 | """ |
| 367 | Args: |
| 368 | model (str): The path to the model. |
| 369 | It could be one of the following options: |
| 370 | - i) A local directory path of a turbomind model which is |
| 371 | converted by `lmdeploy convert` command or download |
| 372 | from ii) and iii). |
| 373 | - ii) The model_id of a lmdeploy-quantized model hosted |
| 374 | inside a model repo on huggingface.co, such as |
| 375 | "InternLM/internlm-chat-20b-4bit", |
| 376 | "lmdeploy/llama2-chat-70b-4bit", etc. |
| 377 | - iii) The model_id of a model hosted inside a model repo |
| 378 | on huggingface.co, such as "internlm/internlm-chat-7b", |
| 379 | "Qwen/Qwen-7B-Chat ", "baichuan-inc/Baichuan2-7B-Chat" |
| 380 | and so on. |
| 381 | chat_template (str): needed when model is a pytorch model on |
| 382 | huggingface.co, such as "internlm-chat-7b", |
| 383 | "Qwen-7B-Chat ", "Baichuan2-7B-Chat" and so on, |
| 384 | and when the model name of local path did not match the original model name in HF. |
| 385 | tp (int): tensor parallel |
| 386 | prompt (Union[str, List[str]]): input texts to be completed. |
| 387 | do_preprocess (bool): whether pre-process the messages. Default to |
| 388 | True, which means chat_template will be applied. |
| 389 | skip_special_tokens (bool): Whether or not to remove special tokens |
| 390 | in the decoding. Default to be True. |
| 391 | do_sample (bool): Whether or not to use sampling, use greedy decoding otherwise. |
| 392 | Default to be False, which means greedy decoding will be applied. |
| 393 | """ |
| 394 | try: |
| 395 | import lmdeploy |
| 396 | from lmdeploy import version_info, GenerationConfig |
| 397 | except Exception: |
| 398 | raise ImportError("Please install lmdeploy before intialize lmdeploy backend.") |
| 399 | |
| 400 | kwargs.pop("response_format", None) |
| 401 | max_new_tokens = kwargs.pop("max_tokens", 512) |
| 402 | tp = kwargs.pop("tp", 1) |
| 403 | skip_special_tokens = kwargs.pop("skip_special_tokens", True) |
| 404 | do_preprocess = kwargs.pop("do_preprocess", True) |
| 405 | do_sample = kwargs.pop("do_sample", False) |
| 406 | gen_params = kwargs |
| 407 | |
| 408 | version = version_info |
| 409 | if do_sample is not None and version < (0, 6, 0): |
| 410 | raise RuntimeError( |
| 411 | "`do_sample` parameter is not supported by lmdeploy until " |
| 412 | f"v0.6.0, but currently using lmdeloy {lmdeploy.__version__}" |
| 413 | ) |
no test coverage detected