Bailey 的 AI 折腾笔记
中文 · English · Deutsch · 한국어 · 日本語
LLMs2026-12-0111 min readLi

Running Qwen2.5 14B on Colab free graphics card: Ollama installation, Gradio chat page and disconnection and reconnection

ColabOllamaQwen2.5Gradio
Contents

Run Qwen2.5 14B on Colab free graphics card

The goal is simple: run Qwen2.5 14B on the T4 graphics card of the free version of Google Colab without spending any money, and have a chat page that can be opened on mobile phones and computers. Finally, I ran through it. I stepped on a few pitfalls in the middle and recorded them all.

Environment

  • Colab Free Runtime: NVIDIA Tesla T4, 15,360 MiB of VRAM, 12 GB of system memory
  • Model: qwen2.5:14b, Q4_K_M quantized, ~9.0 GB, 14.8B parameters — fits right into a T4
  • Tools: Ollama official installation script + Gradio chat interface

Steps

1. Create a new notebook and switch to GPU

After creating a new Colab notebook, first change the runtime: Code Executor → Change Runtime Type → Select GPU as the hardware accelerator (the free version is usually T4).

Small pitfall: "Failed to assign a backend — No backend with GPU available" was reported once at the beginning of the connection. The free GPU was queued to grab, and I got it after trying again after a few minutes.

2. Install Ollama and start the service

!apt-get -qq install -y zstd > /dev/null 2>&1
!curl -fsSL https://ollama.com/install.sh | sh

There is no systemd in Colab, so the service uses nohup to run in the background:

!nohup ollama serve > /tmp/ollama.log 2>&1 &

Wait a few seconds and verify:

!curl -s http://localhost:11434

Returning Ollama is running means the service is started.

3. Pull model

!ollama pull qwen2.5:14b

About 9 GB, a few minutes on a good internet speed. After pulling !ollama list you can see it.

4. Use the API to test the connection first, and then log in to the interface.

Don’t rush to make the interface, first use curl to confirm that the model itself can answer:

!curl -s http://localhost:11434/api/generate -d '{"model": "qwen2.5:14b", "prompt": "用中文用三句话介绍一下你自己", "stream": false}'

Model reply (original text): "My name is Tongyi Qianwen, and I am a large-scale language model developed by Alibaba Cloud. I can understand and generate natural language to help users answer questions, create text, and conduct conversations." — Got it.

5. Gradio chat page

Use Gradio's ChatInterface to make a simple chat page, adjust Ollama's /api/chat on the backend, be careful to set num_ctx to 4096, and don't open the context too large:

import requests, gradio as gr

def chat(message, history):
    msgs = []
    for h in history:
        if isinstance(h, dict):
            msgs.append({"role": h["role"], "content": h["content"]})
    msgs.append({"role": "user", "content": message})
    r = requests.post("http://localhost:11434/api/chat", json={
        "model": "qwen2.5:14b", "messages": msgs,
        "stream": False, "options": {"num_ctx": 4096}}, timeout=600)
    return r.json()["message"]["content"]

gr.ChatInterface(chat, title="Qwen2.5 14B").launch(share=True)

share=True will generate a *.gradio.live public link. You can chat by opening the browser on your mobile phone or computer without logging in. The measured response is normal.

Trampling on pit records

Pit 1: The chat page reports HTTP 400. I opened a ready-made Gradio page during the tossing, and it responded with "(No reply received, HTTP 400)" after sending anything. Later, it was confirmed that the page was not created by this notebook at all, and the Colab session behind it had long been disconnected - the front-end page was still alive, but the back-end was gone, so naturally nothing could be answered. Lesson: The life and death of the Gradio shared link completely depends on the Colab session. Just because the page can be opened does not mean that the model is still alive.

Pit 2: Once the session is disconnected, everything is cleared. After the Colab free version was recycled during runtime, the installed Ollama and the 9 GB model that was pulled were all gone, leaving only the notebook file itself. I originally wanted to save the model to Google Drive to avoid re-pull, but 12 GB of the 15 GB hard drive has been used, and 9 GB cannot be accommodated, so I had to give up.

Disconnection and reconnection: one-click start

The solution is to combine all the startup steps into one grid and put them at the top of the notebook. After disconnecting, restart the notebook and run only this grid:

!apt-get -qq install -y zstd > /dev/null 2>&1
!curl -fsSL https://ollama.com/install.sh | sh
!nohup ollama serve > /tmp/ollama.log 2>&1 &
import time; time.sleep(5)
!ollama pull qwen2.5:14b
!curl -s http://localhost:11434

After running, run the last Gradio cell to generate a new link - note that it is a new link every time and the old link is invalid.

Summary

  • It is completely feasible to run 14B quantitative model on free T4, and the quality of Chinese dialogue is good
  • Qwen2.5 14B is a pure text model. It cannot draw pictures or make videos. If you want to come up with pictures, you have to open a separate notebook to run SDXL and other models.
  • The free version of Colab is suitable for temporary experience: it does not cost money, but the model must be re-pulled every time it is reopened, and the links will also change. For long-term use, either free up 10 GB storage model for the cloud drive, or it is more practical to install Ollama locally.
Views 0 次

Comments

加载中…

Comments appear after review.

← Back to Home