Skip to content

perplexity: opt-in worker cap and chunk-range shards for KLD - #450

Draft
khosravipasha wants to merge 1 commit into
prismfrom
speedup/kld-workers
Draft

khosravipasha wants to merge 1 commit into
prismfrom
speedup/kld-workers

Conversation

@khosravipasha

@khosravipasha khosravipasha commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Two opt-in switches for llama-perplexity. With neither set, behaviour is unchanged.

What

  • LLAMA_PERPLEXITY_THREADS=<n> caps the worker threads that compute the per-token log-softmax and KL work. Today every chunk starts one thread per hardware thread (223 on a 224-thread node), and they all queue on one mutex per token. On a busy node that stalls badly. The per-token math is unchanged; only which thread handles which token changes.
  • LLAMA_PERPLEXITY_SHARD=k/K makes a run evaluate one contiguous range of chunks, cut on whole n_seq batches, so every decode batch is the same one the unsharded run builds.
    • With --kl-divergence-base: every shard writes its chunks at their own offset in one logits file, without truncating it. After all K shards finish, the file is byte-for-byte the unsharded one. Delete any stale file first.
    • With --kl-divergence: LLAMA_KLD_DUMP=<file> saves a shard's sums and per-token values. Then LLAMA_KLD_MERGE=<dump0>,<dump1>,... prints the whole run's final row and summary block from the dumps, with no model loaded.
  • Refactor: the summary and per-chunk row printing moved into functions shared by the normal path and the merge. The statistics code is unchanged.

Exactness (H200 node, Nov 22)

  • Reference file: the 2B logits file written by 8 shards is identical to the unsharded file (cmp, 73 GB).
  • Merged comparison: the merged 2B comparison summary is identical to the unsharded run, and certify_kld.py passes with the same values.
  • All sizes: in the packing pipeline, all 12 comparisons (4 sizes × 3 2-bit files) reproduce the previous runs' KLD numbers exactly.

Speed: the four KLD runs per pack, 8 × H200, 8 shards

Size Before (one GPU, one after another) After (reference, then 3 comparisons at once)
2B 256 s 56 s (25 + 31)
4B 300 s 63 s (26 + 37)
9B 333 s 68 s (30 + 38)
27B 541 s 94 s (34 + 60)
  • Worker cap alone: one full 2B comparison took 65 s with the default threads and 48 s capped at 32, on a node that was also running other jobs.
  • Default use: the packing driver uses this through KLD_SHARDS=K (packing draft PR: PrismML-Eng/packing#212).

…s for KLD

- LLAMA_PERPLEXITY_THREADS=<n> caps the per-chunk worker threads (default unchanged: every
  hardware thread). Same per-token math; far less lock contention on a busy node.
- LLAMA_PERPLEXITY_SHARD=k/K evaluates one contiguous run of chunks, cut on whole n_seq batches.
  With --kl-divergence-base all shards write into one logits file at their own offsets (byte-for-
  byte the unsharded file); with --kl-divergence, LLAMA_KLD_DUMP saves a shard's sums and
  per-token values and LLAMA_KLD_MERGE=<dumps> prints the whole run's summary without a model.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant