Skip to content

fix(distributions): initialize expanded Delta instance - #2768

Open
aswanth-07 wants to merge 1 commit into
cornellius-gp:mainfrom
aswanth-07:agent/fix-delta-expand-without-pyro
Open

fix(distributions): initialize expanded Delta instance#2768
aswanth-07 wants to merge 1 commit into
cornellius-gp:mainfrom
aswanth-07:agent/fix-delta-expand-without-pyro

Conversation

@aswanth-07

Copy link
Copy Markdown

Summary

  • initialize the Delta instance returned by expand() when GPyTorch is using its Pyro-free fallback
  • preserve the original distribution's shape metadata
  • add a focused regression test for the returned value, batch/event shapes, and original instance

Root cause and impact

The fallback implementation called zero-argument super().__init__, which initializes self, after creating and populating new with _get_checked_instance. As a result, expanding a Delta unexpectedly changed the original distribution's batch_shape, while the returned object lacked _batch_shape and _event_shape and failed on normal distribution operations.

The fix follows Pyro's reference implementation and GPyTorch's existing MultivariateNormal.expand() pattern by initializing new explicitly.

Fixes #2767.

Validation

  • regression test on pristine main: fails because the original batch_shape changes from [2] to [3, 2] (and the returned object's batch_shape raises AttributeError)
  • python -m unittest test.distributions.test_delta — 5 passed
  • python -m unittest discover -s test/distributions -p "test_*.py" — 47 passed
  • relevant variational-strategy unit modules — 815 passed
  • python -m ufmt check gpytorch/distributions/delta.py test/distributions/test_delta.py — passed
  • py -3.13 -m flake8 gpytorch/distributions/delta.py test/distributions/test_delta.py — passed
  • remaining pre-commit hooks for both changed files — passed (flake8 was run separately; require-ascii was skipped because its Windows command did not quote this workspace path containing spaces)

All tests used CPU tensors with Pyro absent, exercising the affected fallback.

AI assistance

Codex assisted with repository inspection, reproduction, duplicate searching, implementation, tests, and drafting this pull request. I reviewed the diff and validation results.

@aswanth-07
aswanth-07 marked this pull request as ready for review August 9, 2026 16:41
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.

[Bug] Delta.expand returns an uninitialized distribution when Pyro is unavailable

1 participant