vllm server 启动的推理框架进行模型调用参数说明

curl -X POST "http://localhost:8000/v1/completions" -H "Content-Type: application/json" --data "{
   
   \"model\":\"defog/sqlcoder-70b-alpha\",\"prompt\":\"\\n### Instructions:\\nConvert the following question into a SQL query using the given PostgreSQL database schema.\\n\\nRules:\\n1. **Only output the SQL query**: Do not include any explanations, descriptions, comments, or additional text.\\n2. **The SQL query must be valid and syntactically correct**: It should directly answer the question using the provided schema.\\n3. **For each column in the SELECT statement, use the \AS\ syntax to include Chinese annotations**: Use the \COMMENT\ provided in the schema as the Chinese alias. For example, if the column is \facility_id\, the output should be \facility_id AS '设施ID'\.\\n4. **Ensure that each selected column has a corresponding Chinese alias**: Do not omit any alias.\\n5. **Return only the columns relevant to the question**: Exclude any columns that are not directly requested.\\n\\n### Question:\\n设���ID等于123的设备列表\\n\\n### Schema:\\nCREATE TABLE government_maintenance (facility_id VARCHAR(255) COMMENT '设施ID', type VARCHAR(255) COMME
### 本地部署Vllm模型及其API接口调用 #### 创建Python脚本初始化vLLM服务 为了启动vLLM服务,在Python脚本中需导入必要的库来加载预训练的语言模型和对应的分词器。对于GPT-2这样的模型而言,可以利用`transformers`库完成这一操作。 ```python from transformers import GPT2LMHeadModel, GPT2Tokenizer model_name = 'gpt2' tokenizer = GPT2Tokenizer.from_pretrained(model_name) model = GPT2LMHeadModel.from_pretrained(model_name) # 设置模型为评估模式 model.eval() # 此处原输入有误,已修正语法错误[^1] ``` 当无法连接至Hugging Face时,可以通过环境变量配置转向使用ModelScope作为替代方案: ```bash export VLLM_USE_MODELSCOPE=True ``` 接着实例化特定的大规模语言模型对象,比如Qwen系列中的某一款型号,并指定参数以优化性能表现[^2]。 ```python import torch from vllm import LLM llm = LLM( model='Qwen/Qwen2.5-1.5B-Instruct', trust_remote_code=True, dtype=torch.float16 ) ``` #### 构建FastAPI应用程序提供RESTful API服务 通过集成FastAPI框架能够快速搭建起支持HTTP请求处理的服务端程序,从而对外暴露基于vLLM的自然语言处理能力。下面是一个简单的例子展示怎样定义路由处理器函数用于接收POST请求并将文本传递给底层的LLM引擎进行预测分析后再返回响应数据。 ```python from fastapi import FastAPI, Request app = FastAPI() @app.post("/predict/") async def predict(request: Request): body = await request.json() input_text = body.get('text', '') inputs = tokenizer(input_text, return_tensors="pt") outputs = model.generate(**inputs) result = tokenizer.decode(outputs[0], skip_special_tokens=True) return {"prediction": result} ``` 此部分代码片段假设读者已经熟悉了如何安装并运行FastAPI项目;实际开发过程中可能还需要考虑更多细节如异常捕获、日志记录等功能模块的设计实现。 #### 使用Docker容器简化部署流程 针对希望进一步降低运维复杂度的情况,官方提供了预先打包好的Docker镜像文件,其中包含了执行上述功能所需的一切依赖项。只需拉取最新版本的映像并通过命令行启动即可立即获得一个完整的在线推理平台。 ```bash docker pull registry.cn-hangzhou.aliyuncs.com/modelscope/vllm:latest docker run -p 8000:8000 --name=vllm-server \ registry.cn-hangzhou.aliyuncs.com/modelscope/vllm:latest \ python -m vllm.entrypoints.openai.api_server ``` 这使得即使是没有深厚Linux服务器管理经验的技术人员也能轻松上手部署工作[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MonkeyKing.sun

对你有帮助的话,可以打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值