0


乌班图服务器24.04安装英伟达显卡4090驱动,并使用Ollama安装qwen2.5:32b大模型

一、安装显卡

1、系统要求和准备

# 查看设备信息
ubuntu-drivers devices

运行后会显示ubuntu系统现在能识别到的显卡:

udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
ERROR:root:aplay command not found
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00002684sv00001043sd00008933bc03sc00i00
vendor   : NVIDIA Corporation
model    : AD102 [GeForce RTX 4090]
driver   : nvidia-driver-535 - distro non-free
driver   : nvidia-driver-535-server - distro non-free
driver   : nvidia-driver-550-open - distro non-free
driver   : nvidia-driver-535-server-open - distro non-free
driver   : nvidia-driver-535-open - distro non-free
driver   : nvidia-driver-550 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

然后,你要确保你的系统软件包是最新的,避免出现兼容性问题

# 更新系统和软件包
sudo apt update && sudo apt upgrade -y

2、命令行安装方式

如果使用命令行的方式安装显卡驱动(这是最快捷的方式,也是我推荐的方式),你只需要执行下面的命令。

两种方案,二选一
# 方式1:使用系统工具自动安装
# 使用这个方法会安装带有recommended字段的驱动,即推荐的驱动
ubuntu-drivers devices
sudo ubuntu-drivers autoinstall

# 方式2:
# 或者你想要安装特定版本的驱动,你只需要这样
ubuntu-drivers devices
sudo apt install nvidia-driver-535
# 使用apt命令再加上上面"ubuntu-drivers devices"里列表任意一个驱动

在安装脚本运行完成后你需要重启电脑。

# 重启
sudo reboot

重启完成后使用这条命令查看驱动是否安装成功。

# 查看NVIDIA
nvidia-smi

如果成功输出了显卡信息,代表驱动安装成功了。如下

root@4090:~# nvidia-smi
Thu Sep 19 06:39:10 2024       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.107.02             Driver Version: 550.107.02     CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| 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 4090        Off |   00000000:01:00.0 Off |                  Off |
|  0%   29C    P8             12W /  450W |       2MiB /  24564MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

二、使用Ollama安装qwen2.5:32b模型

官网:https://github.com/ollama/ollama/blob/main/docs/linux.md

1、下载安装包

curl -L https://ollama.com/download/ollama-linux-amd64.tgz -o ollama-linux-amd64.tgz
sudo tar -C /usr -xzf ollama-linux-amd64.tgz

2、将 Ollama 添加为启动服务(推荐)

为 Ollama 创建用户和组:

#创建ollama和用户组,指定家目录且不可登录
sudo useradd -r -s /bin/false -U -m -d /usr/ollama ollama
#把当前用户加入到ollama用户组,获取组的所有权限(让当前用户能进入ollama家目录,读写某些目录和文件的权限)。
sudo usermod -a -G ollama $(whoami)

查看命令:

user@4090:~$ ollama serve -h
Start ollama

Usage:
  ollama serve [flags]

Aliases:
  serve, start

Flags:
  -h, --help   help for serve

Environment Variables:
      OLLAMA_DEBUG               Show additional debug information (e.g. OLLAMA_DEBUG=1)
      OLLAMA_HOST                IP Address for the ollama server (default 127.0.0.1:11434)  
      OLLAMA_KEEP_ALIVE          The duration that models stay loaded in memory (default "5m")
      OLLAMA_MAX_LOADED_MODELS   Maximum number of loaded models per GPU
      OLLAMA_MAX_QUEUE           Maximum number of queued requests
      OLLAMA_MODELS              The path to the models directory
      OLLAMA_NUM_PARALLEL        Maximum number of parallel requests
      OLLAMA_NOPRUNE             Do not prune model blobs on startup
      OLLAMA_ORIGINS             A comma separated list of allowed origins
      OLLAMA_SCHED_SPREAD        Always schedule model across all GPUs
      OLLAMA_TMPDIR              Location for temporary files
      OLLAMA_FLASH_ATTENTION     Enabled flash attention
      OLLAMA_LLM_LIBRARY         Set LLM library to bypass autodetection
      OLLAMA_GPU_OVERHEAD        Reserve a portion of VRAM per GPU (bytes)
      OLLAMA_LOAD_TIMEOUT        How long to allow model loads to stall before giving up (default "5m")

3、做成systemd服务

在systemd中创建服务文件 :/etc/systemd/system/ollama.service

[Unit]
Description=Ollama Service
After=network-online.target

[Service]
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=$PATH"
Environment="OLLAMA_HOST=0.0.0.0:11434"#更改监听的IP和端口,默认的只能本机访问
#Environment="OLLAMA_MODELS=/home/user/ollama/ollama_models"#更改模型的存储路径,默认在用户的家目录的.ollama/models下

[Install]
WantedBy=default.target

然后启动服务:

sudo systemctl daemon-reload
sudo systemctl enable ollama
sudo systemctl  status ollama

4、安装qwen2.5:32b模型

ollama run qwen2.5:32b

这个模型20G,安装时会有点慢

下载完记得查看一下模型的路径对了没

user@4090:/home/ollama$ du -sh  /home/ollama/.ollama/models/
19G    /home/ollama/.ollama/models
标签: linux 机器学习

本文转载自: https://blog.csdn.net/m0_60171711/article/details/142359745
版权归原作者 m0_60171711 所有, 如有侵权,请联系我们删除。

“乌班图服务器24.04安装英伟达显卡4090驱动,并使用Ollama安装qwen2.5:32b大模型”的评论:

还没有评论