
HPC & GPU Workstation Deployment: VRAM Sizing, Containers, and Long-Transcript Chunking
Source:vignettes/hpc-gpu-deployment.Rmd
hpc-gpu-deployment.RmdOverview
Deploying open-weights LLMs (Llama, Qwen,
Gemma, Mistral) on departmental GPU
workstations or university HPC Slurm nodes introduces practical
engineering challenges that go beyond calling a local HTTP port:
- GPU Out-of-Memory (OOM) Failures: Selecting a quantization level and context window that exceeds available VRAM.
- Strict Air-Gapping: Ensuring Docker and Apptainer containers cannot make outbound network calls, download telemetry, or escape mounted model directories via symlinks.
- Long Qualitative Transcripts: Therapy transcripts and semi-structured interviews frequently exceed 4,096–8,192 tokens and require deterministic overlapping chunking prior to extraction.
- Walltime Preemption & Schema Drift: Resuming 50,000-row batches cleanly after Slurm preemption while blocking accidental schema or prompt mismatches.
1. Right-Sizing Workstation & HPC GPUs
(estimate_vram_requirements())
Estimate total GPU memory (model weights + KV cache + runtime overhead) across quantizations and context windows before requesting GPU allocations:
# 8B model in Q4_K_M with 8k context for a single lab workstation GPU
vram_8b <- estimate_vram_requirements(
params_b = 8,
quantization = "Q4_K_M",
context_length = 8192L,
batch_size = 2L
)
vram_8b
#> <airgap_vram_estimate>
#> Model: 8B parameters (Q4_K_M, 32 layers)
#> Context / Batch: 8192 tokens x 2 (KV: FP16)
#> Weights VRAM: 4.47 GB
#> KV-Cache VRAM: 2.00 GB
#> Runtime Overhead: 1.35 GB
#> Total Estimated: 7.82 GB
#> Recommended Tier: 8 GB (Workstation RTX 4060 / 16 GB Unified)
# Compare 70B Q4_K_M vs 14B Q8_0 for an HPC A100-80GB / L40S node
estimate_vram_requirements(14, quantization = "Q8_0", context_length = 8192L, batch_size = 4L)
#> <airgap_vram_estimate>
#> Model: 14B parameters (Q8_0, 40 layers)
#> Context / Batch: 8192 tokens x 4 (KV: FP16)
#> Weights VRAM: 13.95 GB
#> KV-Cache VRAM: 5.00 GB
#> Runtime Overhead: 1.65 GB
#> Total Estimated: 20.60 GB
#> Recommended Tier: 24 GB (RTX 3090/4090 / A10G / L4)
estimate_vram_requirements(70, quantization = "Q4_K_M", context_length = 8192L, batch_size = 2L)
#> <airgap_vram_estimate>
#> Model: 70B parameters (Q4_K_M, 80 layers)
#> Context / Batch: 8192 tokens x 2 (KV: FP16)
#> Weights VRAM: 39.12 GB
#> KV-Cache VRAM: 5.00 GB
#> Runtime Overhead: 1.35 GB
#> Total Estimated: 45.47 GB
#> Recommended Tier: 48 GB (L40S / A6000)Inspect GPU tier headroom directly from $fits_tiers:
vram_8b$fits_tiers
#> # A tibble: 7 × 4
#> gpu_tier vram_gb fits headroom_gb
#> <chr> <dbl> <lgl> <dbl>
#> 1 8 GB (Workstation RTX 4060 / 16 GB Unified) 8 TRUE 0.18
#> 2 16 GB (RTX 4080 / A4000 / V100-16GB) 16 TRUE 8.18
#> 3 24 GB (RTX 3090/4090 / A10G / L4) 24 TRUE 16.2
#> 4 40 GB (A100-40GB) 40 TRUE 32.2
#> 5 48 GB (L40S / A6000) 48 TRUE 40.2
#> 6 80 GB (A100-80GB / H100-80GB) 80 TRUE 72.2
#> 7 160 GB (2x A100/H100 80GB) 160 TRUE 152.2. Hardened --network none Docker & HPC Apptainer
Configurations
Pin both the container image digest (sha256:...) and
local model weight digest (verify_model_digest()) to
guarantee reproducibility and tamper resistance across nodes:
work_dir <- tempfile("airgap_hpc_vignette_")
dir.create(work_dir)
weights_file <- file.path(work_dir, "qwen2.5-14b-instruct-q4_K_M.gguf")
writeBin(charToRaw("synthetic-local-gguf-weights-for-vignette"), weights_file)
# Verify streaming SHA-256 (blocks symlinks & path escapes by default)
w_ver <- verify_model_digest(weights_file, root_dir = work_dir)
w_ver
#> <airgap_digest_verification> [COMPUTED]
#> Path: /tmp/RtmpR4VZNZ/airgap_hpc_vignette_1d4c39b63411/qwen2.5-14b-instruct-q4_K_M.gguf
#> Size bytes: 41
#> Actual: sha256:3dd70bdd5679d2af58a4c576e94e76975aca7a687da3e5f0b6886880579b3915
spec <- airgap_container_spec(
backend = "vllm",
image = "vllm/vllm-openai",
image_digest = paste0("sha256:", strrep("e", 64)),
model_dir = work_dir,
model_file = basename(weights_file),
model_digest = w_ver$actual_digest,
gpu = "nvidia",
gpu_devices = "device=0",
memory_limit = "48g",
shm_size = "8g",
user = "1000:1000"
)
# Emit Compose YAML (read-only rootfs, cap_drop ALL, offline telemetry flags)
cat(emit_docker_compose(spec))
#> # Generated by airgapllm 0.6.0
#> # Spec digest: sha256:2ae43c615c9be4d2ba99e7d0432ecc9abd4a739951df568469c7e96888005139
#> services:
#> airgap-vllm:
#> image: vllm/vllm-openai@sha256:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
#> read_only: yes
#> cap_drop:
#> - ALL
#> security_opt:
#> - no-new-privileges:true
#> tmpfs:
#> - /tmp:rw,noexec,nosuid,size=512m
#> - /run:rw,noexec,nosuid,size=64m
#> volumes:
#> - /tmp/RtmpR4VZNZ/airgap_hpc_vignette_1d4c39b63411:/models:ro
#> environment:
#> DO_NOT_TRACK: '1'
#> HF_DATASETS_OFFLINE: '1'
#> HF_HUB_OFFLINE: '1'
#> TRANSFORMERS_OFFLINE: '1'
#> command:
#> - --model
#> - /models/qwen2.5-14b-instruct-q4_K_M.gguf
#> - --host
#> - 127.0.0.1
#> - --port
#> - '8000'
#> - --disable-log-requests
#> restart: 'no'
#> user: 1000:1000
#> shm_size: 8g
#> mem_limit: 48g
#> deploy:
#> resources:
#> reservations:
#> devices:
#> - driver: nvidia
#> capabilities:
#> - gpu
#> device_ids:
#> - '0'
#> network_mode: noneGenerate the companion HPC Apptainer .def recipe with
--containall --no-home --net --network none --nv:
cat(emit_apptainer_def(spec))
#> # Generated by airgapllm 0.6.0
#> # Air-gapped HPC execution command:
#> # apptainer build airgapllm-vllm.sif airgapllm.def
#> # apptainer run --containall --no-home --net --network none --nv --bind '/tmp/RtmpR4VZNZ/airgap_hpc_vignette_1d4c39b63411:/models:ro' airgapllm-vllm.sif
#>
#> Bootstrap: docker
#> From: vllm/vllm-openai@sha256:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
#>
#> %labels
#> org.airgapllm.generator airgapllm-0.6.0
#> org.airgapllm.backend vllm
#> org.airgapllm.spec_digest sha256:2ae43c615c9be4d2ba99e7d0432ecc9abd4a739951df568469c7e96888005139
#> org.airgapllm.network_mode none
#> org.airgapllm.model_digest sha256:3dd70bdd5679d2af58a4c576e94e76975aca7a687da3e5f0b6886880579b3915
#>
#> %environment
#> export DO_NOT_TRACK='1'
#> export HF_DATASETS_OFFLINE='1'
#> export HF_HUB_OFFLINE='1'
#> export TRANSFORMERS_OFFLINE='1'
#>
#> %post
#> mkdir -p /models
#> chmod 755 /models || true
#>
#> %runscript
#> exec vllm serve '--model' '/models/qwen2.5-14b-instruct-q4_K_M.gguf' '--host' '127.0.0.1' '--port' '8000' '--disable-log-requests' "$@"Confirm container posture, weight integrity, endpoint loopback confinement, and absence of unbypassed outbound proxy variables before starting inference:
preflight_isolation_check(
spec = spec,
endpoint = "http://127.0.0.1:8000/v1",
model_path = weights_file
)
#> <airgap_preflight> [PASS]
#> Checked at: 2026-11-28T20:38:18Z
#> Endpoint: loopback
#> Record hash: sha256:cd28bab4d288ef963fc41f85aa0eb3427d0e7e1bcf5ac21e7476f26cb0c88b3c
#> [PASS] network_isolation: Container network_mode is 'none'.
#> [PASS] read_only_rootfs: Container root filesystem is read-only.
#> [PASS] capabilities_dropped: All Linux capabilities dropped (--cap-drop ALL).
#> [PASS] no_new_privileges: no-new-privileges security option enabled.
#> [PASS] image_digest_pinned: Image pinned to sha256:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.
#> [PASS] host_bind_loopback: Host bind interface restricted to loopback (127.0.0.1).
#> [PASS] container_env_isolation: Container environment preserves mandatory offline/loopback flags with no proxy overrides.
#> [PASS] endpoint_loopback_only: Verified canonical loopback host (127.0.0.1).
#> [PASS] model_digest_verified: Model weights verified against pinned SHA-256 (sha256:3dd70bdd5679d2af58a4c576e94e76975aca7a687da3e5f0b6886880579b3915).
#> [PASS] env_proxy_isolation: No outbound proxy environment variables detected.3. Deterministic Chunking for Long Clinical Transcripts
When transcripts exceed local context windows, split them
deterministically along paragraph or sentence boundaries using
chunk_clinical_texts() while retaining doc_id,
chunk_id, and exact character offsets for downstream
re-aggregation:
data("synthetic_notes", package = "airgapllm")
long_record <- synthetic_notes[synthetic_notes$note_id == "SYN_016", ]
chunks <- chunk_clinical_texts(
data = long_record,
text_col = "note_text",
id_col = "note_id",
max_chars = 340L,
overlap_chars = 50L,
split_on = "paragraph"
)
chunks[, c("doc_id", "chunk_id", "chunk_index", "n_chunks", "start_char", "end_char", "char_count")]
#> # A tibble: 3 × 7
#> doc_id chunk_id chunk_index n_chunks start_char end_char char_count
#> <chr> <chr> <int> <int> <int> <int> <int>
#> 1 SYN_016 SYN_016_chunk_001 1 3 1 251 251
#> 2 SYN_016 SYN_016_chunk_002 2 3 208 498 291
#> 3 SYN_016 SYN_016_chunk_003 3 3 452 715 264Run airgap_extract() directly over chunks
using id_col = "chunk_id" so every chunk is independently
PII-redacted, schema-validated, and checkpointed:
chunk_schema <- extraction_schema(
topic = schema_field("enum", values = c("sleep", "coping", "logistics", "other")),
crisis_flag = schema_field("logical")
)
ck_file <- file.path(work_dir, "chunks_checkpoint.jsonl")
chunk_res <- airgap_extract(
data = chunks,
text_col = "chunk_text",
schema = chunk_schema,
runtime = runtime_mock(seed = 77L),
id_col = "chunk_id",
checkpoint_path = ck_file,
container_spec = spec,
model_path = weights_file
)
chunk_res[, c("chunk_id", "topic", "crisis_flag", ".status")]
#> # A tibble: 3 × 4
#> chunk_id topic crisis_flag .status
#> <chr> <chr> <lgl> <chr>
#> 1 SYN_016_chunk_001 sleep TRUE ok
#> 2 SYN_016_chunk_002 sleep TRUE ok
#> 3 SYN_016_chunk_003 sleep FALSE ok4. Checkpoint Schema-Drift Guards & Offline Troubleshooting
If an analyst edits the extraction schema or prompt template
mid-study and accidentally points airgap_extract() at an
old checkpoint_path with resume = TRUE,
airgapllm refuses to silently mix incompatible schemas:
modified_schema <- extraction_schema(
topic = schema_field("enum", values = c("sleep", "coping", "logistics", "other")),
severity = schema_field("integer", min = 0L, max = 5L)
)
tryCatch(
airgap_extract(
data = chunks,
text_col = "chunk_text",
schema = modified_schema,
runtime = runtime_mock(seed = 77L),
id_col = "chunk_id",
checkpoint_path = ck_file,
resume = TRUE
),
airgap_checkpoint_error = function(e) {
message("Guardrail triggered: ", conditionMessage(e))
}
)
#> Guardrail triggered: Checkpoint schema mismatch: cannot resume into a different extraction
#> schema.
#> ✖ Checkpoint schema digest:
#> sha256:ccffa19b89f611e40fc94527c59158080dfa2c0d822a0ffba2d341ecbce83151
#> ✖ Current schema digest:
#> sha256:1bfa5c739d9a924fa3af797ed463d1c5383e3ae77c47a8cd4eebc5d23d5bf19f
#> ℹ Start a new `checkpoint_path` or pass `resume = FALSE` to overwrite.Offline Troubleshooting Checklist
-
Proxy Pre-Flight Failure
(
env_proxy_isolation): On institutional HPC login nodes that exportHTTP_PROXY/HTTPS_PROXY, either unset proxy variables inside your Slurm job script (unset HTTP_PROXY HTTPS_PROXY ALL_PROXY) or explicitly includeNO_PROXY=127.0.0.1,localhost. -
Legacy Clinical CSV Encoding Errors:
airgapllmautomatically normalizes Windows-1252 smart quotes and Latin-1 characters to valid UTF-8 prior to PII scanning and JSON serialization. -
Symlinked Scratch Directories:
verify_model_digest()blocks symlinks escapingmodel_dirby default (allow_symlinks = FALSE); store canonical weight files directly inside the bound model directory.