GPU Infrastructure and Model Serving / Start Here

Set up the environment and send the first request

Lesson 2 of 29. Open to read. No account needed.

What You Will Build

By the end of this lesson your computer will hold one folder with a Python environment, the llama.cpp server and a 491 MB model file, and you will have watched the server load that model, declare itself healthy and answer one chat request. You will also break it twice on purpose, so that the two commonest setup errors are familiar before they are surprising. Every later lesson starts from the state this lesson leaves.

A flow with five parts: the learner at a terminal; terminal one running llama-server with the model file loaded from the models folder; terminal two sending curl requests; the server's /health route showing 503 while the model loads and 200 once it is ready; the first chat reply flowing back to terminal two with its usage counts.

Figure: the two terminals and the server between them. Terminal one owns the server process; terminal two talks to it over HTTP on your own machine. Read /health as the signal that loading has finished.

Bridge: Two Terminals and a Session Variable

A server is a program that runs until you stop it, so it needs a terminal of its own. This course uses terminal one for the server and terminal two for everything you send to it. Open two windows or tabs of your terminal application (Terminal or iTerm on macOS, Windows Terminal with PowerShell on Windows, any terminal on Linux). In each, pwd prints where you are, ls (or dir on PowerShell) lists files, cd moves, mkdir creates a folder. Ctrl+C stops the program in the foreground.

A variable set in a terminal lives only in that terminal and dies with it. You will use one for the model path:

MODEL=~/gpu-serving-practice/models/qwen2.5-0.5b-instruct-q4_k_m.gguf
echo $MODEL

PowerShell: $MODEL = "$HOME\gpu-serving-practice\models\qwen2.5-0.5b-instruct-q4_k_m.gguf" and echo $MODEL. If you open a new terminal, set it again.

Bridge: HTTP With curl

Everything you send to the server is an HTTP request: a method (GET to read, POST to send data), a path such as /health, optional headers, and for POST a body, here always JSON. The reply has a status code and a body. The codes you will meet in this lesson: 200 (fine), 503 (the server is up but not ready), 404 (no such path). curl sends a request from the terminal; -s keeps it quiet, -H adds a header, -d sends a body. Chat replies can also stream: the server sends the answer piece by piece as it is generated. The first request below does not stream; the next lessons do.

Step 1: Python and the Course Environment

The course supports Python 3.12 to 3.15 (S60). Check what you have:

python3 --version

PowerShell: py -3 --version. If the version is below 3.12, install one from python.org (Windows and macOS) or your distribution's packages (Linux; on Debian and Ubuntu also install the python3-venv package).

Create the practice folder and an environment inside it, then install the two pinned libraries: huggingface_hub 2.2.0 provides the hf download command (S58, S59) and httpx 0.28.1 is the HTTP client the course's scripts use (S66).

mkdir -p ~/gpu-serving-practice/models
python3 -m venv ~/gpu-serving-practice/.venv
source ~/gpu-serving-practice/.venv/bin/activate
python -m pip install "huggingface_hub==2.2.0" "httpx==0.28.1"

PowerShell: py -3 -m venv $HOME\gpu-serving-practice\.venv, then & $HOME\gpu-serving-practice\.venv\Scripts\Activate.ps1, then the same pip line. Activation puts (.venv) at the start of your prompt; every python and pip after that is the environment's. You activate in every new terminal. The author's install took 29 seconds and resolved 18 packages (illustrative).

Step 2: llama.cpp

llama.cpp is the serving program for the core track: one program that runs on CPUs, Apple Metal and NVIDIA CUDA (S06). Install it the way your platform prefers (S04):

  • macOS or Linux with Homebrew: brew install llama.cpp
  • Windows: winget install llama.cpp
  • Any platform: download the archive for your system from the project's releases page (S02): macos-arm64, win-cpu-x64, ubuntu-x64, or a cuda archive if you have an NVIDIA GPU and its driver; extract it and put its folder on your PATH.

Then confirm:

