DeepSparse
本页面介绍如何在LangChain中使用DeepSparse推理运行时。 内容分为两部分:安装和设置,以及DeepSparse使用示例。
安装和设置
- 使用
pip install deepsparse
安装Python包 - 选择一个SparseZoo模型或将支持的模型导出为ONNX格式使用Optimum
存在一个DeepSparse LLM包装器,提供所有模型的统一接口:
<!--IMPORTS:[{"imported": "DeepSparse", "source": "langchain_community.llms", "docs": "https://python.langchain.com/api_reference/community/llms/langchain_community.llms.deepsparse.DeepSparse.html", "title": "DeepSparse"}]-->
from langchain_community.llms import DeepSparse
llm = DeepSparse(
model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base-none"
)
print(llm.invoke("def fib():"))
可以使用 config
参数传递附加参数:
config = {"max_generated_tokens": 256}
llm = DeepSparse(
model="zoo:nlg/text_generation/codegen_mono-350m/pytorch/huggingface/bigpython_bigquery_thepile/base-none",
config=config,
)