用colab 跑ollama很简单

电脑,手机,硬件,软件,电子产品等

版主: Jack12345

头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#1 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

要用GPU,得去右上方Change runtime type 那里,把cpu session改成gpu session

1 打开colab,点页面左下的Terminal按钮,右边会打开一个terminal,可以在里面试试看colab给你多少空间,我的/content还有70G剩余,绰绰有余了

代码: 全选

df -h

2 打如下命令,自动安装ollama

代码: 全选

curl https://ollama.ai/install.sh | sh

3 打如下命令,开启ollama 网络服务

代码: 全选

ollama serve & 

4 打如下命令,下载openAI的gpt-oss模型(我试过,又快又好),下载大小13G

代码: 全选

ollama pull gpt-oss

下载deepseek 14b (32b的有19G VRAM不足会很慢)

代码: 全选

ollama pull deepseek-r1

5 安装 python 的ollama 包(这个包目的是跟服务器通信,发送请求,然后打印LLM的输出)

代码: 全选

pip install ollama

6 清空左边的colab notebook,在左边开一个新格子,运行这句话

代码: 全选

import ollama

7 开始对话

gpt-oss:

代码: 全选

response = ollama.generate(model='gpt-oss', prompt='how to use ollama in colab')
print(response['response'])

deepseek-r1

代码: 全选

response = ollama.generate(model='deepseek-r1', prompt='how to use ollama in colab')
print(response['response'])
x1 图片
上次由 huangchong 在 2025年 12月 1日 23:39 修改。
头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#2 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

代码: 全选

response=ollama.chat(model='gpt-oss',messages=[{'role':'user','content':"why few people use colab to run LLM"}])
print(response['message']['content'])

Short answer:
Because the free/low‑cost Google‑Colab environment simply doesn’t meet the hardware, privacy, and operational needs that most people have when they want to run large language models (LLMs).
Below is a detailed rundown of the key reasons and the alternatives that people usually turn to instead.


1. Hardware & Capacity Limits

FactorColab (Free)Colab (Pro/Pro +)Typical LLM Workloads
GPU typeRTX 2080 Ti (12 GB), Tesla K80, T4 (12 GB)P100, P4, P100 (16 GB), T4 (16 GB)Models > 2–3 B params often need ≥ 24 GB
VRAM12 GB (sometimes < 8 GB on the free tier)16–24 GB7‑B models → 32 GB (or sharded)
CPU4–8 cores8–12 coresHeavy pre‑processing, batching
RAM13 GB26 GBLarge token‑sets, tokenizer buffers
Disk100 MB (ephemeral)1 TB (persistent)Storage for checkpoints, logs
Session length12 h (max)24 h (max)Need months of training or continuous inference
GPU quota12 h/day (or less)24 h/dayMany researchers need > 24 h/day

What it means for LLMs

.......(后面太长,删了,)

上面表格里的很多信息似乎都不对。因为我说很少人用colab跑llm它就顺着我编
例如我应该也是免费用户(应该是,你们可以跟我比比),硬盘总空间似乎100多G,显卡是15G的T4,不是12G的。

上次由 huangchong 在 2025年 12月 1日 21:20 修改。
头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#4 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

这是用colab的T4 GPU(估计相当于2080ti吧),问了问题以后半分钟之内出的答案,虽然是胡扯,但是证明colab跑LLM是没问题的

下面是gpt-oss教我的 若干种通过python和ollama服务器谈话 的方法 之一

代码: 全选

response=ollama.chat(model='gpt-oss',messages=[{'role':'user','content':"why few people use colab to run LLM"}])
print(response['message']['content'])
x1 图片
上次由 huangchong 在 2025年 12月 1日 21:15 修改。
头像
mmking(上水)
论坛元老
论坛元老
帖子互动: 2008
帖子: 14975
注册时间: 2023年 1月 25日 05:10

#5 Re: 用colab 跑ollama很简单

帖子 mmking(上水) »

用colab跑有啥优势?

huangchong 写了: 2025年 12月 1日 21:09

这是用colab的T4 GPU(估计相当于2080ti吧),问了问题以后半分钟之内出的答案,虽然是胡扯,但是证明colab跑LLM是没问题的

硅谷抄手这个ID疑似杀猪盘
viewtopic.php?t=920694

凡所有相,皆是虚妄

viewtopic.php?t=864957

图片

头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#6 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

mmking 写了: 2025年 12月 1日 21:13

用colab跑有啥优势?

不要钱, 给的T4 GPU,显存15.3G,跑很多32b模型都够了

而且理论上只要你有个能打字的电脑就可以随时开一个新session跟local LLM聊天,不用带着个台式机到处跑. 也就是说,你出门在外,想找LLM聊天,随时可以自己开一个

x1 图片
头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#7 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

注意,因为colab每次关闭session之后会把硬盘复原,顶上的安装ollama和下载网络是每次都要做的,虽然5分钟就可以完成,但是为了不每次打这些命令,可以把命令存在google drive里,然后每次从colab里mount google drive,然后跑存在drive里的script

x1 图片
majia
论坛支柱
论坛支柱
帖子互动: 357
帖子: 12771
注册时间: 2022年 7月 23日 23:04

#8 Re: 用colab 跑ollama很简单

帖子 majia »

WARNING: systemd is not running
WARNING: Unable to detect NVIDIA/AMD GPU. Install lspci or lshw to automatically detect and install GPU dependencies.

然后就没有然后了。。。。。。。

MacBook 跑不了?

头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#9 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

majia 写了: 2025年 12月 1日 22:44

WARNING: systemd is not running
WARNING: Unable to detect NVIDIA/AMD GPU. Install lspci or lshw to automatically detect and install GPU dependencies.

然后就没有然后了。。。。。。。

MacBook 跑不了?

哦 忘了说,你得去右上方Connect -- change runtime type 那里,把cpu session改成gpu session

majia
论坛支柱
论坛支柱
帖子互动: 357
帖子: 12771
注册时间: 2022年 7月 23日 23:04

#10 Re: 用colab 跑ollama很简单

帖子 majia »

huangchong 写了: 2025年 12月 1日 22:52

哦 忘了说,你得去右上方Connect -- change runtime type 那里,把cpu session改成gpu session

没看到 Connect

图片

头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#12 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

majia 写了: 2025年 12月 1日 23:04

没看到 Connect

Ram Disk,右边那个朝下的三角里 "Change Runtime type"

majia
论坛支柱
论坛支柱
帖子互动: 357
帖子: 12771
注册时间: 2022年 7月 23日 23:04

#13 Re: 用colab 跑ollama很简单

帖子 majia »

同样结果

WARNING: systemd is not running
WARNING: Unable to detect NVIDIA/AMD GPU. Install lspci or lshw to automatically detect and install GPU dependencies.

Install complete. Run "ollama" from the command line.
/content# ollama serve
Couldn't find '/root/.ollama/id_ed25519'. Generating new private key.

majia
论坛支柱
论坛支柱
帖子互动: 357
帖子: 12771
注册时间: 2022年 7月 23日 23:04

#14 Re: 用colab 跑ollama很简单

帖子 majia »

Colab paid products - Cancel contracts here
You are not subscribed. Learn more
You currently have zero compute units available. Resources offered free of charge are not guaranteed. Purchase more units here.
At your current usage level, this runtime may last up to 4 hours 30 minutes.

dreamcar1
见习作家
见习作家
帖子互动: 34
帖子: 393
注册时间: 2024年 10月 14日 23:14

#15 Re: 用colab 跑ollama很简单

帖子 dreamcar1 »

huangchong 写了: 2025年 12月 1日 21:17

不要钱, 给的T4 GPU,显存15.3G,跑很多32b模型都够了

而且理论上只要你有个能打字的电脑就可以随时开一个新session跟local LLM聊天,不用带着个台式机到处跑. 也就是说,你出门在外,想找LLM聊天,随时可以自己开一个

老大,colab 跑个LLM,有啥具体作用吗?

majia
论坛支柱
论坛支柱
帖子互动: 357
帖子: 12771
注册时间: 2022年 7月 23日 23:04

#16 Re: 用colab 跑ollama很简单

帖子 majia »

dreamcar1 写了: 2025年 12月 1日 23:19

老大,colab 跑个LLM,有啥具体作用吗?

跟电脑聊天?

头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#17 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

majia 写了: 2025年 12月 1日 23:17

Colab paid products - Cancel contracts here
You are not subscribed. Learn more
You currently have zero compute units available. Resources offered free of charge are not guaranteed. Purchase more units here.
At your current usage level, this runtime may last up to 4 hours 30 minutes.

这就奇怪了,看起来你搞不到GPU,但是如果没有免费GPU谁会跑来用colab?你change runtime type是选了T4 GPU吗?

majia
论坛支柱
论坛支柱
帖子互动: 357
帖子: 12771
注册时间: 2022年 7月 23日 23:04

#18 Re: 用colab 跑ollama很简单

帖子 majia »

huangchong 写了: 2025年 12月 1日 23:28

这就奇怪了,看起来你搞不到GPU,但是如果没有免费GPU谁会跑来用colab?你change runtime type是选了T4 GPU吗?

yes

所以是没GPU可用?

头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#19 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

majia 写了: 2025年 12月 1日 23:32

yes

所以是没GPU可用?

可是我试,总是有T4 GPU可以用啊,刚刚又试了一下

majia
论坛支柱
论坛支柱
帖子互动: 357
帖子: 12771
注册时间: 2022年 7月 23日 23:04

#21 Re: 用colab 跑ollama很简单

帖子 majia »

我基本进行到第3步

ollama serve &

就开始出错了

runtime type 是 python 3 么?

上次由 majia 在 2025年 12月 1日 23:50 修改。
头像
huangchong(净坛使者)楼主
论坛元老
论坛元老
2023-24年度优秀版主
帖子互动: 4483
帖子: 64640
注册时间: 2022年 7月 22日 01:22

#22 Re: 用colab 跑ollama很简单

帖子 huangchong(净坛使者)楼主 »

majia 写了: 2025年 12月 1日 23:48

我基本进行到第3步

ollama serve &

就开始出错了

majia 写了: 2025年 12月 1日 23:17

Colab paid products - Cancel contracts here
You are not subscribed. Learn more
You currently have zero compute units available. Resources offered free of charge are not guaranteed. Purchase more units here.
At your current usage level, this runtime may last up to 4 hours 30 minutes.

我的也说一样的话,但是没有顶上这段黄色标出的字。
另外我的/root/.ollama里有id_ed25519 文件,里面是个private key

你打

nvidia-smi

看看有没有这个程序。没有的话就是没有GPU
有的话,下面会出个表,给你列出GPU。

上次由 huangchong 在 2025年 12月 1日 23:57 修改。
majia
论坛支柱
论坛支柱
帖子互动: 357
帖子: 12771
注册时间: 2022年 7月 23日 23:04

#23 Re: 用colab 跑ollama很简单

帖子 majia »

huangchong 写了: 2025年 12月 1日 23:49

我的也说一样的话,但是没有顶上这段黄色标出的字。
另外我的/root/.ollama里有id_ed25519 文件,里面是个private key

你打

nvidia smi

看看有没有这个程序。没有的话就是没有GPU
有的话,下面会出个表,给你列出GPU。

还不是第3步

第2步

代码: 全选

curl https://ollama.ai/install.sh | sh

就开始出错了

打完 nvidia smi

-bash: nvidia: command not found

回复

回到 “电脑手机(IT)”