Bug: empty free variables in positive phase results in index error#37
Open
sugolov wants to merge 2 commits intoextropic-ai:mainfrom
Open
Bug: empty free variables in positive phase results in index error#37sugolov wants to merge 2 commits intoextropic-ai:mainfrom
sugolov wants to merge 2 commits intoextropic-ai:mainfrom
Conversation
lockwo
reviewed
Mar 13, 2026
|
|
||
|
|
||
| class TestEstimateKLGradFullyVisible(unittest.TestCase): | ||
| """Test that estimate_kl_grad works when all nodes are visible (no latent variables).""" |
Collaborator
There was a problem hiding this comment.
the parenthetical statement isn't needed
| """Test that estimate_kl_grad works when all nodes are visible (no latent variables).""" | ||
|
|
||
| def test_fully_visible_ising(self): | ||
| import networkx as nx |
Collaborator
There was a problem hiding this comment.
should be top level import?
| conditioning_blocks=[], | ||
| positive_sampling_blocks=[], | ||
| negative_sampling_blocks=free_blocks, | ||
| schedule_positive=SamplingSchedule(n_warmup=0, n_samples=1, steps_per_sample=0), |
Collaborator
There was a problem hiding this comment.
Seems weird we even need to provide a sampling schedule for positive if we don't sample? Should we change this?
| init_free, | ||
| ) | ||
|
|
||
| # Gradients should be finite and have correct shapes |
Collaborator
There was a problem hiding this comment.
we can add check that gradient is just energy or you think this is good enough?
| # data[0]: (batch, n_nodes) | ||
| spins = 2 * data[0].astype(float_type) - 1 # (batch, n_nodes) | ||
|
|
||
| ei_idx = jnp.array([bias_nodes.index(e[0]) for e in weight_edges]) # (n_edges,) |
Collaborator
There was a problem hiding this comment.
I guess we do this elsewhere? Just want to make sure this unroll isn't painful compilation wise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
If there are no hidden nodes, or all variables are clamped during the positive phase,
estimate_kl_graddoes not handle this edge case. Specifically, in the below contrastive divergence gradientthrmldoes not handle the case whereestimate_kl_gradimplicitly assumes there are always free variables in theinit_positive, by subindexing the list to create keys for sampling.This throws the expected
IndexErrorMinimal reproduction
Fix: explicitly handle this case in
estimate_kl_gradComments
Let me know if there's a more logical way of handling the shapes, or to set
moms_b_pos, moms_w_posto match the previous semantics