llama-server --version
llama-server --list-devices

The author's machine printed version: 0.7.0 (build 11669, commit 620d2225c) and listed BLAS: Accelerate and MTL0: Apple M2 (10922 MiB) (illustrative, 2026-10-21). Package managers build the project's numbered releases, which lag the release page's build tags (b11796 was the newest that day; S02, S63), so your build may be newer. Write your version down; later lessons ask for it when a result differs. A CPU-only machine lists just the CPU; an NVIDIA machine with a CUDA build lists CUDA0.

Step 3: The Model File

The practice model is Qwen2.5-0.5B-Instruct in GGUF form, published by its authors under Apache-2.0 (S56). Download the Q4_K_M file with the hf command into the models folder:

hf download Qwen/Qwen2.5-0.5B-Instruct-GGUF qwen2.5-0.5b-instruct-q4_k_m.gguf --local-dir ~/gpu-serving-practice/models

The file is 491,400,032 bytes. On a slow connection it takes 10 to 20 minutes; the command shows progress and resumes if interrupted. If it stalls with no progress for several minutes, stop it with Ctrl+C and use curl, which resumes a partial file:

curl -L --http1.1 -C - --retry 10 -o ~/gpu-serving-practice/models/qwen2.5-0.5b-instruct-q4_k_m.gguf https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf

Whichever way it arrived, the next step checks its size and hash; a truncated file is the commonest cause of a server that will not load.

Step 4: The Check Script

Save this file as check_setup.py in a new folder ~/gpu-serving-practice/set-up-and-send-the-first-request and run it from there with the environment active. It changes nothing; it reads versions and the file and compares them with the course's pins.

"""Readiness check for the GPU Infrastructure and Model Serving course.

Run it inside the course environment from any folder:

  python check_setup.py

It prints the Python and library versions, the llama-server version and
devices, and the practice model file's size and SHA-256 against the values
published for Qwen2.5-0.5B-Instruct-GGUF Q4_K_M. It changes nothing.
"""
import hashlib, pathlib, shutil, subprocess, sys

EXPECTED_SIZE = 491400032
EXPECTED_SHA256 = "74a4da8c9fdbcd15bd1f6d01d621410d31c6fc00986f5eb687824e7b93d7a9db"
MODEL = pathlib.Path.home() / "gpu-serving-practice" / "models" / "qwen2.5-0.5b-instruct-q4_k_m.gguf"

def line(ok, label, detail):
    print(f"[{'ok' if ok else 'CHECK'}] {label}: {detail}")
    return ok

def main():
    results = []
    v = sys.version_info
    results.append(line((3, 12) <= (v.major, v.minor) <= (3, 15), "Python", f"{v.major}.{v.minor}.{v.micro} at {sys.executable}"))
    results.append(line("gpu-serving-practice" in sys.executable, "environment", "the interpreter is inside ~/gpu-serving-practice/.venv" if "gpu-serving-practice" in sys.executable else "this is not the course environment; activate it first"))
    try:
        import httpx, huggingface_hub
        results.append(line(httpx.__version__ == "0.28.1" and huggingface_hub.__version__ == "2.2.0", "libraries", f"httpx {httpx.__version__}, huggingface_hub {huggingface_hub.__version__} (course pins 0.28.1 and 2.2.0)"))
    except ImportError as e:
        results.append(line(False, "libraries", f"missing: {e}"))
    server = shutil.which("llama-server")
    if server:
        version = subprocess.run([server, "--version"], capture_output=True, text=True).stderr.strip().splitlines()
        results.append(line(True, "llama-server", f"{server}; {version[0] if version else 'no version line'}"))
        devices = subprocess.run([server, "--list-devices"], capture_output=True, text=True)
        print("       devices:", " | ".join(l.strip() for l in (devices.stdout + devices.stderr).splitlines() if l.strip() and "Available" not in l))
    else:
        results.append(line(False, "llama-server", "not found on the PATH"))
    if MODEL.exists():
        size = MODEL.stat().st_size
        ok = size == EXPECTED_SIZE
        results.append(line(ok, "model size", f"{size:,} bytes (expected {EXPECTED_SIZE:,})"))
        if ok:
            h = hashlib.sha256()
            with open(MODEL, "rb") as f:
                for chunk in iter(lambda: f.read(1 << 20), b""):
                    h.update(chunk)
            results.append(line(h.hexdigest() == EXPECTED_SHA256, "model SHA-256", h.hexdigest()[:16] + "... (compared with the published hash)"))
    else:
        results.append(line(False, "model file", f"not found at {MODEL}"))
    print("ready" if all(results) else "not ready: fix the CHECK lines above")
    return 0 if all(results) else 1

