【LocalAI】(9):本地使用CPU运行LocalAI,一次运行4个大模型,embedding模型,qwen-1.5-05b模型,生成图模型,语音转文字模型

本文介绍了LocalAI项目,一个与OpenAIAPI兼容的本地推理服务,支持多种模型在CPU和GPU硬件上运行。详细讲解了使用Docker启动本地镜像、测试接口以及模型替换的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,关于LocalIA项目

LocalAI 是一个用于本地推理的,与 OpenAI API 规范兼容的 REST API。
它允许您在本地使用消费级硬件运行 LLM(不仅如此),支持与 ggml 格式兼容的多个模型系列。支持CPU硬件/GPU硬件。

项目地址:
https://localai.io/

视频地址:

【LocalAI】(9):本地使用CPU运行LocalAI,一次运行4个大模型,embedding模型,qwen-1.5-05b模型,生成图模型,语音转文字模型

在这里插入图片描述

在这里插入图片描述

2,启动方法项目地址

https://gitee.com/fly-llm/localai-run-llm/blob/master/DockerREADME.md

AIO CPU 镜像是:

Use this image with CPU-only.
Please keep using only C++ backends so the base image is as small as possible (without CUDA, cuDNN, python, etc).

3,使用docker 启动本地镜像


git clone https://gitee.com/fly-llm/localai-run-llm.git

# 开启日志:
docker run -p 8080:8080 -e DEBUG=true --name local-ai -it \
-v `pwd`/aio:/aio -v `pwd`/models:/build/models localai/localai:latest-aio-cpu

4,第1个模型embedding,测试接口


curl -X 'POST' http://0.0.0.0:8080/v1/embeddings \
 -H "Content-Type: application/json" \
 -d '{
  "input": "测试ebmeddings",
  "model": "text-embedding-ada-002"
}'

5,第2个模型LLM测试接口


curl -X 'POST' 'http://0.0.0.0:8080/v1/chat/completions' \
-H 'Content-Type: application/json' -d '{
    "model": "qwen-1.5-0.5b-chat",
    "messages": [
        {
            "role": "user",
            "content": "北京景点?"
        }
    ],
    "temperature": 1
}'

6,第3个模型stablediffusion,测试接口


## 生成图片 Model name: stablediffusion                                                 

curl http://localhost:8080/v1/images/generations -H "Content-Type: application/json" -d '{
  "prompt": "floating hair, portrait, ((loli)), ((one girl)), cute face, hidden hands, asymmetrical bangs, beautiful detailed eyes, eye shadow, hair ornament, ribbons, bowties, buttons, pleated skirt, (((masterpiece))), ((best quality)), colorful|((part of the head)), ((((mutated hands and fingers)))), deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, extra limb, ugly, poorly drawn hands, missing limb, blurry, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, Octane renderer, lowres, bad anatomy, bad hands, text",
  "size": "256x256"
}'


7,第4个模型语音转文字


curl http://localhost:8080/v1/audio/transcriptions -H "Content-Type: multipart/form-data" -F file="@$PWD/voice-test.mp3" -F model="whisper-1"


8,第5个模型tts测试接口,没有调试成功

curl http://localhost:8080/tts -H "Content-Type: application/json" -d '{
    "model":"voice-en-us-amy-low",
    "input": "Hi, this is a test."
}'

9,模型地址aio

替换了镜像里面的aio 文件夹。把模型都使用国内镜像进行下载地址替换了。
使用了modescope 下载地址。

download_files:
- filename: "bge-base-zh-v1.5-ggml-model-q4_0.bin"
  sha256: "da4d976e3988977ec4d9fde6653a8fe954b71a0c502c30eda6f84234556cde54"
  uri: "https://www.modelscope.cn/api/v1/models/flyiot/bge-base-zh-v1.5-ggml/repo?Revision=master&FilePath=ggml-model-q4_0.bin"
### DeepSeek-R1-Distill-1.5B 模型架构和参数详情 DeepSeek-R1-Distill-Qwen-1.5B 是一种基于Transformer架构的语言模型,该模型经过蒸馏处理,在保持性能的同时减少了计算资源的需求。此模型具有约15亿个参数[^1]。 #### 架构特点 - **多层编码器**:采用标准的Transformer编码器堆叠方式构建,每一层都包含了自注意力机制(self-attention mechanism),能够捕捉输入序列中的长期依赖关系。 - **前馈神经网络(FFN)**:每个多头自注意模块后面连接着两个线性变换组成的简单全连接层,即所谓的前馈子层。 - **残差链接与Layer Normalization**:为了缓解深层网络训练困难的问题,引入了跳跃连接(residual connections)以及层归一化(layer normalization),有助于加速收敛并提高泛化能力。 #### 参数配置 - **隐藏单元数(Hidden Size)**:768维向量表示每个位置上的token embedding和其他特征embeddings之和的结果空间维度大小。 - **层数(Layers)**:总共由24个相同的transformer blocks组成。 - **头部数量(Heads)**:在multi-head self attention部分设置了12个独立的工作头来平行工作,从而增强表达力。 - **最大长度(Max Position Embedding Length)**:支持的最大输入文本长度设定为1024 tokens。 - **激活函数(Activation Function)**:使用GELU作为非线性的激活组件。 ```python from transformers import AutoConfig config = AutoConfig.from_pretrained("DeepSeek-R1-Distill-1.5B") print(f"Hidden size: {config.hidden_size}") print(f"Number of layers: {config.num_hidden_layers}") print(f"Attention heads: {config.num_attention_heads}") print(f"Max position embeddings length: {config.max_position_embeddings}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值