Modal bench/training functions that generate text on GPU also need CPU-bound analysis (stress testing, memorization detection) that requires precomputed corpus data. The corpus data is mounted read-only in the Modal image. Building indexes (n-gram sets, sentence statistics) inside the GPU function adds ~10s startup overhead but enables richer per-sample diagnostics without a second pass. The trap: making these indexes required parameters blocks the function when they're unavailable, or silently skips scoring when they fail.
Precompute corpus-derived indexes (sentence stats, n-gram source index) after corpus loading but before the candidate loop, wrapped in try/except with WARNING logs. Pass them as optional parameters (default None) to the scoring function. Inside the scoring loop, guard each analysis with if data is not None and wrap in try/except so a single sample's analysis failure doesn't abort the batch. The indexes are informational (no gating, no score contribution) — they enrich the output without changing the scoring contract. This pattern (precompute-once, pass-optional, fail-graceful) works for any ancillary analysis added to an existing scored pipeline.