Skip to content

About

Download models from modelscope using Kubernetes Jobs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

Modelscope Download Job

Download models from modelscope using Kubernetes Jobs, also supports using docker.

Overview

When I deploy models on my clusters I use the following solution:

  1. On all the "model deployment capable" nodes I have SSD disks mounted on specific locations. The nodes are labeled so I can target them with selectors.
  2. I pre-decide which nodes could run these models, let's say I want to deploy a 400B model, I see it could run on 3 servers.
  3. I copy the model to the model SSD disk on the target nodes, and label them to mark it has it, for example, if the model was Qwen/Qwen3.5-397B-A17B, it would be located on the model mount path at /Qwen/Qwen3.5-397B-A17B and the nodes with this model are labeled like has-model/Qwen_Qwen3.5-397B-A17B=1
  4. When I deploy the inference servers, I use nodeSelectors to let Kubernetes decide which node to run, the model is bind-mounted to /model.

This solution avoids repeating model download, you spend a little more time preparing but it is faster to boot.

This project provides a container image, Helm chart, and helper scripts to download these models (from modelscope). The download runs as a Kubernetes Job, making it easy to manage and monitor.

Project Structure

modelscope-download-job/
├── compose.yaml            # Docker Compose for local testing
├── docker/
│   └── Dockerfile          # Container image definition
├── README.md               # This file
├── chart/
│   ├── Chart.yaml          # Helm chart metadata
│   ├── values.yaml         # Default configuration values
│   └── templates/
│       ├── helpers.tpl     # Template helper functions
│       ├── job.yaml        # Job template
│       └── pvc.yaml        # PVC template (for new PVC)
└── scripts/
    ├── download-model.sh   # Linux/macOS helper script
    └── download-model.ps1  # Windows PowerShell helper script

Container Image

The docker/Dockerfile creates a Python-based container with modelscope pre-installed.

Build Arguments

Argument Default Description
REGISTRY docker.io Container registry
PIP_INDEX_URL https://pypi.org/simple PyPI package index

Build Example

# Build with default settings (no registry prefix)
docker build -t aaronps/modelscope-download:latest ./docker

# Build with custom registry
docker build --build-arg REGISTRY=ghcr.io -t ghcr.io/aaronps/modelscope-download:latest ./docker

# Build with custom pip index
docker build --build-arg PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple -t aaronps/modelscope-download:latest ./docker

Docker Compose

For local development or testing, you can use Docker Compose:

# Download model using environment variable
docker compose run --rm -e MODEL=Qwen/Qwen3.5-9B download

# Download preconfigured Qwen model
docker compose run --rm download-qwen

The compose file defines three services:

  • template - Base configuration (not run directly)
  • download - Uses MODEL environment variable (passed via -e)
  • download-qwen - Preconfigured for Qwen/Qwen3.5-0.8B

Note: The download service uses shell expansion ($$MODEL) to read the environment variable at runtime, while download-qwen has the model hardcoded in the command. This is because docker compose run -e sets the environment variable in the container, but the command is parsed when the service is defined.

You can use the same idea to download the models using docker command directly.

Helm Chart

The Helm chart creates a Kubernetes Job that runs modelscope download.

Usage (Manual)

# Download with local bind-mount (requires nodeSelector to match the node with the path)
helm template download-qwen35 ./chart \
  --set model=Qwen/Qwen3.5-9B \
  --set storage.local.path=/mnt/data/models \
  --set nodeSelector.kubernetes\.io/hostname=test \
  | kubectl apply -f - -n mynamespace

# Download with existing PVC
helm template . download-qwen35 \
  --set model=Qwen/Qwen3.5-9B \
  --set storage.pvc.name=my-pvc \
  | kubectl apply -f - -n mynamespace

# Download with new PVC
helm template . download-qwen35 \
  --set model=Qwen/Qwen3.5-9B \
  --set storage.newPvc.name=models-pvc \
  --set storage.newPvc.size=50Gi \
  | kubectl apply -f - -n mynamespace 

# Download on specific node
helm template . download-qwen35 \
  --set model=Qwen/Qwen3.5-9B \
  --set storage.local.path=/mnt/data/models \
  --set nodeSelector.kubernetes\.io/hostname=test \
  | kubectl apply -f - -n mynamespace 

Values Reference

Key Type Default Description
global.imageRegistry string "" Global container registry (used if image.registry is empty)
image.registry string "" Container registry (overrides global)
image.repository string aaronps/modelscope-download Image repository
image.tag string latest Image tag
image.pullPolicy string IfNotPresent Image pull policy
model string "" Required Model name (e.g., Qwen/Qwen3.5-9B)
downloadPath string "" Path within /data (defaults to model name)
storage.local.path string "" Host path for local bind-mount
storage.local.type string Directory Host path type
storage.pvc.name string "" Existing PVC name
storage.newPvc.name string "" New PVC name
storage.newPvc.size string "" New PVC size (required if newPvc.name is set)
storage.newPvc.storageClass string "" Storage class for new PVC
nodeSelector object {} Node selector labels
tolerations array [] Pod tolerations
affinity object {} Pod affinity rules
job.backoffLimit int 3 Number of retry attempts
job.activeDeadlineSeconds int `` Job timeout
job.ttlSecondsAfterFinished int `` TTL for completed job
pod.restartPolicy string Never Pod restart policy
resources object {} Resource limits/requests
imagePullSecrets array [] Image pull secrets

Helper Scripts

Linux/macOS

# Make script executable
chmod +x scripts/download-model.sh

# Download with local bind-mount
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B -l /mnt/models

# Download with existing PVC
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B -p my-pvc

# Download with new PVC
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B --new-pvc model-pvc 50Gi

# Download on specific node, remeber to escape dots.
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B -l /mnt/models --node-selector kubernetes\\.io/hostname=worker-1

# Dry run (show YAML without applying)
./scripts/download-model.sh qwen35-9b Qwen/Qwen3.5-9B -l /mnt/models --dry-run

Windows PowerShell

# Download with local bind-mount
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -LocalPath "/mnt/models"

# Download with existing PVC
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -PvcName "my-pvc"

# Download with new PVC, on powershell you need to use a comma to separate both values.
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -NewPvc model-pvc, 50Gi

# Download on specific node, escape the dot on kuberente.io
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -LocalPath "/mnt/models" -NodeSelector "kubernetes\.io/hostname=worker-1"

# Dry run (show YAML without applying)
.\scripts\download-model.ps1 -JobName "qwen35-9b" -Model "Qwen/Qwen3.5-9B" -LocalPath "/mnt/models" -DryRun

About

Download models from modelscope using Kubernetes Jobs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages