20. Model Download Failures

Chapter 20 of 20 · 20 min

Downloads fail due to network issues, disk space problems, corrupted caches, or registry errors. This chapter covers diagnosing and resolving download failures.

Symptoms

  • ollama pull hangs or times out
  • Error: failed to pull model message
  • Incomplete downloads on retry
  • "file too short" errors

Network Issues

Check connectivity:

curl -I https://ollama.com

If this fails, check your network configuration, proxy settings, or firewall rules.

Proxy configuration:

# Linux/macOS
export HTTPS_PROXY=http://proxy.example.com:8080
export HTTP_PROXY=http://proxy.example.com:8080
ollama pull llama3.2:1b

# Windows PowerShell
$env:HTTPS_PROXY = "http://proxy.example.com:8080"
$env:HTTP_PROXY = "http://proxy.example.com:8080"
ollama pull llama3.2:1b

Timeout settings:

export OLLAMA_CONNECT_TIMEOUT=120
ollama pull llama3.2:1b

Disk Space

Verify available space:

# Linux/macOS
df -h ~/.ollama

# Windows PowerShell
Get-PSDrive C | Select-Object Used,Free

Models can require 2-20 GB of disk space. Free up space or point to a larger drive:

# Linux/macOS - use different directory
export OLLAMA_MODELS=/mnt/large-drive/ollama-models
ollama pull llama3.2:1b

# Windows PowerShell
$env:OLLAMA_MODELS = "D:\\ollama-models"
ollama pull llama3.2:1b

Corrupted Cache

Manifests and partial downloads can corrupt. Clear the cache:

# Stop all running models
ollama stop llama3.2:1b

# Remove the specific model
ollama rm llama3.2:1b

# Clear manifest cache
rm -rf ~/.ollama/models/manifests/registry.ollama.ai/library/llama3.2@*

# Retry download
ollama pull llama3.2:1b

On Windows:

ollama stop llama3.2:1b
ollama rm llama3.2:1b
Remove-Item -Recurse -Force "$env:USERPROFILE\\.ollama\\models\\manifests\\registry.ollama.ai\\library\\llama3.2@*"
ollama pull llama3.2:1b

Registry Errors

If Ollama's registry is unreachable, try an alternative:

# Use a mirror (if available)
export OLLAMA_REGISTRY=https://mirror.example.com
ollama pull llama3.2:1b

Alternatively, download model files manually and import them:

# Import a GGUF file
ollama create llama3.2:1b -f ./Modelfile

Where the Modelfile specifies the local path:

FROM ./llama3.2-1b-q4_k_m.gguf

Retry Logic Script

#!/bin/bash
MODEL=$1
MAX_RETRIES=5
RETRY_DELAY=30

for i in $(seq 1 $MAX_RETRIES); do
    echo "Attempt $i of $MAX_RETRIES: Pulling $MODEL"
    if ollama pull "$MODEL" 2>&1; then
        echo "Success"
        exit 0
    fi
    echo "Failed. Waiting $RETRY_DELAY seconds..."
    sleep $RETRY_DELAY
done

echo "Failed after $MAX_RETRIES attempts"
exit 1

Verifying Downloads

After a successful pull, verify the model:

ollama list
ollama show llama3.2:1b

The show command displays model metadata and file locations. If the model appears but fails to run, the download may be incomplete.

EXERCISE

Simulate a download failure by setting an invalid proxy (export HTTPS_PROXY=http://invalid:8080), then retry with correct settings. Verify the cache cleanup process works correctly.