Skip to content

Conversation

kevinchern
Copy link
Collaborator

  • Fix the autograd computation when hidden units are present. The gradients were computed incorrectly because the linear and quadratic parameters were used to marginalize hidden units without detaching from the computation graph. The fix is to detach them when computing effective fields.
  • Add a test to check the gradient is as expected.

Thanks @mhramani for flagging the lack of tests, which lead to discovering this bug!

Copy link
Contributor

@mhramani mhramani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, made a minor comment

# Compute unnormalized density
# h1v1 + h2v2 + h3v3 + J23v2v3 + J12v1v2 + J13v1v3
q_plus = torch.exp(-torch.tensor(0.2 + 0.2 - 0.3 - 0.6 + 0.2 - 0.3))
q_minus = torch.exp(-torch.tensor(-0.2 - 0.2 + 0.3 - 0.6 + 0.2 - 0.3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is not sorted according to h1v1 + h2v2 + h3v3 + J23v2v3 + J12v1v2 + J13v1v3:
I think it should be
q_plus = torch.exp(-torch.tensor(0.2 + 0.2 - 0.3 - 0.6 + 0.2 - 0.3))
q_minus = torch.exp(-torch.tensor(-0.2 + 0.2 - 0.3 - 0.6 - 0.2 + 0.3))
this won't change the results

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch, thanks!

@mhramani
Copy link
Contributor

@kevinchern this is a very important and time-sensitive PR, I already reviewed approved, could you please merge. @thisac Please have a look once you get a chance.

@kevinchern
Copy link
Collaborator Author

Thanks @mhramani

@kevinchern kevinchern merged commit 5d5f380 into dwavesystems:main Sep 24, 2025
15 checks passed
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.

2 participants