# 推理和部署 以下为swift支持的推理引擎以及接入部分的相应能力,三种推理加速引擎为SWIFT的推理、部署、评测模块提供推理加速: | 推理加速引擎 | OpenAI API | 多模态 | 量化模型 | 多LoRA | QLoRA | Batch推理 | 并行技术 | | ------------ | -------------- | ---------- | ------ | -------- | ------ | ----- | ----- | | pytorch | [✅](https://github.com/modelscope/ms-swift/blob/main/examples/deploy/client/llm/chat/openai_client.py) | [✅](https://github.com/modelscope/ms-swift/blob/main/examples/app/mllm.sh) | ✅ | [✅](https://github.com/modelscope/ms-swift/blob/main/examples/infer/demo_lora.py) | ✅ | [✅](https://github.com/modelscope/ms-swift/blob/main/examples/infer/pt/batch_ddp.sh) |DDP/device_map | | [vllm](https://github.com/vllm-project/vllm) | ✅ | [✅](https://github.com/modelscope/ms-swift/blob/main/examples/infer/vllm/mllm_tp.sh) | ✅ | [✅](https://github.com/modelscope/ms-swift/blob/main/examples/deploy/lora/server.sh) | ❌ | ✅ | TP/PP/DP | | [sglang](https://github.com/sgl-project/sglang) | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | TP/PP/DP/EP | | [lmdeploy](https://github.com/InternLM/lmdeploy) | ✅ | [✅](https://github.com/modelscope/ms-swift/blob/main/examples/infer/lmdeploy/mllm_tp.sh) | ✅ | ❌ | ❌ | ✅ | TP/DP | ## 推理 ms-swift使用了分层式的设计思想,用户可以使用命令行界面、Web-UI界面和直接使用Python的方式进行推理。 如果要查看LoRA微调后模型的推理,可以参考[预训练与微调文档](./Pre-training-and-Fine-tuning.md#推理微调后模型)。 ### 使用CLI **全参数模型:** ```shell CUDA_VISIBLE_DEVICES=0 swift infer \ --model Qwen/Qwen2.5-7B-Instruct \ --stream true \ --infer_backend pt \ --max_new_tokens 2048 ``` **LoRA模型:** ```shell CUDA_VISIBLE_DEVICES=0 swift infer \ --model Qwen/Qwen2.5-7B-Instruct \ --adapters swift/test_lora \ --stream true \ --infer_backend pt \ --temperature 0 \ --max_new_tokens 2048 ``` **命令行推理指令** 以上为交互式命令行界面推理,脚本运行后仅需在terminal中输入query即可。你也可以输入以下特殊指令: - `multi-line`: 切换到多行模式,在输入中支持换行输入,以`#`代表输入结束。 - `single-line`: 切换到单行模式,以换行代表输入结束。 - `reset-system`: 重置system并清空历史记录。 - `clear`: 清除历史记录。 - `quit` or `exit`: 退出对话。 **多模态模型** ```shell CUDA_VISIBLE_DEVICES=0 \ MAX_PIXELS=1003520 \ VIDEO_MAX_PIXELS=50176 \ FPS_MAX_FRAMES=12 \ swift infer \ --model Qwen/Qwen2.5-VL-3B-Instruct \ --stream true \ --infer_backend pt \ --max_new_tokens 2048 ``` 如果要进行多模态模型的推理,可以在query中添加`/