惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
U
Unit 42
MyScale Blog
MyScale Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
量子位
IT之家
IT之家
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Recent Announcements
Recent Announcements
V
Visual Studio Blog
G
Google Developers Blog
Last Week in AI
Last Week in AI
雷峰网
雷峰网
博客园 - 聂微东
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
博客园 - 司徒正美
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏

博客园 - bregman

codexapp不能显示数学公式问题 统计用户使用目录 intel mac 安装 最新版torch node安装 使用Codex问题 测评数据集和大模型报告 litellm 使用介绍 容器中pytorch的cpu速度很慢,原因找到了 KL 散度 podman 替代docker 【代码片段】key-value格式解析 安装 flash-attention windows通过ssh去连接Linux服务器 大模型课件 CSE 234: Data Systems for Machine Learning 大模型训练ultrascale-playbook bash脚本片段 mac 下镜像使用 使用大模型 语言模型资料 使用Python内置的 pdb 模块 debug 快手MARM 文章理解 【脚本片段】cat中防止变量替换
调用本地大模型
bregman · 2025-02-05 · via 博客园 - bregman

  • 利用modelscope下载模型,避免无法连接
modelscope download --model unsloth/DeepSeek-R1-Distill-Qwen-32B-GGUF DeepSeek-R1-Distill-Qwen-32B-Q4_K_M.gguf --local_dir ./DeepSeek-R1-Distill-Qwen-32B-GGUF
modelscope download --model unsloth/DeepSeek-R1-Distill-Qwen-32B-GGUF DeepSeek-R1-Distill-Qwen-32B-Q6_K.gguf --local_dir ./DeepSeek-R1-Distill-Qwen-32B-GGUF
  • bash 直接调用

prompt='<|User|>'$(cat query.txt)'<|Assistant|>You are a helpful medical assistant.'
echo $prompt

LD_LIBRARY_PATH=/home/student/deepseek/build/bin \
/home/student/deepseek/build/bin/llama-cli \
--model /home/student/deepseek/DeepSeek-R1-Distill-Qwen-32B-GGUF/DeepSeek-R1-Distill-Qwen-32B-Q4_K_M.gguf \
--cache-type-k q8_0 \
--threads 16 \
--prompt "$prompt" \
--n-gpu-layers 20 \
 -no-cnv
  • python 调用,还是基于bash命令
import logging


def run_command(command, logger=None):
    '''
    使用 subprocess 模组执行shell 命令。
    打印 subprocess 返回日志信息
    '''
    import subprocess
    logger = logger or logging
    logger.info(command)
    result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    if result.returncode == 0:
        return result.stdout
    else:
        print(f'{result.returncode}, {result.stderr}')
        return None


def predict(query='what is 1 + 1?'):
    cmd = f'''\
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8 \ 
LD_LIBRARY_PATH=/home/student/deepseek/build/bin \
/home/student/deepseek/build/bin/llama-cli \
--model /home/student/deepseek/DeepSeek-R1-Distill-Qwen-32B-GGUF/DeepSeek-R1-Distill-Qwen-32B-Q4_K_M.gguf \
--cache-type-k q8_0 \
--threads 16 \
--prompt '<|User|>{query}<|Assistant|>You are a helpful medical assistant.' \
--n-gpu-layers 20 \
 -no-cnv '''
    ret = run_command(cmd)
    if ret:
        print(ret)
        return ret
    else:
        #print(query)
        return None


if __name__ == '__main__':
    with open('query.txt', 'r') as fp:
        query = fp.read()
        predict(query)