From 52ae7d43a1ad6e97214ca71851b6ef87f34ac427 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Thu, 21 May 2026 18:56:14 +0000 Subject: [PATCH 01/18] Fix lint formatting and mypy checks --- examples/air/main.py | 1 - examples/contrib/cevae/synthetic.py | 1 + examples/contrib/funsor/hmm.py | 1 + examples/hmm.py | 1 + examples/lda.py | 1 + examples/rsa/schelling.py | 1 + examples/rsa/schelling_false.py | 1 + examples/vae/ss_vae_M2.py | 4 ++-- pyro/contrib/autoname/__init__.py | 1 + pyro/contrib/autoname/named.py | 1 + pyro/contrib/autoname/scoping.py | 1 + pyro/contrib/cevae/__init__.py | 1 + pyro/contrib/epidemiology/models.py | 9 ++------- pyro/contrib/funsor/handlers/enum_messenger.py | 1 + pyro/contrib/gp/kernels/__init__.py | 11 ++--------- pyro/contrib/gp/likelihoods/__init__.py | 11 ++--------- pyro/contrib/minipyro.py | 1 + pyro/contrib/timeseries/__init__.py | 1 + pyro/distributions/torch.py | 8 ++------ pyro/distributions/torch_distribution.py | 6 ++---- pyro/infer/autoguide/guides.py | 1 + pyro/infer/autoguide/initialization.py | 1 + pyro/infer/mcmc/api.py | 1 + pyro/nn/auto_reg_nn.py | 11 ++++++----- pyro/nn/dense_nn.py | 8 ++++---- pyro/nn/module.py | 12 ++++++++++-- setup.cfg | 2 +- 27 files changed, 49 insertions(+), 50 deletions(-) diff --git a/examples/air/main.py b/examples/air/main.py index dadf77260c..ff1328448c 100644 --- a/examples/air/main.py +++ b/examples/air/main.py @@ -9,7 +9,6 @@ Processing Systems. 2016. """ - import argparse import math import os diff --git a/examples/contrib/cevae/synthetic.py b/examples/contrib/cevae/synthetic.py index c10c5f77a5..71c9058dd2 100644 --- a/examples/contrib/cevae/synthetic.py +++ b/examples/contrib/cevae/synthetic.py @@ -13,6 +13,7 @@ http://papers.nips.cc/paper/7223-causal-effect-inference-with-deep-latent-variable-models.pdf https://github.com/AMLab-Amsterdam/CEVAE """ + import argparse import logging diff --git a/examples/contrib/funsor/hmm.py b/examples/contrib/funsor/hmm.py index 00885a4616..010ebcf3dd 100644 --- a/examples/contrib/funsor/hmm.py +++ b/examples/contrib/funsor/hmm.py @@ -42,6 +42,7 @@ Fritz Obermeyer, Eli Bingham, Martin Jankowiak, Justin Chiu, Neeraj Pradhan, Alexander Rush, Noah Goodman. https://arxiv.org/abs/1902.03210 """ + import argparse import functools import logging diff --git a/examples/hmm.py b/examples/hmm.py index 76281ac8bd..4fe42d00fc 100644 --- a/examples/hmm.py +++ b/examples/hmm.py @@ -35,6 +35,7 @@ Fritz Obermeyer, Eli Bingham, Martin Jankowiak, Justin Chiu, Neeraj Pradhan, Alexander Rush, Noah Goodman. https://arxiv.org/abs/1902.03210 """ + import argparse import logging import sys diff --git a/examples/lda.py b/examples/lda.py index 00d3ac3bef..70cf9feeaf 100644 --- a/examples/lda.py +++ b/examples/lda.py @@ -19,6 +19,7 @@ "Pathwise gradients beyond the reparametrization trick" https://arxiv.org/pdf/1806.01851.pdf """ + import argparse import functools import logging diff --git a/examples/rsa/schelling.py b/examples/rsa/schelling.py index 7631bf6437..8f47587df5 100644 --- a/examples/rsa/schelling.py +++ b/examples/rsa/schelling.py @@ -10,6 +10,7 @@ Taken from: http://forestdb.org/models/schelling.html """ + import argparse import torch diff --git a/examples/rsa/schelling_false.py b/examples/rsa/schelling_false.py index 2eabb4b1b1..24501b3fae 100644 --- a/examples/rsa/schelling_false.py +++ b/examples/rsa/schelling_false.py @@ -11,6 +11,7 @@ Taken from: http://forestdb.org/models/schelling-falsebelief.html """ + import argparse import torch diff --git a/examples/vae/ss_vae_M2.py b/examples/vae/ss_vae_M2.py index 0d88ff3f0b..dd17104e04 100644 --- a/examples/vae/ss_vae_M2.py +++ b/examples/vae/ss_vae_M2.py @@ -246,10 +246,10 @@ def run_inference_for_epoch(data_loaders, losses, periodic_interval_batches): # extract the corresponding batch if is_supervised: - (xs, ys) = next(sup_iter) + xs, ys = next(sup_iter) ctr_sup += 1 else: - (xs, ys) = next(unsup_iter) + xs, ys = next(unsup_iter) # run the inference for each loss with supervised or un-supervised # data as arguments diff --git a/pyro/contrib/autoname/__init__.py b/pyro/contrib/autoname/__init__.py index 9a379fb2ff..8cd529d986 100644 --- a/pyro/contrib/autoname/__init__.py +++ b/pyro/contrib/autoname/__init__.py @@ -5,6 +5,7 @@ The :mod:`pyro.contrib.autoname` module provides tools for automatically generating unique, semantically meaningful names for sample sites. """ + from pyro.contrib.autoname import named from pyro.contrib.autoname.autoname import autoname, sample from pyro.contrib.autoname.scoping import name_count, scope diff --git a/pyro/contrib/autoname/named.py b/pyro/contrib/autoname/named.py index 1d1b63a929..20abc68dd0 100644 --- a/pyro/contrib/autoname/named.py +++ b/pyro/contrib/autoname/named.py @@ -49,6 +49,7 @@ Authors: Fritz Obermeyer, Alexander Rush """ + import functools import pyro diff --git a/pyro/contrib/autoname/scoping.py b/pyro/contrib/autoname/scoping.py index b9b746d0ba..bbe8c2d996 100644 --- a/pyro/contrib/autoname/scoping.py +++ b/pyro/contrib/autoname/scoping.py @@ -6,6 +6,7 @@ :func:`pyro.contrib.autoname.scope`, a tool for automatically appending a semantically meaningful prefix to names of sample sites. """ + import functools from pyro.poutine.messenger import Messenger diff --git a/pyro/contrib/cevae/__init__.py b/pyro/contrib/cevae/__init__.py index dd6da388a8..88cbc50a40 100644 --- a/pyro/contrib/cevae/__init__.py +++ b/pyro/contrib/cevae/__init__.py @@ -21,6 +21,7 @@ | http://papers.nips.cc/paper/7223-causal-effect-inference-with-deep-latent-variable-models.pdf | https://github.com/AMLab-Amsterdam/CEVAE """ + import logging import torch diff --git a/pyro/contrib/epidemiology/models.py b/pyro/contrib/epidemiology/models.py index cf2a8513c2..00d7121616 100644 --- a/pyro/contrib/epidemiology/models.py +++ b/pyro/contrib/epidemiology/models.py @@ -1277,14 +1277,9 @@ def transition(self, params, state, t): key=lambda name, vals=locals(): vals[name].__init__.__code__.co_firstlineno ) __doc__ = "\n\n".join( - [ - """ + [""" {} ---------------------------------------------------------------- .. autoclass:: pyro.contrib.epidemiology.models.{} - """.format( - re.sub("([A-Z][a-z]+)", r"\1 ", _name[:-5]), _name - ) - for _name in __all__ - ] + """.format(re.sub("([A-Z][a-z]+)", r"\1 ", _name[:-5]), _name) for _name in __all__] ) diff --git a/pyro/contrib/funsor/handlers/enum_messenger.py b/pyro/contrib/funsor/handlers/enum_messenger.py index 89fcd7e93b..b60713c222 100644 --- a/pyro/contrib/funsor/handlers/enum_messenger.py +++ b/pyro/contrib/funsor/handlers/enum_messenger.py @@ -5,6 +5,7 @@ This file contains reimplementations of some of Pyro's core enumeration machinery, which should eventually be drop-in replacements for the current versions. """ + import functools import math from collections import OrderedDict diff --git a/pyro/contrib/gp/kernels/__init__.py b/pyro/contrib/gp/kernels/__init__.py index 8c5985ac10..be7ab29786 100644 --- a/pyro/contrib/gp/kernels/__init__.py +++ b/pyro/contrib/gp/kernels/__init__.py @@ -52,9 +52,7 @@ ] # Create sphinx documentation. -__doc__ = "\n\n".join( - [ - """ +__doc__ = "\n\n".join([""" {0} ---------------------------------------------------------------- .. autoclass:: pyro.contrib.gp.kernels.{0} @@ -63,9 +61,4 @@ :special-members: __call__ :show-inheritance: :member-order: bysource - """.format( - _name - ) - for _name in __all__ - ] -) + """.format(_name) for _name in __all__]) diff --git a/pyro/contrib/gp/likelihoods/__init__.py b/pyro/contrib/gp/likelihoods/__init__.py index 30749be3fb..c9125dc22c 100644 --- a/pyro/contrib/gp/likelihoods/__init__.py +++ b/pyro/contrib/gp/likelihoods/__init__.py @@ -17,9 +17,7 @@ # Create sphinx documentation. -__doc__ = "\n\n".join( - [ - """ +__doc__ = "\n\n".join([""" {0} ---------------------------------------------------------------- .. autoclass:: pyro.contrib.gp.likelihoods.{0} @@ -28,9 +26,4 @@ :special-members: __call__ :show-inheritance: :member-order: bysource - """.format( - _name - ) - for _name in __all__ - ] -) + """.format(_name) for _name in __all__]) diff --git a/pyro/contrib/minipyro.py b/pyro/contrib/minipyro.py index 03e52bd8de..fd6e8a5136 100644 --- a/pyro/contrib/minipyro.py +++ b/pyro/contrib/minipyro.py @@ -14,6 +14,7 @@ An accompanying example that makes use of this implementation can be found at examples/minipyro.py. """ + import random import warnings import weakref diff --git a/pyro/contrib/timeseries/__init__.py b/pyro/contrib/timeseries/__init__.py index 4502744bc7..4aa4e0f298 100644 --- a/pyro/contrib/timeseries/__init__.py +++ b/pyro/contrib/timeseries/__init__.py @@ -5,6 +5,7 @@ The :mod:`pyro.contrib.timeseries` module provides a collection of Bayesian time series models useful for forecasting applications. """ + from pyro.contrib.timeseries.base import TimeSeriesModel from pyro.contrib.timeseries.gp import ( DependentMaternGP, diff --git a/pyro/distributions/torch.py b/pyro/distributions/torch.py index 2f3f255d97..7113bde6b1 100644 --- a/pyro/distributions/torch.py +++ b/pyro/distributions/torch.py @@ -411,9 +411,7 @@ def _cat_docstrings(*docstrings): Wraps :class:`{}.{}` with :class:`~pyro.distributions.torch_distribution.TorchDistributionMixin`. - """.format( - _Dist.__module__, _Dist.__name__ - ) + """.format(_Dist.__module__, _Dist.__name__) _PyroDist.__doc__ = _cat_docstrings(_PyroDist.__doc__, _Dist.__doc__) __all__.append(_name) __all__ = sorted(set(__all__)) @@ -426,9 +424,7 @@ def _cat_docstrings(*docstrings): {0} ---------------------------------------------------------------- .. autoclass:: pyro.distributions.{0} - """.format( - _name - ) + """.format(_name) for _name in sorted(__all__) # Work around sphinx autodoc error in case two InverseGamma's are defined: # "duplicate object description of pyro.distributions.InverseGamma" diff --git a/pyro/distributions/torch_distribution.py b/pyro/distributions/torch_distribution.py index ace02da72a..ee9f07dc87 100644 --- a/pyro/distributions/torch_distribution.py +++ b/pyro/distributions/torch_distribution.py @@ -154,11 +154,9 @@ def expand_by(self, sample_shape): return expanded_dist def reshape(self, sample_shape=None, extra_event_dims=None): - raise Exception( - """ + raise Exception(""" .reshape(sample_shape=s, extra_event_dims=n) was renamed and split into - .expand_by(sample_shape=s).to_event(reinterpreted_batch_ndims=n).""" - ) + .expand_by(sample_shape=s).to_event(reinterpreted_batch_ndims=n).""") def to_event(self, reinterpreted_batch_ndims=None): """ diff --git a/pyro/infer/autoguide/guides.py b/pyro/infer/autoguide/guides.py index 40e401b561..31506b6ee4 100644 --- a/pyro/infer/autoguide/guides.py +++ b/pyro/infer/autoguide/guides.py @@ -15,6 +15,7 @@ def model(): Automatic guides can also be combined using :func:`pyro.poutine.block` and :class:`AutoGuideList`. """ + import functools import operator import warnings diff --git a/pyro/infer/autoguide/initialization.py b/pyro/infer/autoguide/initialization.py index 5654f34346..706f89f602 100644 --- a/pyro/infer/autoguide/initialization.py +++ b/pyro/infer/autoguide/initialization.py @@ -9,6 +9,7 @@ trace ``site`` dict and returns an appropriately sized ``value`` to serve as an initial constrained value for a guide estimate. """ + import functools from typing import Callable, Optional diff --git a/pyro/infer/mcmc/api.py b/pyro/infer/mcmc/api.py index d6df431e9c..4808a7e924 100644 --- a/pyro/infer/mcmc/api.py +++ b/pyro/infer/mcmc/api.py @@ -9,6 +9,7 @@ code that works with different backends. - minimal memory consumption with multiprocessing and CUDA. """ + import copy import json import logging diff --git a/pyro/nn/auto_reg_nn.py b/pyro/nn/auto_reg_nn.py index e2d29feda2..7c0d7efd79 100644 --- a/pyro/nn/auto_reg_nn.py +++ b/pyro/nn/auto_reg_nn.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import warnings -from typing import List, Optional, Sequence, Tuple, Union +from typing import List, Optional, Sequence, Tuple, Union, cast import torch import torch.nn as nn @@ -118,6 +118,7 @@ def __init__( self, in_features: int, out_features: int, mask: torch.Tensor, bias: bool = True ) -> None: super().__init__(in_features, out_features, bias) + self.mask: torch.Tensor self.register_buffer("mask", mask.data) def forward(self, _input: torch.Tensor) -> torch.Tensor: @@ -263,7 +264,7 @@ def forward( ) -> Union[Sequence[torch.Tensor], torch.Tensor]: # We must be able to broadcast the size of the context over the input if context is None: - context = self.context + context = cast(torch.Tensor, self.context) context = context.expand(x.size()[:-1] + (context.size(-1),)) x = torch.cat([context, x], dim=-1) @@ -273,14 +274,14 @@ def _forward(self, x: torch.Tensor) -> Union[Sequence[torch.Tensor], torch.Tenso h = x for layer in self.layers[:-1]: h = self.f(layer(h)) - h = self.layers[-1](h) + h = cast(torch.Tensor, self.layers[-1](h)) if self.skip_layer is not None: h = h + self.skip_layer(x) # Shape the output, squeezing the parameter dimension if all ones if self.output_multiplier == 1: - return h + return cast(torch.Tensor, h) else: h = h.reshape( list(x.size()[:-1]) + [self.output_multiplier, self.input_dim] @@ -288,7 +289,7 @@ def _forward(self, x: torch.Tensor) -> Union[Sequence[torch.Tensor], torch.Tenso # Squeeze dimension if all parameters are one dimensional if self.count_params == 1: - return h + return cast(torch.Tensor, h) elif self.all_ones: return torch.unbind(h, dim=-2) diff --git a/pyro/nn/dense_nn.py b/pyro/nn/dense_nn.py index a3cf93af8d..1b4ad45c24 100644 --- a/pyro/nn/dense_nn.py +++ b/pyro/nn/dense_nn.py @@ -1,7 +1,7 @@ # Copyright (c) 2017-2019 Uber Technologies, Inc. # SPDX-License-Identifier: Apache-2.0 -from typing import List, Sequence, Union +from typing import List, Sequence, Union, cast import torch @@ -83,16 +83,16 @@ def _forward(self, x: torch.Tensor) -> Union[Sequence[torch.Tensor], torch.Tenso h = x for layer in self.layers[:-1]: h = self.f(layer(h)) - h = self.layers[-1](h) + h = cast(torch.Tensor, self.layers[-1](h)) # Shape the output, squeezing the parameter dimension if all ones if self.output_multiplier == 1: - return h + return cast(torch.Tensor, h) else: h = h.reshape(list(x.size()[:-1]) + [self.output_multiplier]) if self.count_params == 1: - return h + return cast(torch.Tensor, h) else: return tuple([h[..., s] for s in self.param_slices]) diff --git a/pyro/nn/module.py b/pyro/nn/module.py index fd897e2877..c11bfc9692 100644 --- a/pyro/nn/module.py +++ b/pyro/nn/module.py @@ -12,6 +12,7 @@ my_module.y = PyroSample(dist.Normal(0, 1)) """ + import functools import inspect import warnings @@ -25,7 +26,7 @@ ) # Fall back to trivial decorator. - def _copy_to_script_wrapper(fn): + def _copy_to_script_wrapper(fn): # type: ignore[misc] return fn @@ -45,6 +46,7 @@ def _copy_to_script_wrapper(fn): Type, TypeVar, Union, + overload, ) import torch @@ -954,10 +956,16 @@ class PyroModuleList(torch.nn.ModuleList, PyroModule): def __init__(self, modules): super().__init__(modules) + @overload + def __getitem__(self, idx: slice) -> torch.nn.ModuleList: ... + + @overload + def __getitem__(self, idx: int) -> torch.nn.Module: ... + @_copy_to_script_wrapper def __getitem__( self, idx: Union[int, slice] - ) -> Union[torch.nn.Module, "PyroModuleList"]: + ) -> Union[torch.nn.Module, torch.nn.ModuleList]: if isinstance(idx, slice): # return self.__class__(list(self._modules.values())[idx]) return torch.nn.ModuleList(list(self._modules.values())[idx]) diff --git a/setup.cfg b/setup.cfg index b21884cb87..9894e4abe7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,7 +28,7 @@ column_limit = 120 # Global options: [mypy] -python_version = 3.8 +python_version = 3.9 explicit_package_bases = True warn_return_any = True warn_unused_configs = True From a4cdef1882bddb3cef76f0438bf67fa73df4809e Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Tue, 26 May 2026 03:00:49 +0000 Subject: [PATCH 02/18] upgrade versions --- docs/requirements.txt | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index de8870c9fe..fff44d9f93 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,8 +2,8 @@ # # SPDX-License-Identifier: Apache-2.0 -sphinx==4.2.0 -sphinx-rtd-theme==1.0.0 +sphinx>=4.2.0 +sphinx-rtd-theme>=1.0.0 graphviz>=0.8 numpy>=1.7 observations>=0.1.4 diff --git a/setup.py b/setup.py index 10e986b994..b61a1a8b1b 100644 --- a/setup.py +++ b/setup.py @@ -70,7 +70,7 @@ "graphviz>=0.8", "matplotlib>=1.3", "torchvision>=0.15.0", - "visdom>=0.1.4,<0.2.2", # FIXME visdom.utils is unavailable >=0.2.2 + "visdom>=0.2.3", "pandas", "pillow>=8.3.1", # https://github.com/pytorch/pytorch/issues/61125 "scikit-learn", From afdc7324096f603496efec955ff7cbedc27aa8dc Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Tue, 26 May 2026 03:21:00 +0000 Subject: [PATCH 03/18] Fix visdom install in CI and tighten NN typing Preinstall visdom without build isolation to avoid pkg_resources failures on modern setuptools, require explicit context in ConditionalAutoRegressiveNN, and replace cast-based mypy suppressions with type ignores. --- .github/workflows/ci.yml | 7 +++++++ Makefile | 1 + pyro/nn/auto_reg_nn.py | 13 +++++-------- pyro/nn/dense_nn.py | 8 ++++---- scripts/install_visdom.sh | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100755 scripts/install_visdom.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1742df05c2..cdb1858123 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,7 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu + bash scripts/install_visdom.sh pip install .[test] pip install -r docs/requirements.txt pip install --upgrade sphinx docutils sphinx-rtd-theme @@ -84,6 +85,7 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu + bash scripts/install_visdom.sh pip install .[test] pip install -r docs/requirements.txt # requirements for tutorials (from .[dev]) @@ -118,6 +120,7 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu + bash scripts/install_visdom.sh pip install .[test] pip install --upgrade coveralls pip freeze @@ -152,6 +155,7 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu + bash scripts/install_visdom.sh pip install .[test] pip install --upgrade coveralls pip freeze @@ -186,6 +190,7 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu + bash scripts/install_visdom.sh pip install .[test] pip install --upgrade coveralls pip freeze @@ -218,6 +223,7 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu + bash scripts/install_visdom.sh pip install .[test] pip install --upgrade coveralls pip freeze @@ -250,6 +256,7 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu + bash scripts/install_visdom.sh pip install .[test] pip install -e .[funsor] pip install --upgrade coveralls diff --git a/Makefile b/Makefile index 04c6112d47..1a8abac3c2 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ all: docs test install: FORCE + bash scripts/install_visdom.sh pip install -e .[dev,profile] --config-settings editable_mode=strict uninstall: FORCE diff --git a/pyro/nn/auto_reg_nn.py b/pyro/nn/auto_reg_nn.py index 7c0d7efd79..4dfaaf0ab7 100644 --- a/pyro/nn/auto_reg_nn.py +++ b/pyro/nn/auto_reg_nn.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 import warnings -from typing import List, Optional, Sequence, Tuple, Union, cast +from typing import List, Optional, Sequence, Tuple, Union import torch import torch.nn as nn @@ -260,12 +260,9 @@ def get_permutation(self) -> torch.LongTensor: return self.permutation def forward( - self, x: torch.Tensor, context: Optional[torch.Tensor] = None + self, x: torch.Tensor, context: torch.Tensor ) -> Union[Sequence[torch.Tensor], torch.Tensor]: # We must be able to broadcast the size of the context over the input - if context is None: - context = cast(torch.Tensor, self.context) - context = context.expand(x.size()[:-1] + (context.size(-1),)) x = torch.cat([context, x], dim=-1) return self._forward(x) @@ -274,14 +271,14 @@ def _forward(self, x: torch.Tensor) -> Union[Sequence[torch.Tensor], torch.Tenso h = x for layer in self.layers[:-1]: h = self.f(layer(h)) - h = cast(torch.Tensor, self.layers[-1](h)) + h = self.layers[-1](h) # type: ignore[no-any-return] if self.skip_layer is not None: h = h + self.skip_layer(x) # Shape the output, squeezing the parameter dimension if all ones if self.output_multiplier == 1: - return cast(torch.Tensor, h) + return h # type: ignore[no-any-return] else: h = h.reshape( list(x.size()[:-1]) + [self.output_multiplier, self.input_dim] @@ -289,7 +286,7 @@ def _forward(self, x: torch.Tensor) -> Union[Sequence[torch.Tensor], torch.Tenso # Squeeze dimension if all parameters are one dimensional if self.count_params == 1: - return cast(torch.Tensor, h) + return h # type: ignore[no-any-return] elif self.all_ones: return torch.unbind(h, dim=-2) diff --git a/pyro/nn/dense_nn.py b/pyro/nn/dense_nn.py index 1b4ad45c24..9e1d6780be 100644 --- a/pyro/nn/dense_nn.py +++ b/pyro/nn/dense_nn.py @@ -1,7 +1,7 @@ # Copyright (c) 2017-2019 Uber Technologies, Inc. # SPDX-License-Identifier: Apache-2.0 -from typing import List, Sequence, Union, cast +from typing import List, Sequence, Union import torch @@ -83,16 +83,16 @@ def _forward(self, x: torch.Tensor) -> Union[Sequence[torch.Tensor], torch.Tenso h = x for layer in self.layers[:-1]: h = self.f(layer(h)) - h = cast(torch.Tensor, self.layers[-1](h)) + h = self.layers[-1](h) # type: ignore[no-any-return] # Shape the output, squeezing the parameter dimension if all ones if self.output_multiplier == 1: - return cast(torch.Tensor, h) + return h # type: ignore[no-any-return] else: h = h.reshape(list(x.size()[:-1]) + [self.output_multiplier]) if self.count_params == 1: - return cast(torch.Tensor, h) + return h # type: ignore[no-any-return] else: return tuple([h[..., s] for s in self.param_slices]) diff --git a/scripts/install_visdom.sh b/scripts/install_visdom.sh new file mode 100755 index 0000000000..72ffe86e15 --- /dev/null +++ b/scripts/install_visdom.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Copyright Contributors to the Pyro project. +# +# SPDX-License-Identifier: Apache-2.0 + +# visdom is distributed as an sdist whose setup.py imports pkg_resources. +# Modern setuptools (>=81) no longer provides pkg_resources in pip's isolated +# build environment, so preinstall visdom without build isolation. + +set -xe + +pip install 'setuptools<81' +pip install --no-build-isolation 'visdom>=0.2.3' From 5f3e3f79201f33d485e1b1424d166f8961dc7a12 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Sun, 31 May 2026 11:03:23 +0000 Subject: [PATCH 04/18] Fix Funsor test and doctest compatibility --- Makefile | 2 +- pyro/distributions/torch_patch.py | 6 ------ setup.cfg | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 1a8abac3c2..4f01faad8a 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,7 @@ test-jit: FORCE -k JIT=True | tee -a jit.log test-funsor: lint FORCE - pytest -vx -n auto --stage funsor + pytest -vx -n auto -p no:benchmark --stage funsor clean: FORCE git clean -dfx -e pyro_ppl.egg-info diff --git a/pyro/distributions/torch_patch.py b/pyro/distributions/torch_patch.py index 3a93d72780..faddc0268e 100644 --- a/pyro/distributions/torch_patch.py +++ b/pyro/distributions/torch_patch.py @@ -86,10 +86,4 @@ def _CorrCholesky_check(self, value): return torch.distributions.constraints.lower_cholesky.check(value) & unit_row_norm -# This adds a __call__ method to satisfy sphinx. -@patch_dependency("torch.distributions.utils.lazy_property.__call__") -def _lazy_property__call__(self): - raise NotImplementedError - - __all__ = [] diff --git a/setup.cfg b/setup.cfg index 9894e4abe7..15410c9278 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,7 +28,7 @@ column_limit = 120 # Global options: [mypy] -python_version = 3.9 +python_version = 3.10 explicit_package_bases = True warn_return_any = True warn_unused_configs = True From b40db874a90a8cc5aa1688d244d4574aba720a96 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Sun, 31 May 2026 11:27:32 +0000 Subject: [PATCH 05/18] Pin Funsor dependency to fix branch --- docs/requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index fff44d9f93..22e298dc04 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -10,6 +10,6 @@ observations>=0.1.4 opt_einsum>=2.3.2 pyro-api>=0.1.1 tqdm>=4.36 -funsor[torch] +funsor[torch] @ git+https://github.com/pyro-ppl/funsor.git@8a8ca81fcc61733ad82e163028c7ff78420df9f0 setuptools sphinx_copybutton diff --git a/setup.py b/setup.py index b61a1a8b1b..27973000d1 100644 --- a/setup.py +++ b/setup.py @@ -141,7 +141,7 @@ "horovod": ["horovod[pytorch]>=0.19"], "lightning": ["lightning"], "funsor": [ - "funsor[torch]==0.4.4", + "funsor[torch] @ git+https://github.com/pyro-ppl/funsor.git@8a8ca81fcc61733ad82e163028c7ff78420df9f0", ], }, python_requires=">=3.8", From b6814a0d57f74dcc586baf7131e8c3d8a2b0f964 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 01:39:35 -0400 Subject: [PATCH 06/18] tuple sequence --- pyro/distributions/spanning_tree.py | 7 +------ pyro/distributions/stable_log_prob.py | 4 ++-- pyro/ops/stats.py | 2 +- pyro/optim/dct_adam.py | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pyro/distributions/spanning_tree.py b/pyro/distributions/spanning_tree.py index 8feb921511..3adb9c2fb9 100644 --- a/pyro/distributions/spanning_tree.py +++ b/pyro/distributions/spanning_tree.py @@ -131,12 +131,7 @@ def log_partition_function(self): shift = 0.5 * log_diag laplacian = torch.eye(V) - (logits - shift - shift[:, None]).exp() truncated = laplacian[:-1, :-1] - try: - import gpytorch - - log_det = gpytorch.lazy.NonLazyTensor(truncated).logdet() - except ImportError: - log_det = torch.linalg.cholesky(truncated).diag().log().sum() * 2 + log_det = torch.linalg.cholesky(truncated).diag().log().sum() * 2 return log_det + log_diag[:-1].sum() def log_prob(self, edges): diff --git a/pyro/distributions/stable_log_prob.py b/pyro/distributions/stable_log_prob.py index fa173e58f9..d330bec4f9 100644 --- a/pyro/distributions/stable_log_prob.py +++ b/pyro/distributions/stable_log_prob.py @@ -27,10 +27,10 @@ def create_integrator(num_points): def integrate(fn, domain): sl = [slice(None)] + (len(domain.shape) - 1) * [None] - half_roots_sl = half_roots[sl] + half_roots_sl = half_roots[tuple(sl)] value = domain[0] * (0.5 - half_roots_sl) + domain[1] * (0.5 + half_roots_sl) return ( - torch.logsumexp(fn(value) + log_weights[sl], dim=0) + torch.logsumexp(fn(value) + log_weights[tuple(sl)], dim=0) + ((domain[1] - domain[0]) / 2).log() ) diff --git a/pyro/ops/stats.py b/pyro/ops/stats.py index cacc68d261..fbc17b47ce 100644 --- a/pyro/ops/stats.py +++ b/pyro/ops/stats.py @@ -316,7 +316,7 @@ def weighed_quantile( probs_shape = [None] * dim + [slice(None)] + [None] * (len(input.shape) - dim - 1) expanded_probs_shape = list(input.shape) expanded_probs_shape[dim] = len(probs) - probs = probs[probs_shape].expand(*expanded_probs_shape) + probs = probs[tuple(probs_shape)].expand(*expanded_probs_shape) weights_below = weights.gather(dim, indices_below) weights_above = weights.gather(dim, indices_above) weights_below = (weights_above - probs) / (weights_above - weights_below) diff --git a/pyro/optim/dct_adam.py b/pyro/optim/dct_adam.py index 10384b4289..bd90cf3d4a 100644 --- a/pyro/optim/dct_adam.py +++ b/pyro/optim/dct_adam.py @@ -47,7 +47,7 @@ def _get_mask(x, indices): idx = [] for dim in range(-x.dim(), 0): if dim in indices: - mask[idx + [indices[dim]]] += 1 + mask[tuple(idx + [indices[dim]])] += 1 idx.append(slice(None)) return mask == len(indices) From 850c82c503f4599c0510424e8df62fbc9350f2dc Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 14:01:33 +0000 Subject: [PATCH 07/18] Stop forcing GCC 9 in CI --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cdb1858123..78eec8e54c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,8 +7,6 @@ on: branches: [dev, master] env: - CXX: g++-9 - CC: gcc-9 # See coveralls-python - Github Actions support: # https://github.com/TheKevJames/coveralls-python/blob/master/docs/usage/configuration.rst#github-actions-support GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From fb8668c4635c8476ce4103b6e771ec7c06e81582 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 15:27:18 +0000 Subject: [PATCH 08/18] Fix PyTorch distribution compatibility --- pyro/distributions/torch.py | 4 ++++ pyro/infer/abstract_infer.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyro/distributions/torch.py b/pyro/distributions/torch.py index 7113bde6b1..cb143b655d 100644 --- a/pyro/distributions/torch.py +++ b/pyro/distributions/torch.py @@ -331,6 +331,10 @@ def expand(self, batch_shape, _instance=None): new._unbroadcasted_high = self._unbroadcasted_high return new + @staticmethod + def infer_shapes(low, high): + return torch.Size(broadcast_shape(low, high)), torch.Size() + @constraints.dependent_property(is_discrete=False, event_dim=0) def support(self): return constraints.interval(self._unbroadcasted_low, self._unbroadcasted_high) diff --git a/pyro/infer/abstract_infer.py b/pyro/infer/abstract_infer.py index 2f48f16836..29105ec416 100644 --- a/pyro/infer/abstract_infer.py +++ b/pyro/infer/abstract_infer.py @@ -247,7 +247,7 @@ def run(self, *args, **kwargs): :param kwargs: optional keywords args taken by `self._traces`. """ self._reset() - with poutine.block(): + with torch.no_grad(), poutine.block(): for i, vals in enumerate(self._traces(*args, **kwargs)): if len(vals) == 2: chain_id = 0 @@ -259,7 +259,7 @@ def run(self, *args, **kwargs): self.log_weights.append(logit) self.chain_ids.append(chain_id) self._idx_by_chain[chain_id].append(i) - self._categorical = Categorical(logits=torch.tensor(self.log_weights)) + self._categorical = Categorical(logits=torch.stack(self.log_weights)) return self def information_criterion(self, pointwise=False): From 524b97911c9b485db1dd98adfd896a591c0f35a6 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 15:42:47 +0000 Subject: [PATCH 09/18] Remove Visdom from test dependencies --- .github/workflows/ci.yml | 7 ------- Makefile | 1 - examples/air/main.py | 3 ++- examples/vae/ss_vae_M2.py | 3 ++- examples/vae/vae.py | 3 ++- scripts/install_visdom.sh | 14 -------------- setup.py | 1 - 7 files changed, 6 insertions(+), 26 deletions(-) delete mode 100755 scripts/install_visdom.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78eec8e54c..97fac2e6c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,6 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - bash scripts/install_visdom.sh pip install .[test] pip install -r docs/requirements.txt pip install --upgrade sphinx docutils sphinx-rtd-theme @@ -83,7 +82,6 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - bash scripts/install_visdom.sh pip install .[test] pip install -r docs/requirements.txt # requirements for tutorials (from .[dev]) @@ -118,7 +116,6 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - bash scripts/install_visdom.sh pip install .[test] pip install --upgrade coveralls pip freeze @@ -153,7 +150,6 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - bash scripts/install_visdom.sh pip install .[test] pip install --upgrade coveralls pip freeze @@ -188,7 +184,6 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - bash scripts/install_visdom.sh pip install .[test] pip install --upgrade coveralls pip freeze @@ -221,7 +216,6 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - bash scripts/install_visdom.sh pip install .[test] pip install --upgrade coveralls pip freeze @@ -254,7 +248,6 @@ jobs: # Keep track of pyro-api master branch pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu - bash scripts/install_visdom.sh pip install .[test] pip install -e .[funsor] pip install --upgrade coveralls diff --git a/Makefile b/Makefile index 4f01faad8a..745a4910f5 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ all: docs test install: FORCE - bash scripts/install_visdom.sh pip install -e .[dev,profile] --config-settings editable_mode=strict uninstall: FORCE diff --git a/examples/air/main.py b/examples/air/main.py index ff1328448c..a491f0bd1e 100644 --- a/examples/air/main.py +++ b/examples/air/main.py @@ -17,7 +17,6 @@ import numpy as np import torch -import visdom from air import AIR, latents_to_tensor from viz import draw_many, tensor_to_objs @@ -203,6 +202,8 @@ def z_pres_prior_p(opt_step, time_step): # Viz sample from prior. if args.viz: + import visdom + vis = visdom.Visdom(env=args.visdom_env) z, x = air.prior(5, z_pres_prior_p=partial(z_pres_prior_p, 0)) vis.images(draw_many(x, tensor_to_objs(latents_to_tensor(z)))) diff --git a/examples/vae/ss_vae_M2.py b/examples/vae/ss_vae_M2.py index dd17104e04..4f1af44bb6 100644 --- a/examples/vae/ss_vae_M2.py +++ b/examples/vae/ss_vae_M2.py @@ -8,7 +8,6 @@ from utils.custom_mlp import MLP, Exp from utils.mnist_cached import MNISTCached, mkdir_p, setup_data_loaders from utils.vae_plots import mnist_test_tsne_ssvae, plot_conditional_samples_ssvae -from visdom import Visdom import pyro import pyro.distributions as dist @@ -306,6 +305,8 @@ def main(args): viz = None if args.visualize: + from visdom import Visdom + viz = Visdom() mkdir_p("./vae_results") diff --git a/examples/vae/vae.py b/examples/vae/vae.py index 5677b6e22c..fbc650f80f 100644 --- a/examples/vae/vae.py +++ b/examples/vae/vae.py @@ -6,7 +6,6 @@ import numpy as np import torch import torch.nn as nn -import visdom from utils.mnist_cached import MNISTCached as MNIST from utils.mnist_cached import setup_data_loaders from utils.vae_plots import mnist_test_tsne, plot_llk, plot_vae_samples @@ -145,6 +144,8 @@ def main(args): # setup visdom for visualization if args.visdom_flag: + import visdom + vis = visdom.Visdom() train_elbo = {} diff --git a/scripts/install_visdom.sh b/scripts/install_visdom.sh deleted file mode 100755 index 72ffe86e15..0000000000 --- a/scripts/install_visdom.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# Copyright Contributors to the Pyro project. -# -# SPDX-License-Identifier: Apache-2.0 - -# visdom is distributed as an sdist whose setup.py imports pkg_resources. -# Modern setuptools (>=81) no longer provides pkg_resources in pip's isolated -# build environment, so preinstall visdom without build isolation. - -set -xe - -pip install 'setuptools<81' -pip install --no-build-isolation 'visdom>=0.2.3' diff --git a/setup.py b/setup.py index 27973000d1..b41f6fb656 100644 --- a/setup.py +++ b/setup.py @@ -70,7 +70,6 @@ "graphviz>=0.8", "matplotlib>=1.3", "torchvision>=0.15.0", - "visdom>=0.2.3", "pandas", "pillow>=8.3.1", # https://github.com/pytorch/pytorch/issues/61125 "scikit-learn", From b06eb00cde05287aa233aa46e014bb2304969ec6 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 15:53:56 +0000 Subject: [PATCH 10/18] Enforce unused type ignore checks --- Makefile | 2 +- pyro/__init__.py | 2 +- pyro/nn/auto_reg_nn.py | 2 +- pyro/nn/dense_nn.py | 2 +- pyro/ops/special.py | 2 +- pyro/poutine/subsample_messenger.py | 6 +++--- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 745a4910f5..323645f15f 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ lint: FORCE ruff check . black --check *.py pyro examples tests scripts profiler python scripts/update_headers.py --check - mypy --install-types --non-interactive pyro scripts tests + mypy --install-types --non-interactive --warn-unused-ignores pyro scripts tests license: FORCE python scripts/update_headers.py diff --git a/pyro/__init__.py b/pyro/__init__.py index c9b4905eab..7f95b83966 100644 --- a/pyro/__init__.py +++ b/pyro/__init__.py @@ -32,7 +32,7 @@ # Get the __version__ string from the auto-generated _version.py file, if exists. try: - from pyro._version import __version__ # type: ignore + from pyro._version import __version__ except ImportError: __version__ = version_prefix diff --git a/pyro/nn/auto_reg_nn.py b/pyro/nn/auto_reg_nn.py index 4dfaaf0ab7..30d038aa39 100644 --- a/pyro/nn/auto_reg_nn.py +++ b/pyro/nn/auto_reg_nn.py @@ -271,7 +271,7 @@ def _forward(self, x: torch.Tensor) -> Union[Sequence[torch.Tensor], torch.Tenso h = x for layer in self.layers[:-1]: h = self.f(layer(h)) - h = self.layers[-1](h) # type: ignore[no-any-return] + h = self.layers[-1](h) if self.skip_layer is not None: h = h + self.skip_layer(x) diff --git a/pyro/nn/dense_nn.py b/pyro/nn/dense_nn.py index 9e1d6780be..e935a8d4ca 100644 --- a/pyro/nn/dense_nn.py +++ b/pyro/nn/dense_nn.py @@ -83,7 +83,7 @@ def _forward(self, x: torch.Tensor) -> Union[Sequence[torch.Tensor], torch.Tenso h = x for layer in self.layers[:-1]: h = self.f(layer(h)) - h = self.layers[-1](h) # type: ignore[no-any-return] + h = self.layers[-1](h) # Shape the output, squeezing the parameter dimension if all ones if self.output_multiplier == 1: diff --git a/pyro/ops/special.py b/pyro/ops/special.py index abd16df47a..7e38896df7 100644 --- a/pyro/ops/special.py +++ b/pyro/ops/special.py @@ -213,6 +213,6 @@ def _log_factorial_sum(x: torch.Tensor) -> torch.Tensor: return (x + 1).lgamma().sum() key = id(x) if key not in _log_factorial_cache: - weakref.finalize(x, _log_factorial_cache.pop, key, None) # type: ignore + weakref.finalize(x, _log_factorial_cache.pop, key, None) _log_factorial_cache[key] = (x + 1).lgamma().sum() return _log_factorial_cache[key] diff --git a/pyro/poutine/subsample_messenger.py b/pyro/poutine/subsample_messenger.py index 5fe9203aea..c62258e68a 100644 --- a/pyro/poutine/subsample_messenger.py +++ b/pyro/poutine/subsample_messenger.py @@ -205,13 +205,13 @@ def _postprocess_message(self, msg: Message) -> None: ) if msg["type"] == "param": if hasattr(value, "_pyro_unconstrained_param"): - param = value._pyro_unconstrained_param # type: ignore[attr-defined] + param = value._pyro_unconstrained_param else: - param = value.unconstrained() # type: ignore[attr-defined] + param = value.unconstrained() if not hasattr(param, "_pyro_subsample"): param._pyro_subsample = {} param._pyro_subsample[dim] = self._indices - new_value._pyro_unconstrained_param = param # type: ignore[attr-defined] + new_value._pyro_unconstrained_param = param msg["value"] = new_value From ea50d799b9bed3a86ab2a2d0a3977d925f9c3914 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 16:46:25 +0000 Subject: [PATCH 11/18] Install Pyro before CI lint --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97fac2e6c0..e045fa54a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,7 @@ jobs: run: | python -m pip install --upgrade pip wheel setuptools pip install ruff black mypy nbstripout nbformat + pip install -e . - name: Lint run: | make lint From 5c698ffd5c9793ea4ca49f10c6278000fe2cafe0 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 17:33:41 +0000 Subject: [PATCH 12/18] Preserve gradients during posterior runs --- pyro/infer/abstract_infer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyro/infer/abstract_infer.py b/pyro/infer/abstract_infer.py index 29105ec416..9db509b677 100644 --- a/pyro/infer/abstract_infer.py +++ b/pyro/infer/abstract_infer.py @@ -247,7 +247,7 @@ def run(self, *args, **kwargs): :param kwargs: optional keywords args taken by `self._traces`. """ self._reset() - with torch.no_grad(), poutine.block(): + with poutine.block(): for i, vals in enumerate(self._traces(*args, **kwargs)): if len(vals) == 2: chain_id = 0 From f4709fb5dd2553d10050c0fff2d5c4b0884c923f Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 20:36:23 +0000 Subject: [PATCH 13/18] Detach posterior log weights before storage --- pyro/infer/abstract_infer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyro/infer/abstract_infer.py b/pyro/infer/abstract_infer.py index 9db509b677..332023adf2 100644 --- a/pyro/infer/abstract_infer.py +++ b/pyro/infer/abstract_infer.py @@ -256,7 +256,7 @@ def run(self, *args, **kwargs): tr, logit, chain_id = vals assert chain_id < self.num_chains self.exec_traces.append(tr) - self.log_weights.append(logit) + self.log_weights.append(torch.as_tensor(logit).detach()) self.chain_ids.append(chain_id) self._idx_by_chain[chain_id].append(i) self._categorical = Categorical(logits=torch.stack(self.log_weights)) From c99a8973ff24b696596729a1204d5f9e01a4533e Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Wed, 3 Jun 2026 23:08:40 +0000 Subject: [PATCH 14/18] Stack predictive log probabilities --- pyro/infer/predictive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyro/infer/predictive.py b/pyro/infer/predictive.py index b57a193f4d..fa31236ea2 100644 --- a/pyro/infer/predictive.py +++ b/pyro/infer/predictive.py @@ -424,13 +424,13 @@ def forward(self, *args, **kwargs): guide_log_prob = plate_log_prob_sum(guide_trace, plate_symbol) model_log_prob = plate_log_prob_sum(model_trace, plate_symbol) else: - guide_log_prob = torch.Tensor( + guide_log_prob = torch.stack( [ trace_element.log_prob_sum() for trace_element in guide_predictive.trace ] ) - model_log_prob = torch.Tensor( + model_log_prob = torch.stack( [ trace_element.log_prob_sum() for trace_element in model_predictive.trace From c0ee224a2ecc26ac992b8c974723a478de5d5a13 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Thu, 4 Jun 2026 00:31:06 +0000 Subject: [PATCH 15/18] Relax near-one stable fit tolerances --- tests/distributions/test_stable_log_prob.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/distributions/test_stable_log_prob.py b/tests/distributions/test_stable_log_prob.py index 30be413f57..96b2a44ef0 100644 --- a/tests/distributions/test_stable_log_prob.py +++ b/tests/distributions/test_stable_log_prob.py @@ -129,8 +129,11 @@ def log_progress(): train(model, guide) # Verify fit accuracy - assert_close(alpha, pyro.param("alpha").item(), atol=0.04) - assert_close(beta, pyro.param("beta").item(), atol=0.06) + alpha_near_one = abs(alpha - 1.0) < 0.05 + alpha_atol = 0.1 if alpha_near_one else 0.04 + beta_atol = 0.12 if alpha_near_one else 0.06 + assert_close(alpha, pyro.param("alpha").item(), atol=alpha_atol) + assert_close(beta, pyro.param("beta").item(), atol=beta_atol) assert_close(c, pyro.param("c").item(), atol=0.2) assert_close(mu, pyro.param("mu").item(), atol=0.2) From 5507926736f9299922569cbe32fbe479478770f3 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Thu, 4 Jun 2026 02:53:31 +0000 Subject: [PATCH 16/18] Detach autoregressive Jacobian scalar --- tests/nn/test_autoregressive.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nn/test_autoregressive.py b/tests/nn/test_autoregressive.py index 573a015939..016c785df1 100644 --- a/tests/nn/test_autoregressive.py +++ b/tests/nn/test_autoregressive.py @@ -46,7 +46,7 @@ def nonzero(x): arn(x + 0.5 * epsilon_vector) - arn(x - 0.5 * epsilon_vector) ) / self.epsilon - jacobian[j, k] = float(delta[0, output_index, k]) + jacobian[j, k] = float(delta[0, output_index, k].detach()) permutation = arn.get_permutation() permuted_jacobian = jacobian.clone() From ff3dd899dd8bfdc9380d82fcf95fd86b32da2b1e Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Thu, 4 Jun 2026 13:34:35 +0000 Subject: [PATCH 17/18] Modernize tensor constructors --- examples/baseball.py | 4 +--- examples/vae/utils/mnist_cached.py | 6 +++--- pyro/contrib/examples/polyphonic_data_loader.py | 2 +- pyro/distributions/stable_log_prob.py | 4 ++-- .../distributions/transforms/block_autoregressive.py | 8 ++++---- .../transforms/generalized_channel_permute.py | 4 +--- pyro/distributions/transforms/householder.py | 2 +- pyro/distributions/transforms/matrix_exponential.py | 2 +- pyro/distributions/transforms/planar.py | 6 +++--- pyro/distributions/transforms/polynomial.py | 2 +- pyro/distributions/transforms/radial.py | 6 +++--- pyro/distributions/transforms/sylvester.py | 10 +++++----- pyro/infer/mcmc/api.py | 4 ++-- pyro/nn/auto_reg_nn.py | 2 +- pyro/ops/stats.py | 8 ++++---- tests/contrib/gp/test_models.py | 4 ++-- tests/distributions/test_delta.py | 2 +- tests/distributions/test_reshape.py | 2 +- tests/distributions/test_stable_log_prob.py | 2 +- tests/infer/autoguide/test_mean_field_entropy.py | 4 ++-- tests/infer/mcmc/test_nuts.py | 2 +- .../test_conjugate_gaussian_models.py | 4 ++-- tests/ops/test_stats.py | 8 ++++---- tests/optim/test_optim.py | 12 ++++++------ 24 files changed, 53 insertions(+), 57 deletions(-) diff --git a/examples/baseball.py b/examples/baseball.py index fe90355967..0585afe003 100644 --- a/examples/baseball.py +++ b/examples/baseball.py @@ -178,14 +178,12 @@ def train_test_split(pd_dataframe): Training data - 45 initial at-bats and hits for each player. Validation data - Full season at-bats and hits for each player. """ - device = torch.Tensor().device train_data = torch.tensor( - pd_dataframe[["At-Bats", "Hits"]].values, dtype=torch.float, device=device + pd_dataframe[["At-Bats", "Hits"]].values, dtype=torch.float ) test_data = torch.tensor( pd_dataframe[["SeasonAt-Bats", "SeasonHits"]].values, dtype=torch.float, - device=device, ) first_name = pd_dataframe["FirstName"].values last_name = pd_dataframe["LastName"].values diff --git a/examples/vae/utils/mnist_cached.py b/examples/vae/utils/mnist_cached.py index 212596fc20..603133fad3 100644 --- a/examples/vae/utils/mnist_cached.py +++ b/examples/vae/utils/mnist_cached.py @@ -182,9 +182,9 @@ def target_transform(y): self.data = MNISTCached.train_data_unsup # making sure that the unsupervised labels are not available to inference - self.targets = ( - torch.Tensor(MNISTCached.train_labels_unsup.shape[0]).view(-1, 1) - ) * np.nan + self.targets = torch.full( + (MNISTCached.train_labels_unsup.shape[0], 1), torch.nan + ) else: self.data, self.targets = ( MNISTCached.data_valid, diff --git a/pyro/contrib/examples/polyphonic_data_loader.py b/pyro/contrib/examples/polyphonic_data_loader.py index 7539d7627c..9adb90cd79 100644 --- a/pyro/contrib/examples/polyphonic_data_loader.py +++ b/pyro/contrib/examples/polyphonic_data_loader.py @@ -109,7 +109,7 @@ def load_data(dataset): torch.Tensor ) dset[k]["sequence_lengths"] = v["sequence_lengths"].to( - device=torch.Tensor().device + device=torch.get_default_device() ) return dset diff --git a/pyro/distributions/stable_log_prob.py b/pyro/distributions/stable_log_prob.py index d330bec4f9..adb1acbd10 100644 --- a/pyro/distributions/stable_log_prob.py +++ b/pyro/distributions/stable_log_prob.py @@ -20,8 +20,8 @@ def create_integrator(num_points): from scipy.special import roots_legendre roots, weights = roots_legendre(num_points) - roots = torch.Tensor(roots).double() - weights = torch.Tensor(weights).double() + roots = torch.as_tensor(roots) + weights = torch.as_tensor(weights) log_weights = weights.log() half_roots = roots * 0.5 diff --git a/pyro/distributions/transforms/block_autoregressive.py b/pyro/distributions/transforms/block_autoregressive.py index bdafb05d5b..2c7c1c2dff 100644 --- a/pyro/distributions/transforms/block_autoregressive.py +++ b/pyro/distributions/transforms/block_autoregressive.py @@ -121,7 +121,7 @@ def __init__( self._cached_logDetJ = None if residual == "gated": - self.gate = torch.nn.Parameter(torch.nn.init.normal_(torch.Tensor(1))) + self.gate = torch.nn.Parameter(torch.nn.init.normal_(torch.empty(1))) def _call(self, x): """ @@ -219,18 +219,18 @@ def __init__(self, in_features, out_features, dim, bias=True): i * out_features // dim : (i + 1) * out_features // dim, 0 : (i + 1) * in_features // dim, ] = torch.nn.init.xavier_uniform_( - torch.Tensor(out_features // dim, (i + 1) * in_features // dim) + torch.empty(out_features // dim, (i + 1) * in_features // dim) ) self._weight = torch.nn.Parameter(weight) self._diag_weight = torch.nn.Parameter( - torch.nn.init.uniform_(torch.Tensor(out_features, 1)).log() + torch.nn.init.uniform_(torch.empty(out_features, 1)).log() ) self.bias = ( torch.nn.Parameter( torch.nn.init.uniform_( - torch.Tensor(out_features), + torch.empty(out_features), -1 / math.sqrt(out_features), 1 / math.sqrt(out_features), ) diff --git a/pyro/distributions/transforms/generalized_channel_permute.py b/pyro/distributions/transforms/generalized_channel_permute.py index 1d2e733823..25526c2bad 100644 --- a/pyro/distributions/transforms/generalized_channel_permute.py +++ b/pyro/distributions/transforms/generalized_channel_permute.py @@ -269,9 +269,7 @@ def __init__(self, nn, channels=3, permutation=None): self.nn = nn self.channels = channels if permutation is None: - permutation = torch.randperm(channels, device="cpu").to( - torch.Tensor().device - ) + permutation = torch.randperm(channels) P = torch.eye(len(permutation), len(permutation))[ permutation.type(dtype=torch.int64) ] diff --git a/pyro/distributions/transforms/householder.py b/pyro/distributions/transforms/householder.py index 47183de925..a15422582e 100644 --- a/pyro/distributions/transforms/householder.py +++ b/pyro/distributions/transforms/householder.py @@ -145,7 +145,7 @@ def __init__(self, input_dim, count_transforms=1): count_transforms, input_dim ) ) - self.u_unnormed = nn.Parameter(torch.Tensor(count_transforms, input_dim)) + self.u_unnormed = nn.Parameter(torch.empty(count_transforms, input_dim)) self.reset_parameters() def reset_parameters(self): diff --git a/pyro/distributions/transforms/matrix_exponential.py b/pyro/distributions/transforms/matrix_exponential.py index 8b721f060d..4fd3cce50a 100644 --- a/pyro/distributions/transforms/matrix_exponential.py +++ b/pyro/distributions/transforms/matrix_exponential.py @@ -156,7 +156,7 @@ def __init__(self, input_dim, iterations=8, normalization="none", bound=None): iterations=iterations, normalization=normalization, bound=bound ) - self.weights = nn.Parameter(torch.Tensor(input_dim, input_dim)) + self.weights = nn.Parameter(torch.empty(input_dim, input_dim)) self.reset_parameters() def reset_parameters(self): diff --git a/pyro/distributions/transforms/planar.py b/pyro/distributions/transforms/planar.py index 0aab945e2c..d1337da44b 100644 --- a/pyro/distributions/transforms/planar.py +++ b/pyro/distributions/transforms/planar.py @@ -138,17 +138,17 @@ def __init__(self, input_dim): super().__init__(self._params) self.bias = nn.Parameter( - torch.Tensor( + torch.empty( 1, ) ) self.u = nn.Parameter( - torch.Tensor( + torch.empty( input_dim, ) ) self.w = nn.Parameter( - torch.Tensor( + torch.empty( input_dim, ) ) diff --git a/pyro/distributions/transforms/polynomial.py b/pyro/distributions/transforms/polynomial.py index ba765cc2cf..1b15e0e016 100644 --- a/pyro/distributions/transforms/polynomial.py +++ b/pyro/distributions/transforms/polynomial.py @@ -82,7 +82,7 @@ def __init__(self, autoregressive_nn, input_dim, count_degree, count_sum): self.count_sum = count_sum self._cached_logDetJ = None - self.c = nn.Parameter(torch.Tensor(input_dim)) + self.c = nn.Parameter(torch.empty(input_dim)) self.reset_parameters() # Vector of powers of input dimension diff --git a/pyro/distributions/transforms/radial.py b/pyro/distributions/transforms/radial.py index 98522d0dea..852550eddc 100644 --- a/pyro/distributions/transforms/radial.py +++ b/pyro/distributions/transforms/radial.py @@ -135,17 +135,17 @@ def __init__(self, input_dim): super().__init__(self._params) self.x0 = nn.Parameter( - torch.Tensor( + torch.empty( input_dim, ) ) self.alpha_prime = nn.Parameter( - torch.Tensor( + torch.empty( 1, ) ) self.beta_prime = nn.Parameter( - torch.Tensor( + torch.empty( 1, ) ) diff --git a/pyro/distributions/transforms/sylvester.py b/pyro/distributions/transforms/sylvester.py index a115873b90..34d9c9f2bc 100644 --- a/pyro/distributions/transforms/sylvester.py +++ b/pyro/distributions/transforms/sylvester.py @@ -61,11 +61,11 @@ def __init__(self, input_dim, count_transforms=1): super().__init__(input_dim, count_transforms) # Create parameters for Sylvester transform - self.R_dense = nn.Parameter(torch.Tensor(input_dim, input_dim)) - self.S_dense = nn.Parameter(torch.Tensor(input_dim, input_dim)) - self.R_diag = nn.Parameter(torch.Tensor(input_dim)) - self.S_diag = nn.Parameter(torch.Tensor(input_dim)) - self.b = nn.Parameter(torch.Tensor(input_dim)) + self.R_dense = nn.Parameter(torch.empty(input_dim, input_dim)) + self.S_dense = nn.Parameter(torch.empty(input_dim, input_dim)) + self.R_diag = nn.Parameter(torch.empty(input_dim)) + self.S_diag = nn.Parameter(torch.empty(input_dim)) + self.b = nn.Parameter(torch.empty(input_dim)) # Register masks and indices triangular_mask = torch.triu(torch.ones(input_dim, input_dim), diagonal=1) diff --git a/pyro/infer/mcmc/api.py b/pyro/infer/mcmc/api.py index 4808a7e924..2da7632e3c 100644 --- a/pyro/infer/mcmc/api.py +++ b/pyro/infer/mcmc/api.py @@ -108,8 +108,8 @@ def __init__( self.rng_seed = (torch.initial_seed() + chain_id) % MAX_SEED self.log_queue = log_queue self.result_queue = result_queue - self.default_dtype = torch.Tensor().dtype - self.default_device = torch.Tensor().device + self.default_dtype = torch.get_default_dtype() + self.default_device = torch.get_default_device() self.hook = hook self.event = event diff --git a/pyro/nn/auto_reg_nn.py b/pyro/nn/auto_reg_nn.py index 30d038aa39..2b5f594132 100644 --- a/pyro/nn/auto_reg_nn.py +++ b/pyro/nn/auto_reg_nn.py @@ -210,7 +210,7 @@ def __init__( if permutation is None: # By default set a random permutation of variables, which is important for performance with multiple steps - P = torch.randperm(input_dim, device="cpu").to(torch.Tensor().device) + P = torch.randperm(input_dim) else: # The permutation is chosen by the user P = permutation.type(dtype=torch.int64) diff --git a/pyro/ops/stats.py b/pyro/ops/stats.py index fbc17b47ce..95df78e0c1 100644 --- a/pyro/ops/stats.py +++ b/pyro/ops/stats.py @@ -283,11 +283,11 @@ def weighed_quantile( >>> from pyro.ops.stats import weighed_quantile >>> import torch - >>> input = torch.Tensor([[10, 50, 40], [20, 30, 0]]) - >>> probs = torch.Tensor([0.2, 0.8]) - >>> log_weights = torch.Tensor([0.4, 0.5, 0.1]).log() + >>> input = torch.tensor([[10.0, 50.0, 40.0], [20.0, 30.0, 0.0]]) + >>> probs = torch.tensor([0.2, 0.8]) + >>> log_weights = torch.tensor([0.4, 0.5, 0.1]).log() >>> result = weighed_quantile(input, probs, log_weights, -1) - >>> torch.testing.assert_close(result, torch.Tensor([[40.4, 47.6], [9.0, 26.4]])) + >>> torch.testing.assert_close(result, torch.tensor([[40.4, 47.6], [9.0, 26.4]])) """ dim = dim if dim >= 0 else (len(input.shape) + dim) if isinstance(probs, (list, tuple)): diff --git a/tests/contrib/gp/test_models.py b/tests/contrib/gp/test_models.py index e4c8231c2b..68e027eb85 100644 --- a/tests/contrib/gp/test_models.py +++ b/tests/contrib/gp/test_models.py @@ -349,9 +349,9 @@ def _pre_test_mean_function(): def f(x): return 2 * x + 3 + 5 * torch.sin(7 * x) - X = torch.arange(100, dtype=torch.Tensor().dtype) + X = torch.arange(100, dtype=torch.get_default_dtype()) y = f(X) - Xnew = torch.arange(100, 150, dtype=torch.Tensor().dtype) + Xnew = torch.arange(100, 150, dtype=torch.get_default_dtype()) ynew = f(Xnew) kernel = Cosine(input_dim=1) diff --git a/tests/distributions/test_delta.py b/tests/distributions/test_delta.py index 932a923d1b..fc34db1fba 100644 --- a/tests/distributions/test_delta.py +++ b/tests/distributions/test_delta.py @@ -19,7 +19,7 @@ def setUp(self): self.test_data = torch.tensor([[3.0], [3.0], [3.0]]) self.batch_test_data_1 = torch.arange(0.0, 4.0).unsqueeze(1).expand(4, 3) self.batch_test_data_2 = torch.arange(4.0, 8.0).unsqueeze(1).expand(4, 3) - self.batch_test_data_3 = torch.Tensor([[3.0], [3.0], [3.0], [3.0]]) + self.batch_test_data_3 = torch.tensor([[3.0], [3.0], [3.0], [3.0]]) self.expected_support = [[[0.0], [1.0], [2.0], [3.0]]] self.expected_support_non_vec = [[3.0]] self.analytic_mean = 3.0 diff --git a/tests/distributions/test_reshape.py b/tests/distributions/test_reshape.py index d0dbdce6dc..54ce2c83a4 100644 --- a/tests/distributions/test_reshape.py +++ b/tests/distributions/test_reshape.py @@ -151,5 +151,5 @@ def test_extra_event_dim_overflow(sample_dim, batch_dim, event_dim): def test_independent_entropy(): dist_univ = Bernoulli(0.5) - dist_multi = Bernoulli(torch.Tensor([0.5, 0.5])).to_event(1) + dist_multi = Bernoulli(torch.tensor([0.5, 0.5])).to_event(1) assert_equal(dist_multi.entropy(), 2 * dist_univ.entropy()) diff --git a/tests/distributions/test_stable_log_prob.py b/tests/distributions/test_stable_log_prob.py index 96b2a44ef0..c776331a42 100644 --- a/tests/distributions/test_stable_log_prob.py +++ b/tests/distributions/test_stable_log_prob.py @@ -42,7 +42,7 @@ def test_stable_gof(stability, skew): f"Calculating log-probability of (stablity={stability}, " f"skew={skew}) for {len(samples_scipy)} samples with scipy" ) - probs_scipy = torch.Tensor(dist_scipy.pdf(samples_scipy)) + probs_scipy = torch.as_tensor(dist_scipy.pdf(samples_scipy)) gof_scipy = auto_goodness_of_fit(samples_scipy, probs_scipy) assert gof_scipy > TEST_FAILURE_RATE logging.info( diff --git a/tests/infer/autoguide/test_mean_field_entropy.py b/tests/infer/autoguide/test_mean_field_entropy.py index 0558ef4604..ccfd2da8c8 100644 --- a/tests/infer/autoguide/test_mean_field_entropy.py +++ b/tests/infer/autoguide/test_mean_field_entropy.py @@ -28,8 +28,8 @@ def h(p): [ ( mean_field_guide, - (torch.Tensor([0.0]), None), - torch.Tensor([h(0.2) + h(0.5)]), + (torch.tensor([0.0]), None), + torch.tensor([h(0.2) + h(0.5)]), ), (mean_field_guide, (torch.eye(2), None), (h(0.2) + h(0.5)) * torch.ones(2, 2)), ], diff --git a/tests/infer/mcmc/test_nuts.py b/tests/infer/mcmc/test_nuts.py index 646f8e3b72..f86ab27c49 100644 --- a/tests/infer/mcmc/test_nuts.py +++ b/tests/infer/mcmc/test_nuts.py @@ -371,7 +371,7 @@ def _get_initial_trace(): def _generate_data(): transition_probs = torch.rand(dim, dim) - emissions_loc = torch.arange(dim, dtype=torch.Tensor().dtype) + emissions_loc = torch.arange(dim, dtype=torch.get_default_dtype()) emissions_scale = 1.0 state = torch.tensor(1) obs = [dist.Normal(emissions_loc[state], emissions_scale).sample()] diff --git a/tests/integration_tests/test_conjugate_gaussian_models.py b/tests/integration_tests/test_conjugate_gaussian_models.py index acb23da814..36748c6e67 100644 --- a/tests/integration_tests/test_conjugate_gaussian_models.py +++ b/tests/integration_tests/test_conjugate_gaussian_models.py @@ -510,11 +510,11 @@ def guide(self, reparameterized, model_permutation, difficulty=0.0): log_sig_node = pyro.param( "log_sig_" + node_suffix, -0.5 * torch.log(self.target_lambdas[node_suffix]) - + difficulty * (torch.Tensor([-0.3]) - 0.3 * (torch.randn(1) ** 2)), + + difficulty * (torch.tensor([-0.3]) - 0.3 * (torch.randn(1) ** 2)), ) mean_function_node = pyro.param( "constant_term_" + node, - self.loc0 + torch.Tensor([difficulty * i / n_nodes]), + self.loc0 + torch.tensor([difficulty * i / n_nodes]), ) for dep in deps: kappa_dep = pyro.param( diff --git a/tests/ops/test_stats.py b/tests/ops/test_stats.py index d52ea0f6f2..9418b3ddc1 100644 --- a/tests/ops/test_stats.py +++ b/tests/ops/test_stats.py @@ -62,11 +62,11 @@ def test_quantile(): @pytest.mark.init(rng_seed=3) def test_weighed_quantile(): # Fixed values test - input = torch.Tensor([[10, 50, 40], [20, 30, 0]]) + input = torch.tensor([[10.0, 50.0, 40.0], [20.0, 30.0, 0.0]]) probs = [0.2, 0.8] - log_weights = torch.Tensor([0.4, 0.5, 0.1]).log() + log_weights = torch.tensor([0.4, 0.5, 0.1]).log() result = weighed_quantile(input, probs, log_weights, -1) - assert_equal(result, torch.Tensor([[40.4, 47.6], [9.0, 26.4]])) + assert_equal(result, torch.tensor([[40.4, 47.6], [9.0, 26.4]])) # Random values test dist = torch.distributions.normal.Normal(0, 1) @@ -75,7 +75,7 @@ def test_weighed_quantile(): log_weights = dist.log_prob(input) result = weighed_quantile(input, probs, log_weights) result_dist = torch.distributions.normal.Normal(0, torch.tensor(0.5).sqrt()) - assert_equal(result, result_dist.icdf(torch.Tensor(probs)), prec=0.01) + assert_equal(result, result_dist.icdf(torch.tensor(probs)), prec=0.01) def test_pi(): diff --git a/tests/optim/test_optim.py b/tests/optim/test_optim.py index c0acefd7ef..06dfcc5a37 100644 --- a/tests/optim/test_optim.py +++ b/tests/optim/test_optim.py @@ -451,14 +451,14 @@ def test_centered_clipped_adam(plot): else: lr_vec = [0.1, 0.05, 0.02, 0.01, 0.005, 0.002, 0.001] - w = torch.Tensor([1, 500]) + w = torch.tensor([1.0, 500.0]) def loss_fn(p): return (1 + w * p * p).sqrt().sum() - len(w) def fit(lr, centered_variance, num_iter=5000): loss_vec = [] - p = torch.nn.Parameter(torch.Tensor([10, 1])) + p = torch.nn.Parameter(torch.tensor([10.0, 1.0])) optim = pyro.optim.clipped_adam.ClippedAdam( lr=lr, params=[p], centered_variance=centered_variance ) @@ -468,7 +468,7 @@ def fit(lr, centered_variance, num_iter=5000): loss.backward() optim.step() loss_vec.append(loss) - return torch.Tensor(loss_vec) + return torch.stack([loss.detach() for loss in loss_vec]) def calc_convergence(loss_vec, tail_len=100, threshold=0.01): """ @@ -498,8 +498,8 @@ def get_convergence_vec(lr_vec, centered_variance): convergence_rate_vec.append(convergence_rate) convergence_iter_vec.append(convergence_iter) return ( - torch.Tensor(ultimate_loss_vec), - torch.Tensor(convergence_rate_vec), + torch.stack(ultimate_loss_vec), + torch.stack(convergence_rate_vec), convergence_iter_vec, ) @@ -519,7 +519,7 @@ def get_convergence_vec(lr_vec, centered_variance): # Verify convergence rate improvement assert ( (centered_convergence_rate_vec / convergence_rate_vec) - > ((0.12 / torch.Tensor(lr_vec)).log() * 1.08) + > ((0.12 / torch.tensor(lr_vec)).log() * 1.08) ).all() if plot: From 5aea156116d1318a00ab7471e9f2d8cf76dabdc1 Mon Sep 17 00:00:00 2001 From: Yerdos Ordabayev Date: Thu, 4 Jun 2026 18:09:49 +0000 Subject: [PATCH 18/18] add back double() Signed-off-by: Yerdos Ordabayev --- pyro/distributions/stable_log_prob.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyro/distributions/stable_log_prob.py b/pyro/distributions/stable_log_prob.py index adb1acbd10..ddd022bbb6 100644 --- a/pyro/distributions/stable_log_prob.py +++ b/pyro/distributions/stable_log_prob.py @@ -20,8 +20,8 @@ def create_integrator(num_points): from scipy.special import roots_legendre roots, weights = roots_legendre(num_points) - roots = torch.as_tensor(roots) - weights = torch.as_tensor(weights) + roots = torch.as_tensor(roots).double() + weights = torch.as_tensor(weights).double() log_weights = weights.log() half_roots = roots * 0.5