Skip to content

Conversation

@arrjon
Copy link
Member

@arrjon arrjon commented Sep 8, 2025

This pull request introduces compositional sampling support to the BayesFlow framework, enabling diffusion models to handle multiple compositional conditions efficiently. The main changes span the continuous approximator, diffusion model, and inference network modules, adding new methods and refactoring existing ones to support compositional structures in sampling, inference, and diffusion processes.

Larger changes include:

  • Added a new compositional_sample method to ContinuousApproximator, which generates samples with compositional structure and handles flattening, reshaping, and prior score computation for multiple compositional conditions. Supporting internal method _compositional_sample was also introduced.
  • In DiffusionModel, implemented compositional diffusion support including:
    • New compositional_bridge and compositional_velocity methods for compositional score calculation.
    • _compute_individual_scores helper for handling multiple compositional conditions.
    • _inverse_compositional method for inverse compositional diffusion sampling.

The idea is that the workflow now has the method compositional_sample, which expects conditions in the form (n_datasets, n_conditions, ...). Then we can perform compositional sampling with diffusion models.
compositional_sample allows to set a mini_batch_size for memory efficient computation of the compositional score, which does not work with jax backend however, as jax does not like stochasticity in its integrators which cannot be precomputed. We could support here only fixed step sizes though?

To compute the compositional score we need access to the score of the prior. Here we need to handle the adapter carefully so that we compute the correct score. In the current draft, I am not sure I computed the prior score correctly. Some ideas would be great, currently it fails for jax because the adpater is converting stuff to numpy back and forth, but for torch it is working.

@arrjon arrjon self-assigned this Sep 8, 2025
@arrjon arrjon requested a review from stefanradev93 September 8, 2025 15:13
@codecov
Copy link

codecov bot commented Sep 8, 2025

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.

4 participants