LuChengTHU / dpm-solver

Official code for "DPM-Solver: A Fast ODE Solver for Diffusion Probabilistic Model Sampling in Around 10 Steps" (Neurips 2022 Oral)
MIT License
1.57k stars 120 forks source link

Question regarding likelihood evaluation #35

Open mickelliu opened 1 year ago

mickelliu commented 1 year ago

Hi Cheng,

Congrads on your impactful works.

I'm pretty new to this field and want to know if evaluating the negative log-likelihood $(-\log P_\theta ( x_0 | c ) )$ really makes sense to you. I want to compute the exact likelihood of an image being sampled from the denoising process parameterized by $\theta$. I was wondering if this is possible with an ODE solver like DPM-solver.

Thanks.

LuChengTHU commented 1 year ago

Hi @mickelliu , what is the dimension of your image? And what do you want to do with your likelihood?

DPM-Solver can also improve the computation speed for evaluating likelihood, but it cannot ensure it is a valid likelihood if the solver does not converge.

mickelliu commented 1 year ago

Thanks for you reply!

Hi @mickelliu , what is the dimension of your image?

I'm testing on 512x512 images but I am running stable diffusion v-1-5 which has a latent dimension of 64x64.

And what do you want to do with your likelihood?

I want to estimate the likelihood of generating a bad sample so I can try to minimize it. Or letting people to select between two samples, and award the model for generating good samples relative to the preference score. I'm not sure if there's any other way to do it

DPM-Solver can also improve the computation speed for evaluating likelihood, but it cannot ensure it is a valid likelihood if the solver does not converge.

I actually have very little idea about how to evaluate exact likelihood using the DPM-solver. And I think this paper by Song Yang (Eq. 39) is the only paper that explicitly tells us how to compute the exact log-likehood out of every diffusion papers i have read.

Best,

Mickel

mickelliu commented 1 year ago

Is it easy to derive a differential form (with dx and dt) of the DPM-solver's equation?

LuChengTHU commented 1 year ago

Hi @mickelliu ,

I think in such case, you can easily combine DPM-Solver with likelihood solver. The basic idea is that the likelihood of diffusion ODEs can be solved by a D+1 dimension ODE as following:

dx / dt = f(x, t) (it is the diffusion ODE that dpm-solver solves) d logp / dt = -tr(\nabla f(x,t))

and then (x, logp(x)) is a D+1 dim variable, which follows the above ODE. (In fact, such theory is firstly proposed by "Neural Ordinary Differential Equations".

You can use dpm-solver to approximate the solution, but you need to write another update rule for approximate d logp / dt.

Nevertheless, I will add a feature to dpm-solver to support likelihood computation :)

mickelliu commented 1 year ago

Nevertheless, I will add a feature to dpm-solver to support likelihood computation

Thanks for your response, and apologize for the delayed reply.

This would be a very nice addition, but I am curious to know how to do it efficiently. To my knowledge, I think you would have to compute or at least approximate the second-order gradient (d_nabla/d_theta_unet) anyway, and this could be extremely inefficient.