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

在这里插入图片描述


关于 xinference

Xorbits Inference(Xinference)是一个性能强大且功能全面的分布式推理框架。
可用于大语言模型(LLM),语音识别模型,多模态模型等各种模型的推理。
通过 Xorbits Inference,你可以轻松地一键部署你自己的模型或内置的前沿开源模型。
无论你是研究者,开发者,或是数据科学家,都可以通过 Xorbits Inference 与最前沿的 AI 模型,发掘更多可能。


使用

1、启动 xinference

xinference-local -H 0.0.0.0 -p 8094

设置其他参数

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

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

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}
)

得到:

{
	'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 调用:

 python -c "import torch; print(torch.cuda.is_available())"

伊织 2024-03-19(二)

相关推荐

  1. 模型】1. 深度学习框架推理框架概念

    2024-03-20 02:30:02       12 阅读
  2. xinference

    2024-03-20 02:30:02       46 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-20 02:30:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-20 02:30:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-20 02:30:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-20 02:30:02       18 阅读

热门阅读

  1. 抽象类abstract

    2024-03-20 02:30:02       20 阅读
  2. 安达发|APS高级计划与排产软件在家具业的新趋势

    2024-03-20 02:30:02       22 阅读
  3. 02 Statement和PreparedStatement

    2024-03-20 02:30:02       20 阅读
  4. SpringBoot项目串口通讯之jSerialComm

    2024-03-20 02:30:02       22 阅读
  5. 代码随想录算法训练营|一刷总结与反思

    2024-03-20 02:30:02       25 阅读
  6. 73_Pandas获取分位数/百分位数

    2024-03-20 02:30:02       19 阅读
  7. Flutter如何正确使用图片资源

    2024-03-20 02:30:02       18 阅读
  8. UDP协议

    UDP协议

    2024-03-20 02:30:02      20 阅读
  9. 程序员排查BUG指南

    2024-03-20 02:30:02       20 阅读
  10. 开发遇到的bug:设置好的请求头不起作用

    2024-03-20 02:30:02       20 阅读