Happy Dussehra! May good always win. Merry Christmas! Warm wishes from Vizag. Happy New Year! Here’s to a great year ahead.

DevOps

Sprint 6 project, Part 3: The Model Path

Decide GPU spot nodes versus a small CPU model from prices read on the day, then build the model path: Karpenter pools, MatrixHub, vLLM served through KServe, a Kubeflow Trainer forecast job, an Unsloth fine-tune, a DeepEval gate and one Kubeflow Pipelines run that registers only passing models.

16 min read

  • MatrixHub
  • vLLM
  • KServe
  • Kubeflow Trainer
  • Kubeflow Pipelines
  • Unsloth
  • DeepEval
  • Karpenter
  • ClickHouse
  • Kubernetes
  • Python
  • NVIDIA device plugin

This is Part 3 of the six-part build in the Sprint 6 project overview. Parts 1 and 2 left you a cluster with Karpenter, a data layer and seeded tenants. Now the AI half gets its model path: a registry (MatrixHub), a server (vLLM through KServe), training (Kubeflow Trainer for a demand-forecast model and Unsloth for a small fine-tune), a gate (DeepEval) and one run of Kubeflow Pipelines that ties it together. The first section is a decision: GPU spot nodes for a few hours, or a small model on CPU.

Where this part fits. This part builds the model path (marked Part 3 on the overall diagram). Open the zoomable Sprint 6 architecture or read the Overview.

Overall Sprint 6 architecture

What this is and is not. This is engineering guidance, not legal or financial advice. It is a reference blueprint: the intended flow and the wiring between the tools. Versions, chart keys, runtime arguments and API fields change between releases, so each section gives a check to confirm them on your version. If you hit a bug or a mismatch, use the “Suggest a correction” link on this page.

What you build, and in what order

Part 3 architecture. ClickHouse supplies features to Kubeflow Pipelines, which starts a Kubeflow Trainer job for the forecast model and an Unsloth fine-tune on a spot GPU node. A DeepEval gate scores each candidate; only a passing model is registered in MatrixHub. KServe pulls weights from MatrixHub and serves them with vLLM, on nodes that Karpenter provides as GPU spot nodes or CPU nodes.

One image, the layers of this part. Open the zoomable diagram, or download it as SVG or PNG.

Two models travel the same road. The forecast model is small, trains on CPU from the seeded orders in ClickHouse, and feeds planning screens. The copilot model is a small language model that Unsloth fine-tunes with LoRA, which needs a GPU for a short while. Both must pass a gate before MatrixHub accepts them, and only models in MatrixHub are served.

Flow in eight steps: decide GPU or CPU from prices read that day, create node pools, cache the base model in MatrixHub, serve it through KServe with vLLM, train the forecast model, fine-tune with Unsloth, gate with DeepEval, then run it all as one Kubeflow pipeline.

  1. The decision: GPU spot or CPU, with prices read today
  2. Node pools
  3. MatrixHub and the base model
  4. Serving with KServe and vLLM
  5. The forecast model with Kubeflow Trainer
  6. The fine-tune with Unsloth
  7. The DeepEval gate
  8. One Kubeflow Pipelines run
  9. Troubleshooting, cost, cleanup, checklist

1. The decision: GPU spot or CPU

The question left open in the plan: do you rent a GPU for a few hours, or run a small model on CPU? The prices below were read on 4 December 2026. They come from a third-party price tracker (DoiT’s spot pages), not from AWS pricing pages, and they are for ap-south-1 (Mumbai), which is the Region this build uses. Spot prices move continuously, and the tracker showed more than one snapshot, so treat each spot figure as a range.

Instance GPU On-demand per hour Spot, lowest seen Spot interruption band
g6.xlarge 1 Ă— L4 $0.9664 $0.3880 above 20%
g5.xlarge 1 Ă— A10G, 24 GB $1.2080 $0.4215 to $0.6102 (two snapshots) above 20%
g4dn.xlarge 1 Ă— T4 $0.5790 $0.2087 15 to 20%
m5.xlarge (CPU) none $0.2020 $0.0512 10 to 15%

What this means for the build:

  • Training and the fine-tune use spot GPUs. They are batch jobs, they checkpoint, and an interruption costs minutes, not an outage. Six GPU hours on a g5.xlarge is about $7.25 on demand and roughly $2.5 to $3.7 on spot at the prices above; a g6.xlarge or g4dn.xlarge is cheaper still. The NodePool lists all three instance types, because AWS advises being as diverse as possible in instance types and zones for Spot, and the interruption bands above are high enough that a single type would stall.
  • Serving during the build uses the same GPU pool, scaled to zero when idle. A GPU node serving a 1 to 3 billion parameter model answers in a second or two; leave it up only while you test the copilot in Parts 4 and 5.
  • A small CPU model is the standing fallback. Keeping a GPU node up for the full three days would cost on the order of $30 on spot or $87 on demand for a g5.xlarge (72 hours), so between sessions the copilot falls back to a small model on the CPU nodes the general pool already has. The vLLM docs describe their CPU example as for demonstration only, so the fallback is slower, and this build accepts that.

Decision: spot GPU for training and for short serving sessions, scale to zero otherwise, and a small CPU model as the fallback. If a spot GPU is not available in your Region on the day, run the fine-tune on a g4dn on demand, or skip it and use the base model; the pipeline’s gate works either way. Recheck prices before you start; the figures above are a snapshot, not a quote.

2. Node pools

Add a GPU NodePool next to the general one from Part 1. It scales to zero, and the taint keeps ordinary pods off it:

apiVersion: karpenter.sh/v1
kind: NodePool
metadata: { name: gpu-spot }
spec:
  template:
    spec:
      nodeClassRef: { group: karpenter.k8s.aws, kind: EC2NodeClass, name: default }
      taints: [{ key: nvidia.com/gpu, value: "true", effect: NoSchedule }]
      requirements:
        - { key: karpenter.sh/capacity-type, operator: In, values: ["spot", "on-demand"] }
        - { key: node.kubernetes.io/instance-type, operator: In, values: ["g6.xlarge", "g5.xlarge", "g4dn.xlarge"] }
        - { key: kubernetes.io/arch, operator: In, values: ["amd64"] }
  limits: { cpu: "16", "nvidia.com/gpu": "4" }
  disruption: { consolidationPolicy: WhenEmpty, consolidateAfter: 2m }

Listing both capacity types lets Karpenter fall back to on-demand when spot capacity is missing (it prefers spot when both are allowed). GPU pods need the NVIDIA device plugin to see the GPU:

helm repo add nvdp https://nvidia.github.io/k8s-device-plugin && helm repo update
helm upgrade --install nvdp nvdp/nvidia-device-plugin -n kube-system \
  --set tolerations[0].key=nvidia.com/gpu --set tolerations[0].operator=Exists

Confirm that the al2023@latest image alias in the Part 1 EC2NodeClass resolves to an NVIDIA-capable image for GPU instance types; if not, create a second EC2NodeClass for the GPU pool with the accelerated AMI. Check: schedule a pod that requests nvidia.com/gpu: 1 and runs nvidia-smi; a node appears, the output lists the GPU, and two minutes after you delete the pod the node is gone.

3. MatrixHub and the base model

helm install matrixhub oci://ghcr.io/matrixhub-ai/matrixhub --version <chart-version> \
  --namespace matrixhub --create-namespace \
  --set apiserver.storage.pvc.size=100Gi
kubectl -n matrixhub get pods,svc,pvc

The brief explains the chart’s values; the model volume defaults to 50 Gi, so raise it as above. MatrixHub speaks the Hugging Face protocol, so you cache a base model by pointing the standard client at it:

kubectl -n matrixhub port-forward svc/matrixhub 9527:<service-port> &
HF_ENDPOINT=http://localhost:9527 hf download Qwen/Qwen3-0.6B

Pick the base model for the language skills you need and the licence you can accept; the example above is small enough for the CPU fallback, and a 1 to 3 billion parameter model is a reasonable fine-tune size on a 24 GB GPU with 4-bit LoRA. Check: run the same download again; it returns fast and the MatrixHub logs show a cache hit.

4. Serving with KServe and vLLM

