Skip to content

More CUDA compatibility #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

More CUDA compatibility #52

wants to merge 1 commit into from

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