【vLLM 学习】Mlpspeculator

vLLM 是一款专为大语言模型推理加速而设计的框架,实现了 KV 缓存内存几乎零浪费,解决了内存管理瓶颈问题。

更多 vLLM 中文文档及教程可访问 →vllm.hyper.ai/

*在线运行 vLLM 入门教程:零基础分步指南

源码 examples/offline_inference/mlpspeculator.py

ini 复制代码
# SPDX-License-Identifier: Apache-2.0

import gc
import time

from vllm import LLM, SamplingParams


def time_generation(llm: LLM, prompts: list[str],
                    sampling_params: SamplingParams):
    # 从提示中生成文本。输出是 RequestOutput 的包含提示,生成文本和其他信息的对象列表。
    # 首先预热
    llm.generate(prompts, sampling_params)
    llm.generate(prompts, sampling_params)
    start = time.time()
    outputs = llm.generate(prompts, sampling_params)
    end = time.time()
    print((end - start) / sum([len(o.outputs[0].token_ids) for o in outputs]))
    # 打印输出。
    for output in outputs:
        generated_text = output.outputs[0].text
        print(f"text: {generated_text!r}")


if __name__ == "__main__":

    template = (
        "Below is an instruction that describes a task. Write a response "
        "that appropriately completes the request.\n\n### Instruction:\n{}"
        "\n\n### Response:\n")

    # 样本提示。
    prompts = [
        "Write about the president of the United States.",
    ]
    prompts = [template.format(prompt) for prompt in prompts]
    # 创建一个采样参数对象。
    sampling_params = SamplingParams(temperature=0.0, max_tokens=200)

    # 创建一个不使用规格解码的 LLM
    llm = LLM(model="meta-llama/Llama-2-13b-chat-hf")

    print("Without speculation")
    time_generation(llm, prompts, sampling_params)

    del llm
    gc.collect()

    # 与规格解码创建一个 LLM
    llm = LLM(
        model="meta-llama/Llama-2-13b-chat-hf",
        speculative_config={
            "model": "ibm-ai-platform/llama-13b-accelerator",
        },
    )

    print("With speculation")
    time_generation(llm, prompts, sampling_params)
相关推荐
zhengfei6111 小时前
人工智能驱动的暗网开源情报工具
人工智能·开源
说私域2 小时前
开源链动2+1模式商城小程序在深度分销数字化转型中的应用研究
人工智能·小程序·开源·流量运营·私域运营
万岳软件开发小城2 小时前
在线问诊系统源码实战:视频/图文问诊平台搭建步骤全解析
人工智能·开源·源码·在线问诊系统源码·问诊app开发·问诊软件开发·视频问诊小程序
没事儿写两篇2 小时前
Anaconda 的开源替代软件 Miniforge
开源·conda·miniconda·miniforge
山顶夕景2 小时前
【LLM】多模态智能体Kimi-K2.5模型
llm·agent·多模态
冬奇Lab2 小时前
一天一个开源项目(第8篇):UI/UX Pro Max Skill - AI设计智能助手,让AI帮你构建专业UI/UX
ui·开源·ux
向哆哆2 小时前
高校四六级报名系统通知公告模块实战:基于 Flutter × OpenHarmony 跨端开发
flutter·开源·鸿蒙·openharmony·开源鸿蒙
WangYaolove13143 小时前
基于opencv的疲劳检测系(源码+文档)
python·mysql·django·毕业设计·源码
飞乐鸟3 小时前
Github 16.8k Star!推荐一款开源的高性能分布式对象存储系统!
分布式·开源·github
JTnnnnn3 小时前
【架構優化】拒絕 LLM 幻覺:設計基於 Python 路由的 AntV 智慧圖表生成系統
llm·antv·dify