Skip to content

ImproperEmpirical bug #1812

Closed
Closed

Description

@manuelgloeckler

Improper Empirical still saves simulations

In #1700 the simulation cache should have been removed from the ImproperEmpirical prior, but its still there because it call super().__init__(values, log_weights=log_weights) and subclasses Empirical. Given that sample now raises an error these are not used at all and should be removed (i.e. by not using inheriting from Empirical.

Furthermore there is a bug in to method i.e. see below. This surfaced in #1793 .

class ImproperEmpirical(Empirical):
    """
    Wrapper around pyro's `Emprirical` distribution that returns constant `log_prob()`.

    This class is used in SNPE when no prior is passed. Having a constant
    log-probability will lead to no samples being rejected during rejection-sampling.

    The default behavior of `pyro.distributions.Empirical` is that it returns `-inf`
    for any value that does not **exactly** match one of the samples passed at
    initialization. Thus, all posterior samples would be rejected for not fitting this
    criterion.
    """

    def __init__(self, values: Tensor, log_weights: Optional[Tensor] = None):
        super().__init__(values, log_weights=log_weights)
        # Warn if extremely large to inform about memory/serialization cost.
        self._mean = self._compute_mean(values, log_weights)
        self._variance = self._compute_variance(values, log_weights)
...
...
...
 def to(self, device: Union[str, torch.device]) -> None:
        """
        Move the distribution to a different device.

        Args:
            device: The device to move the distribution to.

        Returns:
            The distribution on the specified device.
        """
        self._mean = self._mean.to(device)
        self._variance = self._variance.to(device)
        #super().to(device) TODO: This needs to be removed as neither Distirbution nor Empirical implement it.

Activity

  1. added
    bug
    on Mar 13, 2026
  2. patelshivani2283-lab commented on Mar 20, 2026

    @patelshivani2283-lab
    Contributor

    Nice catch! I had a look and agree this could be simplified by removing the Empirical inheritance and avoiding storing the simulations altogether.

    I’m happy to work on this and fix the .to() issue as well—unless someone is already working on it

  3. manuelgloeckler commented on Mar 20, 2026

    @manuelgloeckler
    ContributorAuthor

    Hey @patelshivani2283-lab,

    No one is working on this currently, happy for an PR on this :)

  4. manuelgloeckler commented on Apr 9, 2026

    @manuelgloeckler
    ContributorAuthor

    I close this as it was fixed in #1822

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions