Skip to content

Conversation

zuhengxu
Copy link
Member

@zuhengxu zuhengxu commented Jun 20, 2025

This PR aims to get a complete normalizing flow example/test on GPU (see #49).

After #11, we now support batch-wise training/inference for some flows (e.g., RealNVP), which is crucial for getting performance gain on GPU. PR #25 then got the cuda sampling for the reference dist working. The only missing piece is to ensure logpdf computation for both the reference and flow to work, and to ensure AD working.

I've identified some issue here:

using CUDA
const NF = NormalizingFlows
rng_g = CUDA.default_rng() # use GPU RNG if available

CUDA.allowscalar(true)
n_samples = 100
q0 = MvNormal(CUDA.zeros(2), cu([1f0 0f0; 0f0 1f0]))
# gpu sample from the reference
xs = NF._device_specific_rand(rng_g, q0, n_samples) # working properly

# Although xs is a cuda array, logpdf(q0, xs) returns a cpu array
logpdf(q0, xs) # returns a CPU array

I think a quick solution is to define a NF._device_specific_logpdf(...).

@zuhengxu zuhengxu marked this pull request as draft June 20, 2025 22:58
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