xinference - 大模型分布式推理框架

文章目录


关于 xinference

Xorbits Inference(Xinference)是一个性能强大且功能全面的分布式推理框架。

可用于大语言模型(LLM),语音识别模型,多模态模型等各种模型的推理。

通过 Xorbits Inference,你可以轻松地一键部署你自己的模型或内置的前沿开源模型。

无论你是研究者,开发者,或是数据科学家,都可以通过 Xorbits Inference 与最前沿的 AI 模型,发掘更多可能。


使用

1、启动 xinference

shell 复制代码
xinference-local -H 0.0.0.0 -p 8094

设置其他参数

Xinference 也允许从其他模型托管平台下载模型。可以通过在拉起 Xinference 时指定环境变量,比如,如果想要从 ModelScope 中下载模型,可以使用如下命令:

shell 复制代码
XINFERENCE_MODEL_SRC=modelscope xinference-local --host 0.0.0.0 --port  8094  

xinference 缓存地址:~/.xinference/cache

模型缓存地址,我使用 modelscope 下载模型,被缓存到 ~/.cache/modelscope/hub/qwen/Qwen-7B-Chat


2、加载模型

搜索,点击 chat model 设置参数,然后点击 飞机 来加载模型



如果你的第1个cuda 被占用,又设置 N-GPU 为 auto,可能会报如下错误

Server error: 400 - [address=0.0.0.0:46785, pid=12000] Some modules are dispatched on the CPU or the disk. Make sure you have enough GPU RAM to fit the quantized model. If you want to dispatch the model on the CPU or the disk while keeping these modules in 32-bit, you need to set load_in_8bit_fp32_cpu_offload=True and pass a custom device_map to from_pretrained. Check https://huggingface.co/docs/transformers/main/en/main_classes/quantization#offload-between-cpu-and-gpu for more details.

将 N-GPU 设置为 可用的cuda 就好



可以在 Running Models 中看到刚调起来的模型


3、模型交互

没有交互的 UI 界面,你可以使用代码进行交互

以下代码来自:https://inference.readthedocs.io/zh-cn/latest/index.html

python 复制代码
client = Client("http://localhost:8094")
model = client.get_model("qwen-chat") # 填入上面的 model id
# <xinference.client.restful.restful_client.RESTfulChatModelHandle object at 0x7f203fb8e050>


# Chat to LLM
model.chat(
   prompt="What is the largest animal?",
   system_prompt="You are a helpful assistant",
   generate_config={"max_tokens": 1024}
)

得到:

json 复制代码
{
	'id': 'chat744c3bf4-e5e3-11ee-8014-ac1f6b206f62',
	'object': 'chat.completion',
	'created': 1710847556,
	'model': 'qwen-chat',
	'choices': [{
		'index': 0,
		'message': {
			'role': 'assistant',
			'content': 'The largest animal on Earth is the blue whale, which can grow up to 100 feet (30 meters) in length and weigh as much as 200 tons (90 metric tonnes). It has the biggest brain of any living creature, with an estimated volume of around 70 cubic feet (26 liters). The blue whale also has one of the strongest voices in the world, capable of producing a loud noise that can be heard over 5 miles (8 kilometers) away.'
		},
		'finish_reason': 'stop'
	}],
	'usage': {
		'prompt_tokens': 24,
		'completion_tokens': 103,
		'total_tokens': 127
	}
}

其它

报错处理 - transformer.wte.weight

KeyError: [address=0.0.0.0:41435, pid=40327] 'transformer.wte.weight'

如果出现这个错误,可以检查下 cuda 是否能正常被 torch 调用:

shell 复制代码
 python -c "import torch; print(torch.cuda.is_available())"

伊织 2024-03-19(二)

相关推荐
徐先生 @_@|||16 分钟前
数据分析体系全览导图综述
大数据·hadoop·分布式·数据分析
xixixi777771 小时前
解析 Claude模型 —— Anthropic公司打造,以安全性和推理能力为核心竞争力的顶尖大语言模型
人工智能·ai·语言模型·自然语言处理·大模型·claude·主流模型
虹科网络安全1 小时前
艾体宝洞察 | 缓存策略深度解析:从内存缓存到 Redis 分布式缓存
redis·分布式·缓存
喜欢吃豆3 小时前
从「文件URL」到「模型可理解内容」:一套完整的文件上传与解析处理流程详解(含PDF/Excel/图片)
pdf·大模型·excel
wangmengxxw3 小时前
SpringAi-memory
人工智能·大模型·memory·springai
人工智能培训3 小时前
企业如何安全、私密地部署大模型?
人工智能·深度学习·安全·大模型·知识图谱·强化学习·大模型工程师
千桐科技4 小时前
qKnow 知识平台核心能力解析|第 02 期:非结构化抽取能力全景
大模型·知识图谱·三元组·知识抽取·qknow·知识平台·非结构化抽取
YE1234567_4 小时前
从底层零拷贝到分布式架构:深度剖析现代 C++ 构建超大规模高性能 AI 插件引擎的实战之道
c++·分布式·架构
笃行客从不躺平4 小时前
Seata + AT 模式 复习记录
java·分布式
世优科技虚拟人5 小时前
智慧文旅体验新引擎:世优科技“数字人+”战略全场景落地实践
人工智能·科技·大模型·数字人·智慧展厅