Skip to content

Two independent memory reductions for SWIFT on high-dimensional data.#91

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
cl/947706110
Open

Two independent memory reductions for SWIFT on high-dimensional data.#91
copybara-service[bot] wants to merge 1 commit into
mainfrom
cl/947706110

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Jul 14, 2026

Copy link
Copy Markdown

Two independent memory reductions for SWIFT on high-dimensional data.

  1. Memory-efficient marginal oracle for final estimation.

SWIFT's final MirrorDescent estimation hardcoded the HUGIN marginal oracle
(message_passing_stable), which materializes every junction-tree clique
belief simultaneously. On high-dimensional data with large maximal cliques
this drives peak memory to the sum of all clique beliefs (tens of GiB) and
is numerically unstable with -inf potentials (HUGIN uses belief subtraction).

Switch to message_passing_implicit with the einsum_materialized contraction:

  • Peak memory is bounded by the largest single clique super-factor rather
    than the sum of all beliefs.
  • Numerically stable: log-space add + logsumexp, no exp/log round-trip and
    no belief subtraction.
  • Fastest contraction on GPU.

Both oracles perform exact junction-tree inference, so estimated marginals
are identical up to floating-point error.

  1. Free precomputed candidate marginals after measurement.

The candidate marginals produced by from_projectable (plus the workload
intermediates) are only needed through query selection and measurement, but
they stayed live for the rest of call -- through estimation and the
column-by-column generation phase. On host-memory-constrained slices this
residual is enough to push generation over the host RAM limit. Free them
right after measurement so the peak during estimation and generation is
lower.

1. Memory-efficient marginal oracle for final estimation.

SWIFT's final MirrorDescent estimation hardcoded the HUGIN marginal oracle
(message_passing_stable), which materializes every junction-tree clique
belief simultaneously. On high-dimensional data with large maximal cliques
this drives peak memory to the sum of all clique beliefs (tens of GiB) and
is numerically unstable with -inf potentials (HUGIN uses belief subtraction).

Switch to message_passing_implicit with the einsum_materialized contraction:

- Peak memory is bounded by the largest single clique super-factor rather
  than the sum of all beliefs.
- Numerically stable: log-space add + logsumexp, no exp/log round-trip and
  no belief subtraction.
- Fastest contraction on GPU.

Both oracles perform exact junction-tree inference, so estimated marginals
are identical up to floating-point error.

2. Free precomputed candidate marginals after measurement.

The candidate marginals produced by from_projectable (plus the workload
intermediates) are only needed through query selection and measurement, but
they stayed live for the rest of __call__ -- through estimation and the
column-by-column generation phase. On host-memory-constrained slices this
residual is enough to push generation over the host RAM limit. Free them
right after measurement so the peak during estimation and generation is
lower.

PiperOrigin-RevId: 947706110
@copybara-service copybara-service Bot changed the title SWIFT's final MirrorDescent estimation hardcoded the HUGIN marginal oracle Two independent memory reductions for SWIFT on high-dimensional data. Jul 14, 2026
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.

0 participants