Skip to content

cluster: faster blockmodel sweeps - #33

Merged
YPARK merged 1 commit into
mainfrom
speed
Oct 18, 2026
Merged

YPARK merged 1 commit into
mainfrom
speed

Conversation

@YPARK

@YPARK YPARK commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

What

Speeds up both blockmodel presets without changing the moves.

  • Release profile: fat LTO, one codegen unit.
  • Finite strength (link preset):
    • The Gibbs relabel loops sites outer and blocks inner over contiguous memory.
    • The ln Gamma and prior ln Beta terms are cached per (site, block), and the caches are kept current on every update.
    • Whole-read sites multiply rising-factorial ratios into a running product per block, kept as a mantissa and a power of two, so each block takes one log instead of one per term.
  • Infinite strength (blocks preset):
    • exp(-shift), exp(-level) and exp(-mu) are cached, so ln sigmoid becomes one log of a product per block.
    • Extreme logits fall back to ln_1p, so the product cannot overflow.
  • Fast ln Gamma: an f32 approximation below 16, and the library at 16 and above. It is used at sites with fractional or large counts.
    • The target shifts slightly, by about 1e-3 per term.
    • The moves leave that target invariant exactly: the exactness tests' reference densities use the same functions.
  • Memory estimate: counts the new caches.

Tests

  • Golden test: fixed-seed chains are pinned bit for bit, recorded before any change. Every step was checked against it, and the changes in its recorded values are explained in the commit. It runs on Apple silicon only, because it depends on the platform's maths library.
  • Exactness: the existing total-variation, swap-ratio, log-joint-definition and conditional tests all pass. A weighted fixture now exercises the fast-ln-Gamma sites.
  • New checks, each with a mutation check that makes it fail:
    • the caches match the live reads, shifts and levels;
    • a long link's predictive equals its sites summed;
    • the mantissa splits rebuild exactly;
    • extreme logits score right;
    • ln Gamma differences stay near the library's.

- Release profile with fat LTO and one codegen unit.
- Finite strength: the relabel runs sites outer and blocks inner over
  contiguous memory, caches the ln Gamma and prior ln Beta terms per
  (site, block), and takes one log per block for whole-read sites through
  a running rising-factorial product kept as mantissa and power of two.
- Infinite strength: exp(-shift), exp(-level) and exp(-mu) are cached, so
  ln sigmoid is one log of a product per block; extreme logits fall back
  to ln_1p so the product cannot overflow.
- An f32 fast ln Gamma (exact library above 16) at sites with fractional
  or large counts. The target shifts slightly (about 1e-3 per term) and
  the moves leave that target invariant exactly; the exactness tests use
  the same functions.
- The memory estimate counts the new caches.
- A golden test pins the chains bit for bit on fixed seeds (Apple silicon
  only, since it depends on the platform's maths library).
@YPARK
YPARK merged commit 5d6e042 into main Oct 18, 2026
6 checks passed
@YPARK
YPARK deleted the speed branch October 18, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant