Serving a Video Captioner on a Tight GPU Budget, Then Searching It
System DesignModel answerLast updated
Design a memory- and compute-efficient serving stack for a multimodal video captioning model, then a fast search-and-watermark pipeline for advertisers over existing captions and embeddings.
Context
You are on the ML platform team of a large short-video app. A multimodal model accepts a video (sampled frames, with optional audio) and produces a text caption. Your job is to make it a dependable production service and then build a product feature on top of its output.
Assumptions:
- New uploads arrive continuously, and the existing catalog also has to be captioned (backfill).
- The GPU pool is limited and shared with other teams. VRAM per replica and total GPU-hours are hard caps, so you cannot just add machines.
- Videos range from a few seconds to many minutes, at varied resolutions.
- The catalog holds hundreds of millions to billions of videos, each with at least one caption and at least one embedding.
- Watermarking re-encodes or overlays media, so it costs far more than writing metadata.
Part A: Deploy the captioner within compute and VRAM limits
Design the modeling and serving system. Discuss:
- How you shrink the cost of the multimodal input.
- How you make the model fit in memory.
- How the serving path is organized (online, offline/batch, or hybrid).
- How outputs are stored and how the system is monitored.
Part B: Fast advertiser search and watermarking
Captions and embeddings already exist. A brand advertiser wants to find videos relevant to a query (text, an example creative, or both) and then watermark the matches. Design the pipeline so that both search and watermarking are fast at scale. Cover indexing, filtering and ranking, caching, the watermarking path, trade-offs and failure modes.
What to do first
State the clarifying questions you would ask (online vs. batch latency, caption format and languages, quality bar after compression, query types, watermark type, index freshness, brand-safety gating) and the assumptions you pick. Then give a structured design with justified trade-offs.
Hints
Hint 1
Treat cost as the primary constraint. For every choice, say what it saves (VRAM, FLOPs, GPU-hours) and what quality or complexity it costs.
Hint 2
For Part A, work through the pipeline in order: reduce what goes into the model (frames, resolution, audio), shrink the model (quantization, distillation), control runtime memory (KV cache, batching), then choose the serving mode.
Hint 3
For Part B, split search into cheap candidate generation and expensive re-ranking, and make the watermark step an asynchronous, idempotent job that only runs after matches are approved.
Hint 4
Mention versioning: a query embedding must be produced by the same model version as the index it searches.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Clarify and assume
I would ask: is captioning needed synchronously on upload, or can most of it be offline? What caption format (one short caption, or per-segment for long videos) and how many languages? How is quality measured, and what drop is acceptable after compression? For Part B: text-only or example-creative queries, interactive or campaign-batch use, visible or forensic watermark, and who owns brand-safety review?
My working assumptions: a hybrid latency model (priority online path, bulk offline path), one caption per segment, a measurable quality metric, interactive search with batch watermarking, and a visible overlay applied to a derivative.
Part A: Deploying the captioner
1. Reduce input cost
Visual tokens dominate cost, so cut them first.
- Frame sampling: sample at a low rate (for example 1 fps or fewer) and use scene-change or keyframe detection so static footage yields few frames. Cap frames per clip.
- Spatial downsampling: reduce resolution to the encoder's native size, and merge or pool visual tokens (for example a token-compression layer) before they reach the language model.
- Long videos: split into clips of fixed length, caption each, then optionally run a short summarization pass. This bounds memory per request and parallelizes well.
- Audio on demand: run the audio branch only when it is likely to add information (speech detected, or visual confidence is low). Skipping it for silent or music-only videos saves compute.
- Dedup: hash near-duplicate videos and reuse captions.
2. Fit the model in memory
| Lever | Saves | Cost |
|---|---|---|
| 8-bit or 4-bit weight quantization (AWQ/GPTQ style) | roughly 2x to 4x weight memory | small quality loss, needs eval, especially on rare content |
| KV-cache control: cap output length, use paged cache, quantize the cache | cache memory, which grows with batch and sequence | slightly more complex runtime |
| Tensor or pipeline parallelism | lets a large model span GPUs | communication overhead, fewer replicas per fleet |
| Distillation into a smaller student | permanent reduction in FLOPs and VRAM | training effort, a quality ceiling |
| Adapters (LoRA) over one shared base | many task or language variants without full copies | small per-request overhead |
My default order: quantize first (cheap, big win), then distill if the budget is still exceeded, and use parallelism only if the model cannot fit on one GPU after quantization. As a sanity check, a 7B model needs about 14 GB in fp16 but about 4 GB in 4-bit, leaving room for cache and batching on a shared GPU.
3. Serving architecture
A hybrid design fits the workload:
- Online path: for new uploads and priority content, with a per-video latency target. Small batches, strict queue timeouts, a smaller or more heavily quantized model if needed.
- Offline path: for backfill. Large batches, scheduled on idle GPU capacity, preemptible, sorted by length to reduce padding.
- Throughput techniques: continuous batching for the decoder, running the vision encoder in a separate stage so encode of one request overlaps with decode of another, and caching encoder outputs.
- Degradation: under load, lower the frame count, skip audio, or fall back to the distilled model, and mark the caption with the tier that produced it so it can be upgraded later.
4. Storage and monitoring
- Store captions and embeddings keyed by
(video_id, segment, model_version, config). Versioning enables rollback, A/B comparison and selective re-captioning. - Quality: a fixed golden set evaluated on every model or quantization change, plus sampled human review and automatic checks (empty output, language mismatch, repetition, hallucinated entities).
- Serving health: GPU utilization, VRAM headroom, OOM rate, queue time, p50/p95/p99 latency, tokens per second, cost per video, fallback rate.
- Roll out changes with canaries and compare against the previous version before full deployment.
Part B: Search and watermarking
1. Retrieval
- Query handling: embed text queries (or example creatives) with the same model version as the index. Cache query embeddings.
- Stage 1, candidate generation: an ANN index (HNSW for recall and latency in memory, or IVF-PQ when billions of vectors demand compression). Return a few hundred to a few thousand candidates.
- Hybrid search: combine semantic scores with a lexical (BM25) match over captions, and apply metadata prefilters (region, language, duration, policy status) inside the index query where possible, since post-filtering can leave too few results.
- Stage 2, re-ranking: a heavier cross-encoder or a combination of caption and embedding signals on the top candidates only.
- Segments: for long videos, index segments and aggregate to video level (max or top-k score), keeping the segment timestamp for the result.
- Multiple embedding types: keep separate indexes per type and fuse scores, rather than concatenating incompatible spaces.
2. Caching and sharding
- Cache results for repeated or popular queries with a short TTL, and cache query embeddings for longer.
- Shard by language and region to cut fan-out and fit data-residency needs; replicate hot shards.
- Freshness: stream new videos into a small real-time index and merge periodically into the large static one, querying both.
3. Watermarking at scale
- Matches go to an asynchronous job queue. Jobs are idempotent, keyed by
(video_id, campaign_id, watermark_version), so retries never duplicate work. - Brand-safety gate runs before any marking, so no compute is wasted on videos that will be rejected.
- Batch by campaign: pre-generate the overlay asset once, and group jobs to reuse decoders and GPU or hardware encoders.
- Where the use case allows, watermark a lower-resolution derivative or preview instead of re-encoding the original.
- Write outputs to object storage and serve through a CDN with access control so only the advertiser can fetch them.
- Autoscale workers on queue depth, with rate limits per advertiser to protect shared capacity.
Trade-offs and failure modes
- Freshness vs. cost: streaming updates cost more than periodic rebuilds. Use the two-tier index to get most of the benefit.
- Recall vs. latency: larger ANN search width raises recall but also latency. Tune against a measured recall target.
- Embedding version mismatch: querying an index with a different model version silently degrades results. Enforce version checks and dual-index during migrations.
- False positives: weak matches waste watermark compute and may embarrass the brand. Use a score threshold plus human approval for the final list.
- Segment-to-video mapping errors: duplicates or wrong timestamps. Deduplicate by video and keep segment metadata.
- Common mistakes: ignoring KV-cache memory, quantizing without re-evaluating quality, post-filtering ANN results, and running watermarking synchronously inside the search request.
Summary
Cut input tokens, quantize and distill to fit VRAM, run a hybrid online/offline serving path with a degradation plan, and version everything. For advertisers, use filtered ANN plus re-ranking, cache aggressively, and push watermarking into a gated, idempotent, batched asynchronous pipeline.