Install KServe in standard (raw deployment) mode as the brief describes, then serve the model from MatrixHub by pointing the runtime at it through HF_ENDPOINT. The runtime and argument names below follow the KServe Hugging Face runtime; confirm them with kubectl get clusterservingruntimes on your version.

apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
  name: copilot-llm
  namespace: ai
  annotations: { serving.kserve.io/deploymentMode: RawDeployment }
spec:
  predictor:
    minReplicas: 0
    maxReplicas: 1
    tolerations: [{ key: nvidia.com/gpu, operator: Exists, effect: NoSchedule }]
    model:
      modelFormat: { name: huggingface }
      runtime: kserve-huggingfaceserver
      args: ["--model_id=Qwen/Qwen3-0.6B", "--model_name=copilot", "--backend=vllm"]
      env:
        - { name: HF_ENDPOINT, value: "http://matrixhub.matrixhub.svc.cluster.local:<service-port>" }
      resources:
        limits: { nvidia.com/gpu: "1", memory: 12Gi }

minReplicas: 0 needs an autoscaling mode that supports scale to zero; in raw mode with KEDA, check the brief’s autoscaling section, or use minReplicas: 1 for the test and delete the service afterwards. For the CPU fallback, deploy a second InferenceService without the GPU limit and with a smaller model, and expect it to be slow.

kubectl -n ai get inferenceservice copilot-llm
kubectl -n ai port-forward svc/copilot-llm-predictor 8080:80 &
curl http://localhost:8080/openai/v1/chat/completions -H 'Content-Type: application/json' \
  -d '{"model":"copilot","messages":[{"role":"user","content":"Explain accounts payable in one sentence."}],"max_tokens":60}'

Check: the InferenceService reports Ready, the request returns a completion, and the pod logs show the model loaded from the MatrixHub address, not from the internet. The OpenAI-style path differs between runtimes, so read it from the service’s documentation if the request returns 404.

5. The forecast model with Kubeflow Trainer

The forecast is a small model of weekly demand per tenant and item, trained on the orders Part 2 seeded. It runs on CPU as a one-node TrainJob; the same shape scales to several nodes when the model grows.

apiVersion: trainer.kubeflow.org/v1alpha1
kind: TrainJob
metadata: { name: forecast-v1, namespace: ai }
spec:
  runtimeRef: { apiGroup: trainer.kubeflow.org, kind: ClusterTrainingRuntime, name: torch-distributed }
  trainer:
    numNodes: 1
    image: <your-registry>/erp-forecast:<tag>
    command: ["python", "/app/train_forecast.py"]
    env:
      - { name: CLICKHOUSE_URL, value: "http://clickhouse.clickhouse:8123" }
      - { name: OUT_DIR, value: /out }

The script reads daily order counts per tenant and item from ClickHouse, builds lag features, trains a small network, and reports the mean absolute percentage error on the last four weeks as held-out data. Field names under trainer differ between Trainer releases, so check kubectl explain trainjob.spec.trainer on your version. Check: kubectl -n ai get trainjob forecast-v1 ends Complete and the log prints a MAPE figure.

6. The fine-tune with Unsloth

The copilot’s job includes extracting fields from invoice text. A few hundred labelled examples, generated from the seeded invoices, are enough to teach a small model the output format.

