【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)
相关推荐
AI大模型12 小时前
GitHub 狂飙 72k Star,这本大模型书凭啥能圈粉无数?
程序员·llm·agent
颜如玉14 小时前
HikariCP:Dead code elimination优化
后端·性能优化·源码
堆栈future15 小时前
秒级生成4K图!字节豆包Seedream 4.0实测:完爆GPT-4o和Nano Banana
llm·aigc
算家计算15 小时前
7B参数拿下30个世界第一!Hunyuan-MT-7B本地部署教程:腾讯混元开源业界首个翻译集成模型
人工智能·开源
FIT2CLOUD飞致云15 小时前
SQLBot开源智能问数系统成功进入GitHub趋势榜主榜,Star数突破2,000个!
开源
大模型教程16 小时前
小白学大模型:从零搭建LLaMA
程序员·llm·llama
AI大模型16 小时前
一篇文章看懂RAG + 实战,看不懂来揍我
程序员·llm·agent
聚客AI17 小时前
🙋‍♀️Transformer训练与推理全流程:从输入处理到输出生成
人工智能·算法·llm
智泊AI21 小时前
Transformer之词嵌入 | 为什么要做词嵌入?
llm
库森学长1 天前
一文带你 "看见" MCP 的过程,彻底理解 MCP 的概念
llm·ai编程·mcp