源码编译llama.cpp 、ggml 后端启用自定义BLAS加速

源码编译llama.cpp 、ggml 后端启用自定义BLAS加速

我在llama.cpp 官网上提交了我的解决方案:How to setup OpenBlas on windows? #625

GGML 官网 https://github.com/ggerganov/ggml/issues/959

windows on arm 编译 llama.cpp 、ggml 后端启用自定义BLAS加速

我这以编译 windows on arm 的 llama.cpp 、ggml 为例子,其它情况同样可以

参考我的文章 《源码编译 openblas for windows on arm》 我用了自己编译的这个 openblas

原理 blas 加速是通过编译ggml提供的

所以修改llama.cpp/ggml/src/CMakeLists.txt ,在这一行代码if (GGML_BLAS) 前面添加以下代码:

自定义编译blas:

复制代码
# add custom blas
if (CUSTOM_BLAS)
	set(BLAS_ROOT "C:/workspace/program/openblas")
	set(BLAS_INCLUDE_DIRS
        "${BLAS_ROOT}/include/"
        "${BLAS_ROOT}/include/openblas"
    )
	set(BLAS_LIBRARIES "${BLAS_ROOT}/lib/openblas.lib")
	list(APPEND GGML_CDEF_PUBLIC GGML_USE_BLAS)
	
	set(GGML_HEADERS_BLAS ../include/ggml-blas.h)
	set(GGML_SOURCES_BLAS ggml-blas.cpp)
	
	set(GGML_EXTRA_LIBS     ${GGML_EXTRA_LIBS}     ${BLAS_LIBRARIES})
	set(GGML_EXTRA_INCLUDES ${GGML_EXTRA_INCLUDES} ${BLAS_INCLUDE_DIRS})
endif()

然后编译时指定 CUSTOM_BLAS=ON:

复制代码
cmake -B build -DGGML_BLAS=OFF  -DCUSTOM_BLAS=ON
cmake --build build --config Release

测试

llama.cpp/wmx_test/test_cli.sh :

bash 复制代码
#!/bin/bash

# ./llama-cli --hf-repo hfxing/Qwen2-1.5B-Q4_K_M-GGUF --hf-file qwen2-1.5b-q4_k_m.gguf -p "The meaning to life and the universe is"


cmd=../build/bin/llama-cli

modelpath=/media/wmx/soft1/huggingface_cache/Qwen2-1.5B-Q4_K_M-GGUF/qwen2-1.5b-q4_k_m.gguf
# modelpath=/media/wmx/soft1/huggingface_cache/Qwen1.5-1.8B-Chat/ggml-model-f16.gguf


user_prompt="你是一个AI助手。请问:深圳在哪里?"

$cmd \
-m $modelpath \
-p "$user_prompt" 

llama.cpp/wmx_test/test_llava_cli.sh :

bash 复制代码
#!/bin/bash

cmd=../build/bin/llama-llava-cli

modelpath=/media/wmx/soft1/huggingface_cache/Bunny-v1_0-4B-gguf

user_prompt="A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. \
USER: <image>\n Why is the image funny? \
ASSISTANT:" 

# img_url="https://pic35.photophoto.cn/20150511/0034034892281415_b.jpg"

$cmd -m $modelpath/ggml-model-Q4_K_M.gguf \
--mmproj $modelpath/mmproj-model-f16.gguf \
--image $modelpath/images/example_2.png \
-c 4096 -e \
--temp 0.0 \
# --log-disable \
-p "$user_prompt"

llama.cpp/wmx_test/test_server.sh :

bash 复制代码
#!/bin/bash

# netstat -lnp |grep 8000

# default port=8080 is used by ollama
PORT=8000

cmd=../build/bin/llama-server 

modelpath=/media/wmx/soft1/huggingface_cache/Qwen2-1.5B-Q4_K_M-GGUF/qwen2-1.5b-q4_k_m.gguf

# modelpath=/media/wmx/soft1/huggingface_cache/Qwen1.5-1.8B-Chat/ggml-model-f16.gguf

$cmd \
-m $modelpath \
--port $PORT 

llama.cpp/wmx_test/test_client.sh :

bash 复制代码
import openai

PORT=8000
openai.api_key = "sk-no-key-required"

client = openai.OpenAI(
    base_url=f"http://localhost:{PORT}/v1",
)

completion = client.chat.completions.create(
    model="gpt-3.5-turbo", 
    messages=[
        {"role": "system", "content": "You are an AI assistant. Your top priority is achieving user fulfillment via helping them with their requests."},
        {"role": "user", "content": "深圳在哪里?"}
    ]
)

print(completion.choices[0].message)
相关推荐
菠菠萝宝3 分钟前
【Java手搓RAGFlow】-3- 用户认证与权限管理
java·开发语言·人工智能·llm·openai·qwen·rag
youngfengying1 小时前
《轻量化 Transformers:开启计算机视觉新篇》
人工智能·计算机视觉
搞科研的小刘选手3 小时前
【同济大学主办】第十一届能源资源与环境工程研究进展国际学术会议(ICAESEE 2025)
大数据·人工智能·能源·材质·材料工程·地理信息
MARS_AI_3 小时前
云蝠智能 VoiceAgent 2.0:全栈语音交互能力升级
人工智能·自然语言处理·交互·信息与通信·agi
top_designer4 小时前
Substance 3D Stager:电商“虚拟摄影”工作流
人工智能·3d·设计模式·prompt·技术美术·教育电商·游戏美术
雷神大青椒4 小时前
离别的十字路口: 是否还记得曾经追求的梦想
人工智能·程序人生·职场和发展·玩游戏
m0_650108245 小时前
多模态大模型 VS. 图像视频生成模型浅析
人工智能·技术边界与协同·mllm与生成模型·技术浅谈
ai_xiaogui5 小时前
Mac苹果版Krita AI一键安装教程:AIStarter+ComfyUI零基础部署全流程(X86/ARM双架构)
arm开发·人工智能·macos·comfyui·一键部署·ai绘画教程·kritaai
lapiii3585 小时前
[智能体设计模式] 第11章:目标设定与监控模式
人工智能·设计模式
这张生成的图像能检测吗5 小时前
(论文速读)WFF-Net:用于表面缺陷检测的可训练权重特征融合卷积神经网络
人工智能·深度学习·神经网络·缺陷检测·图像分割