from unsloth import FastLanguageModel
from trl import SFTTrainer, SFTConfig
from datasets import load_dataset

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="Qwen/Qwen3-0.6B", max_seq_length=2048, load_in_4bit=True)   # QLoRA: 4-bit base
model = FastLanguageModel.get_peft_model(model, r=16, lora_alpha=16,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"])
ds = load_dataset("json", data_files="invoice_extraction.jsonl", split="train")
trainer = SFTTrainer(model=model, tokenizer=tokenizer, train_dataset=ds,
    args=SFTConfig(output_dir="out", per_device_train_batch_size=4, num_train_epochs=2,
                   learning_rate=2e-4, save_steps=50, report_to="none"))
trainer.train()
model.save_pretrained("invoice-adapter")        # the small adapter only

Run it as a Kubernetes Job with nvidia.com/gpu: 1, the GPU toleration and a mounted volume for checkpoints (save_steps is what makes a spot interruption cheap: the job restarts from the last checkpoint). The training data is synthetic; do not put real invoices in a lab run. Check: the Job completes and invoice-adapter/ holds a small adapter file, far smaller than the base model.

7. The DeepEval gate

A gate is code that says yes or no. For the language model it scores a set of reviewed examples; for the forecast it is a plain threshold on the error, because a custom number does not need an LLM judge.

# gate_llm.py: run with `deepeval test run gate_llm.py`
from deepeval import assert_test
from deepeval.test_case import LLMTestCase
from deepeval.metrics import GEval
from deepeval.test_case import LLMTestCaseParams

extraction = GEval(
    name="Invoice extraction correctness",
    criteria="The output is valid JSON with the same supplier, date and total as the expected output.",
    evaluation_params=[LLMTestCaseParams.ACTUAL_OUTPUT, LLMTestCaseParams.EXPECTED_OUTPUT],
    threshold=0.8,
)

def test_cases():
    for case in load_golden():                         # reviewed examples, kept in Git
        out = call_candidate(case["input"])
        assert_test(LLMTestCase(input=case["input"], actual_output=out, expected_output=case["expected"]), [extraction])
# gate_forecast.py
import json, sys
mape = json.load(open("/out/metrics.json"))["mape_last4w"]
sys.exit(0 if mape <= 0.20 else 1)                     # 20% is an example threshold; set yours from the baseline

DeepEval’s LLM-judged metrics need a judge model; point them at a model you control, or a hosted one with the cost in mind, and keep the golden set small and reviewed. Check: a deliberately broken adapter (train for one step) fails the gate and a good one passes. If you cannot make the gate fail on a bad model, the gate does nothing.

8. One Kubeflow Pipelines run

The pipeline connects the steps so a model is never registered by hand: it runs training, evaluates, and registers only on a pass.

from kfp import dsl, compiler

@dsl.component(base_image="<your-registry>/erp-ml:<tag>")
def train_forecast(out: dsl.Output[dsl.Model]): ...

@dsl.component(base_image="<your-registry>/erp-ml:<tag>")
def gate(model: dsl.Input[dsl.Model]) -> str:
    ...        # returns "pass" or raises, which fails the run

@dsl.component(base_image="<your-registry>/erp-ml:<tag>")
def register(model: dsl.Input[dsl.Model], repo: str): ...   # pushes to MatrixHub

@dsl.pipeline(name="erp-model-path")
def erp_model_path():
    t = train_forecast()
    g = gate(model=t.outputs["out"])
    register(model=t.outputs["out"], repo="erp/forecast").after(g)

compiler.Compiler().compile(erp_model_path, "erp_model_path.yaml")

The fine-tune step has the same shape and uses the GPU toleration; component resource requests are set on the task (.set_accelerator_type and .set_accelerator_limit, which are SDK calls to confirm on your kfp version). Install Kubeflow Pipelines as the brief describes and upload the YAML. Check: one run shows all steps green, the model appears in MatrixHub, and a second run with a bad model stops at the gate without registering anything.

9. Troubleshooting

Symptom Likely cause Fix
GPU pod Pending, no node Spot unavailable in the listed types, or the limit reached Allow on-demand in the NodePool; check the NodeClaim events
Node up, pod says no GPU Device plugin missing or not tolerating the taint Install it with the GPU toleration; check kubectl describe node for nvidia.com/gpu
Node never Ready Image lacks the NVIDIA driver Use the accelerated AMI for the GPU node class
Spot node interrupted mid-job Normal at the interruption rates above Resume from the last checkpoint; keep the Job’s restart policy on failure
KServe pod stays at 0 minReplicas: 0 without a scale-from-zero path Use minReplicas: 1 for testing
Model loads from the internet HF_ENDPOINT not set on the runtime Set it on the container and check the log line
Runtime rejects arguments Argument names differ by version Compare with the runtime’s --help
TrainJob stuck Runtime name or image not found kubectl get clustertrainingruntimes; check pull secrets
Unsloth import error CUDA and PyTorch versions mismatch Use the installation guidance for your CUDA version
Out of memory in fine-tune Sequence length or batch too high Lower max_seq_length or batch size
DeepEval cannot score No judge model configured Set the model and key as a Secret
Pipeline registers a bad model Gate failure does not stop the run The gate must raise or exit non-zero, and register must depend on it

Cost note

The GPU figures in the decision table are from a third-party tracker for ap-south-1, read on 4 December 2026, and are a snapshot. An A10G (g5.xlarge) at $1.208 an hour on demand costs about $7.25 for six hours; at the spot prices seen it is roughly $2.5 to $3.7. The EC2 CPU nodes for MatrixHub, Kubeflow and the fallback model come from the general pool; EBS and data-transfer prices were not read. Storage is a quiet cost: model files and checkpoints sit on volumes until you delete them. Scale the GPU pool to zero by deleting the workloads, not only by waiting for consolidation, and check kubectl get nodeclaims at the end of every session.

Cleanup

kubectl -n ai delete inferenceservice --all
kubectl -n ai delete trainjob --all && kubectl -n ai delete job --all
helm -n kubeflow uninstall <kubeflow-pipelines-release>
kubectl delete nodepool gpu-spot            # Karpenter drains and terminates the GPU nodes
helm -n matrixhub uninstall matrixhub && kubectl -n matrixhub delete pvc --all
kubectl get nodeclaims                       # expect no GPU nodes

Delete the model volumes only when you are sure you will not need the adapter; Part 4 uses the served endpoint, and the adapter in MatrixHub is how you get it back.

Design notes and version checks

  • Nothing here was run on AWS or on a GPU. The manifests follow the briefs on this site and the projects’ documentation; the likeliest differences are the KServe Hugging Face runtime arguments, Trainer’s trainer fields, the Kubeflow Pipelines accelerator calls and the accelerated AMI selection.
  • Prices. The GPU and CPU prices are third-party and a snapshot. Spot prices moved between two snapshots (g5.xlarge showed both $0.4215 and $0.6102), and the interruption bands are as the tracker reported them.
  • Models and licences. The example base model is a placeholder. Choose one whose licence suits a commercial ERP, and record it in Git. Fine-tuning on synthetic data teaches format, not facts.
  • The gate is only as good as its examples. A small reviewed golden set catches a broken format; it does not prove the copilot answers correctly on real documents. Part 4 adds tests on retrieval answers.
  • LLM-judged metrics have their own cost and noise. Use a deterministic check where one exists, as for the forecast.
  • Kubeflow Pipelines label. It is a component of the graduated Kubeflow project; the Landscape lists it without a CNCF label, so its brief carries NON CNCF.
  • Open items from the Overview (the Kuadrant provider and Apache AGE on RDS) are not touched here; Parts 4 and 5 decide them.

Setup checklist

  • 1. Decision: done when the GPU or CPU choice and the prices read are written into docs/ with today’s date.
  • 2. Pools: done when a GPU pod gets a node, runs nvidia-smi, and the node leaves after the pod is deleted.
  • 3. Registry: done when MatrixHub caches the base model and a second download is a cache hit.
  • 4. Serving: done when the InferenceService is Ready, answers a chat request, and loads weights from MatrixHub.
  • 5. Forecast: done when the TrainJob completes and logs a MAPE figure.
  • 6. Fine-tune: done when the Unsloth Job completes and writes an adapter.
  • 7. Gate: done when a bad model fails and a good model passes.
  • 8. Pipeline: done when one run registers a passing model and another run stops before registering a failing one.
  • 9. Cleanup of GPU nodes: done when kubectl get nodeclaims shows no GPU node after the session.

Tools used

MatrixHub, vLLM, KServe, Kubeflow Trainer, Kubeflow Pipelines, Unsloth, DeepEval, Karpenter, ClickHouse, Project Jupyter (for exploring the forecast data).

What comes next

Part 4 builds the copilot on this path: Docling reads documents into pgvector and Apache AGE, a LangGraph agent on kagent calls MCP tools, NeMo Guardrails and agentgateway protect it, and Langfuse traces every question. Back to the Overview.

Spotted something wrong or out of date?Suggest a correction. I review every suggestion before changing the page.