if __name__ == "__main__":
    sys.exit(main())

What it checks, block by block: the interpreter is a supported version and lives inside the course environment (so pip installed into the right place); the two libraries are the pinned versions; llama-server is on the PATH, with its version and devices printed for your notes; the model file exists, has exactly the published size and, if so, the published SHA-256 (the hash takes a few seconds). A line that starts [CHECK] names what to fix; the last line is ready or not.

cd ~/gpu-serving-practice/set-up-and-send-the-first-request
python check_setup.py

The author's output (illustrative; the path and devices are the machine's):

[ok] Python: 3.13.0 at /Users/.../gpu-serving-practice/.venv/bin/python
[ok] environment: the interpreter is inside ~/gpu-serving-practice/.venv
[ok] libraries: httpx 0.28.1, huggingface_hub 2.2.0 (course pins 0.28.1 and 2.2.0)
[ok] llama-server: /opt/homebrew/bin/llama-server; version: 0.7.0 (build 11669, commit 620d2225c)
       devices: BLAS: Accelerate (0 MiB, 0 MiB free) | MTL0: Apple M2 (10922 MiB, 10922 MiB free)
[ok] model size: 491,400,032 bytes (expected 491,400,032)
[ok] model SHA-256: 74a4da8c9fdbcd15... (compared with the published hash)
ready

Step 5: Start the Server and Send the First Request

Terminal one, with the environment active:

llama-server -m ~/gpu-serving-practice/models/qwen2.5-0.5b-instruct-q4_k_m.gguf --metrics

The server prints its start-up and, when the model is loaded, a line listening on http://127.0.0.1:9931: the default address is your own machine and the default port is 9931 (S01). The first load of a session reads 491 MB from disk; the author's took about 23 seconds, later starts one or two.

Terminal two, while it loads and again after:

curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:9931/health

During loading the code is 503; once the model is loaded it is 200 and the body is {"status":"ok"} (S01). Then the first request:

curl -s http://127.0.0.1:9931/v1/chat/completions -H 'Content-Type: application/json' -d '{"messages":[{"role":"user","content":"Reply with the single word READY."}],"max_tokens":8,"temperature":0}'

PowerShell quoting differs; put the JSON in a file first.json and use curl.exe -s http://127.0.0.1:9931/v1/chat/completions -H "Content-Type: application/json" -d "@first.json".

The reply is a JSON object. The author's (illustrative):

{"choices":[{"finish_reason":"stop","index":0,"message":{"role":"assistant","content":"READY"}}],
 "created":1792597059,"model":"...qwen2.5-0.5b-instruct-q4_k_m.gguf",
 "usage":{"completion_tokens":2,"prompt_tokens":36,"total_tokens":38, ...}}

Two fields matter from now on: choices[0].message.content is the answer, and usage counts the prompt tokens (36, because the chat template wraps your message) and the completion tokens (2: the word and the stop). temperature: 0 makes the answer repeatable.

Observable Success

check_setup.py ends with ready; /health moved from 503 to 200; the reply contains a content string and a usage object with a positive completion_tokens. That last field is the proof, not the exit code of curl, which is zero even for a 404.

Step 6: Break It Twice (the Planted Failures)

