Skip to content
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

Is it feasible to directly calculate the DSM loss function without scorenet estimation? #13

Open
AlyssaYoung opened this issue Mar 13, 2024 · 0 comments

Comments

@AlyssaYoung
Copy link

I saw an implementation of the formula form. I wonder whether it is feasible to directly calculate the loss via torch.autograd operations, if I define an energy function, like the logSumExp function in this paper 'Your classifier is secretly an energy based model and you should treat it like one'.

ncsn/losses/dsm.py

Lines 5 to 15 in 7f27f4a

def dsm(energy_net, samples, sigma=1):
samples.requires_grad_(True)
vector = torch.randn_like(samples) * sigma
perturbed_inputs = samples + vector
logp = -energy_net(perturbed_inputs)
dlogp = sigma ** 2 * autograd.grad(logp.sum(), perturbed_inputs, create_graph=True)[0]
kernel = vector
loss = torch.norm(dlogp + kernel, dim=-1) ** 2
loss = loss.mean() / 2.
return loss

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

No branches or pull requests

1 participant