APP下载

AI | Ollama: Build the Model - 1

原创

AI

你对一件事的理解,就是你在这件事上的竞争力。—— 张一鸣

择偶观:不是我要找什么样的人,而是我要成为什么样的人。—— 傅行之

需求背景

最近,医疗大语言模型google/medgemma-4b-it 发布了,就想在Ollama上试一试。但是等了一段时间发现官方一直支持,于是决定自己动手构建一个。

基本信息

服务器

  1. 系统信息
               
  • 1
  • 2
  • 3
uname -a # Linux fu 6.8.0-60-generic #63-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 19:04:15 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux COPY
  1. 显卡信息
               
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
nvidia-smi # output Mon Jun 9 05:46:57 2025 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 560.35.05 Driver Version: 560.35.05 CUDA Version: 12.6 | |-----------------------------------------+------------------------+----------------------+ | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |=========================================+========================+======================| | 0 NVIDIA GeForce RTX 3060 Off | 00000000:01:00.0 On | N/A | | 34% 36C P8 16W / 170W | 3812MiB / 12288MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ COPY
  1. ollama: version is 0.9.0

AI工具辅助

1. deepseek - https://chat.deepseek.com/ 

详细步骤

1. 环境准备

小提示:需要科学上网,请自行处理!

1.1 系统配置

               
  • 1
  • 2
sudo apt update && sudo apt upgrade -y sudo apt install -y python3-pip git build-essential cmake clang COPY

1.2 下载 CUDA Toolkit

详细步骤直接参考官网 ,根据自己的操作系统进行配置。

注意:下载时间有点长,需要耐心等待。

1.3 配置Python环境

               
  • 1
  • 2
  • 3
python3 -m venv medgemma-env source medgemma-env/bin/activate pip install --upgrade pip COPY
               
  • 1
COPY

1.4 安装Python依赖

               
  • 1
pip install torch transformers sentencepiece huggingface_hub COPY

1.5 安装Ollama 

               
  • 1
  • 2
curl -fsSL https://ollama.com/install.sh | sh ollama serve & # Keep running in background COPY

说明:到这里为止,如果使用deepseek这样的AI工具,整个流程没什么问题。但是从下面开始AI就出现了各种问题,需要多次调试才能正确。主要问题还是AI知识库不够新,注意:我是开启了联网功能的,但首次生成的内容还是不对。

2. 配置llama.cpp

2.1 克隆llama.cpp - Releases/b5604 

               
  • 1
  • 2
git clone https://github.com/ggerganov/llama.cpp cd llama.cpp COPY

说明:

  • 从这里开始AI就说得不太对了,如:它提示你使用make进行构建,但该方法当前是不支持的,正确地构建可以参考这里 ;
  • 构建过程出现了很多问题,我这里不一一展示了,直接走正确地流程;

2.2 构建llama.cpp

               
  • 1
  • 2
# 在llama.cpp根目录 cmake . -DLLAMA_CUDA=ON -DLLAMA_BUILD_TESTS=ON -DLLAMA_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release -DLLAMA_CURL=OFF COPY

3. 下载模型

               
  • 1
  • 2
  • 3
  • 4
# 登录 huggingface-cli login huggingface-cli download google/medgemma-4b-it --local-dir medgemma-4b-it COPY

说明:

Appendixes

  1. google/medgemma-4b-it - https://hf-mirror.com/google/medgemma-4b-it 
  2. 如何快速下载huggingface模型——全方法总结 - https://zhuanlan.zhihu.com/p/663712983 
  3. Build llama.cpp locally - https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md 
  4. llama.cpp(github: 82k) - https://github.com/ggml-org/llama.cpp/tree/master 
  5. ollama(github: 144k) - https://github.com/ollama/ollama 
  6. CUDA Toolkit 12.9 Update 1 Downloads - https://developer.nvidia.com/cuda-downloads 

评论区

写评论

登录

所以,就随便说点什么吧...

这里什么都没有,快来评论吧...