Leave the server running in terminal one. In terminal two, start a second server on the same port:

llama-server -m ~/gpu-serving-practice/models/qwen2.5-0.5b-instruct-q4_k_m.gguf

It loads the whole model first and only then fails, so the error arrives after the loading time (the author's after 1 minute 19 seconds on a busy machine):

E srv         start: couldn't bind HTTP server socket, hostname: 127.0.0.1, port: 9931
E srv  llama_server: exiting due to HTTP server error

The exit code is 1. That is P01: something already holds the port. lsof -i :9931 (macOS, Linux) or Get-NetTCPConnection -LocalPort 9931 (PowerShell) names the process; the fix is to stop it or to start the new server with --port 9932.

Now stop the server in terminal one (Ctrl+C) and start one with a misspelt path:

llama-server -m ~/gpu-serving-practice/models/qwen2.5-0.5b-instruct-q4_k_m.ggfu
E gguf_init_from_file: failed to open GGUF file '.../qwen2.5-0.5b-instruct-q4_k_m.ggfu'
E llama_model_load: error loading model: llama_model_loader: failed to load model from ...
E srv  llama_server: exiting due to model loading error

Exit code 1 again, within a second. That is P02: the path is wrong, or the file is truncated, in which case the message is a load failure rather than "failed to open". check_setup.py catches the truncated case by size before you ever start a server; a wrong path it cannot guess, so read the path in the error.

What Differing Results Mean

  • [CHECK] environment: you ran python without activating, so pip installed into the system interpreter. Activate and reinstall.
  • [CHECK] llama-server: not found: the install did not put it on the PATH; for an extracted archive, add its folder to the PATH or call it by its full path.
  • [CHECK] model size: a partial download; rerun the hf command or the curl command, both resume.
  • /health stays 503 for minutes: the first load on a slow disk; wait, and watch terminal one for the model loaded line.
  • curl: (7) Failed to connect: the server is not listening yet or is on another port; read its listening on line.
  • A 404: the path is wrong (/v1/chat/completion without the s, for example).
  • The reply is not READY: the model may phrase it differently; what matters is content and usage, not the word.

Independent Task

Send the same request with "max_tokens": 1 and predict finish_reason and completion_tokens before you look. Then ask a longer question with "max_tokens": 64 and compare prompt_tokens with your first request: why did it change by more than the words you added? (The chat template adds the same fixed tokens each time; the difference is your text.)

Check Your Understanding

  1. Why does the course pin huggingface_hub==2.2.0 and httpx==0.28.1 instead of installing the latest?
  2. What does [ok] environment prove, and which failure does it prevent?
  3. The second server failed 79 seconds after you started it. Why so late, and what does that tell you to check before blaming the port?
  4. Which field in the first reply proves the server generated text, and why is curl's exit code not enough?

Answers: (1) So that the scripts behave the same on every machine and the course can state what it tested; newer versions may change behaviour. (2) That python is the environment's interpreter, so pip installed into it; it prevents installing into the system Python and then not finding the libraries. (3) It loaded the model before trying to bind the port, so the time was the load; the bind error names the port, and lsof names the holder. (4) usage.completion_tokens above zero with a content string; curl exits zero for any HTTP reply, including 404.

Reset and Cleanup

Stop any server with Ctrl+C. Keep ~/gpu-serving-practice/.venv and models; every later lesson uses them. You may remove the exercise folder set-up-and-send-the-first-request after checking the path. If you ever need to start over, delete .venv and repeat Step 1; keep the model file, which took the longest to obtain.

Sources

Routes, the default port and the health behaviour: the llama-server README (S01). Install methods and release archives: the llama.cpp install and release pages (S02, S04, S63). The model and its licence: the model card (S56). The hf command and the library versions: the Hub CLI guide and PyPI (S58, S59, S66). Python support status: python.org (S60). Measurements are the author's on 2026-10-21 and illustrative.

24 more lessons in the full course

Course access opens every lesson and adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

Get the full course

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy