LM StudioLM Studio

推测解码

在 lmstudio-python 中使用草稿模型进行投机采样的 API

所需 Python SDK 版本1.2.0

投机采样(Speculative decoding)是一种可以在不降低响应质量的前提下,显著提高大型语言模型 (LLM) 生成速度的技术。更多信息请参阅 投机采样

要在 lmstudio-python 中使用投机采样,只需在执行预测时提供 draftModel 参数即可。您无需单独加载草稿模型。

import lmstudio as lms

main_model_key = "qwen2.5-7b-instruct"
draft_model_key = "qwen2.5-0.5b-instruct"

model = lms.llm(main_model_key)
result = model.respond(
    "What are the prime numbers between 0 and 100?",
    config={
        "draftModel": draft_model_key,
    }
)

print(result)
stats = result.stats
print(f"Accepted {stats.accepted_draft_tokens_count}/{stats.predicted_tokens_count} tokens")
© . This site is unofficial and not affiliated with Element Labs, Inc.