← Experiments

Code view

Many small jobs on one GPU

The locks, branches and pins that decide how many GPU jobs run at once: the Argo semaphore, the cached and cache-free branches, the template pin, and the quota and priorities that park batch work while the 7B is up.

The series changed only a few lines of code: one number in a ConfigMap, one branch in a workflow template, one commit pin. The excerpts are from two private repos, trimmed to the code; comments are left out, and line numbers are the files' own. Some values have moved on since the series. Where they have, the prose says so.

01The test job

Every run used the lab's smallest GPU job. It does a 4096×4096 matmul and a tiny in-process language model, each checked against a float64 CPU reference, while a sampler watches the card. For the concurrency tests it then holds its allocation idle for hold_s seconds, so that jobs overlap.

studies/job_lifecycle/cell.py
    with open_sampler(run, hz=cfg.hz, name="gpu") as sampler:        run.heartbeat(0.0, "opened")        t0 = clock()        matmul = payload.matmul(cfg)        matmul_s = clock() - t0        run.heartbeat(0.4, "matmul done")        t0 = clock()        tiny_lm = payload.tiny_lm(cfg)        tiny_lm_s = clock() - t0        run.heartbeat(0.8, "tiny LM done")        if cfg.hold_s > 0:            run.heartbeat(0.9, f"holding the allocation {cfg.hold_s:g}s (cancel drill)")            sleep(cfg.hold_s)

02One at a time, by a lock

Kueue's quota could already admit several small jobs at once. What kept them to one was an Argo semaphore whose capacity is a single string in a ConfigMap. At the start of the series it read "1". Each hand-off of that lock took most of the 16 s between 5-second jobs.

workflows/gpu-semaphore-configmap.yaml
apiVersion: v1kind: ConfigMapmetadata:  name: gpu-semaphore  namespace: workflowsdata:  gpu: "7"

03Size the lock to the queue

The general GPU queue has eight shares, four held by always-on services. Its 12 Gi memory quota fits four 2 Gi jobs. So the lock went from one to four, and Kueue's quota decides admission below that ceiling. The cost: a benchmark holding the lock no longer has the card to itself.

It reads seven now. A second card joined the cluster after the series and brought three more slots.

workflows/gpu-semaphore-configmap.yaml
  gpu: "7"

04The cached and cache-free branches

A GPU job either mounts the shared model store or doesn't. Each kind gets its own branch of the cell template, chosen by when clauses on the job's inputs. A third branch places a job on a named card, and it is always cache-free.

workflows/mlr-cell.yaml
      steps:        - - name: gpu-cell-cached            when: '"{{inputs.parameters.gpu}}" == "true" && "{{inputs.parameters.hf-cache}}" != "false" && "{{inputs.parameters.gpu-node}}" == ""'            template: gpu-cell-cached          - name: gpu-cell-uncached            when: '"{{inputs.parameters.gpu}}" == "true" && "{{inputs.parameters.hf-cache}}" == "false" && "{{inputs.parameters.gpu-node}}" == ""'            template: gpu-cell-uncached          - name: gpu-cell-placed            when: '"{{inputs.parameters.gpu}}" == "true" && "{{inputs.parameters.gpu-node}}" != ""'            template: gpu-cell-placed

05A cache lock with room for one

At first, the cached branch also took a second lock with room for one, so the store would never have two writers. In the first live check, three jobs ran together and the second cache job waited. The jobs run as an unprivileged user and the store is read-only to them, so that lock was later removed. Now the only difference between the branches is the mount.

workflows/mlr-cell.yaml
                - name: pvc-name                  value: workflows-hf-cache                - name: pvc-mount-path                  value: /cache/hf

06The pin that hid the memory declarations

ml_research owns its workflow templates, but the cluster runs them at a pinned commit, not at HEAD. The pin predated the change that let a job declare its GPU memory. So every job counted as the 1 GiB default, whatever it asked for. Moving the pin fixed it, and a job declaring 11,000 MiB then waited for room.

apps/ml-research-workflows.yaml
    targetRevision: 2f15a2a71ecb2881179842056298123dfde730d9

07While the 7B is up, batch waits

The card's memory quota is lent in one piece: 12,400 MiB to the language-model queue. With the 7B awake, the always-on services take most of what is left, and a 1,024 MiB batch job doesn't fit.

scheduling/kueue/clusterqueue.yaml
            - name: "homelab.dev/vram-mib"              nominalQuota: "15888"              lendingLimit: "12400"            - name: "homelab.dev/vram-mib"              nominalQuota: "0"              borrowingLimit: "12400"

08Batch never preempts

Training outranks the 7B and would take its share back. Batch sits at the bottom, 500 against the 7B's 5000, with preemptionPolicy: Never. So it waits. Two jobs waited 30 minutes without failing, and were admitted within seven seconds of the 7B scaling down.

scheduling/priorityclasses.yaml
value: 9000value: 5000value: 500preemptionPolicy: Never