Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -31,6 +29,7 @@ jobs:
run: |
python -m pip install --upgrade pip wheel setuptools
pip install ruff black mypy nbstripout nbformat
pip install -e .

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added this so that the type checker can get dependency libraries stubs.

- name: Lint
run: |
make lint
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,7 +83,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
Expand Down
6 changes: 3 additions & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#
# 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
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will be pinned to a released funsor version before pyro release.

setuptools
sphinx_copybutton
4 changes: 2 additions & 2 deletions examples/air/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Processing Systems. 2016.
"""


import argparse
import math
import os
Expand All @@ -18,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

Expand Down Expand Up @@ -204,6 +202,8 @@ def z_pres_prior_p(opt_step, time_step):

# Viz sample from prior.
if args.viz:
import visdom

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Visdom is not actively supported - made the import lazy.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should we just replace this with some matplotlib equivalent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In another PR? This one already has a lot of changes


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))))
Expand Down
4 changes: 1 addition & 3 deletions examples/baseball.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The constructor should use the default device so no need to pass it.

)
first_name = pd_dataframe["FirstName"].values
last_name = pd_dataframe["LastName"].values
Expand Down
1 change: 1 addition & 0 deletions examples/contrib/cevae/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions examples/contrib/funsor/hmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/hmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/lda.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Pathwise gradients beyond the reparametrization trick"
https://arxiv.org/pdf/1806.01851.pdf
"""

import argparse
import functools
import logging
Expand Down
1 change: 1 addition & 0 deletions examples/rsa/schelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

Taken from: http://forestdb.org/models/schelling.html
"""

import argparse

import torch
Expand Down
1 change: 1 addition & 0 deletions examples/rsa/schelling_false.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

Taken from: http://forestdb.org/models/schelling-falsebelief.html
"""

import argparse

import torch
Expand Down
7 changes: 4 additions & 3 deletions examples/vae/ss_vae_M2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -246,10 +245,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
Expand Down Expand Up @@ -306,6 +305,8 @@ def main(args):

viz = None
if args.visualize:
from visdom import Visdom

viz = Visdom()
mkdir_p("./vae_results")

Expand Down
6 changes: 3 additions & 3 deletions examples/vae/utils/mnist_cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion examples/vae/vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -145,6 +144,8 @@ def main(args):

# setup visdom for visualization
if args.visdom_flag:
import visdom

vis = visdom.Visdom()

train_elbo = {}
Expand Down
2 changes: 1 addition & 1 deletion pyro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions pyro/contrib/autoname/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyro/contrib/autoname/named.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

Authors: Fritz Obermeyer, Alexander Rush
"""

import functools

import pyro
Expand Down
1 change: 1 addition & 0 deletions pyro/contrib/autoname/scoping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyro/contrib/cevae/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions pyro/contrib/epidemiology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__]
)
2 changes: 1 addition & 1 deletion pyro/contrib/examples/polyphonic_data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions pyro/contrib/funsor/handlers/enum_messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions pyro/contrib/gp/kernels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
]

# Create sphinx documentation.
__doc__ = "\n\n".join(
[
"""
__doc__ = "\n\n".join(["""
{0}
----------------------------------------------------------------
.. autoclass:: pyro.contrib.gp.kernels.{0}
Expand All @@ -63,9 +61,4 @@
:special-members: __call__
:show-inheritance:
:member-order: bysource
""".format(
_name
)
for _name in __all__
]
)
""".format(_name) for _name in __all__])
11 changes: 2 additions & 9 deletions pyro/contrib/gp/likelihoods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@


# Create sphinx documentation.
__doc__ = "\n\n".join(
[
"""
__doc__ = "\n\n".join(["""
{0}
----------------------------------------------------------------
.. autoclass:: pyro.contrib.gp.likelihoods.{0}
Expand All @@ -28,9 +26,4 @@
:special-members: __call__
:show-inheritance:
:member-order: bysource
""".format(
_name
)
for _name in __all__
]
)
""".format(_name) for _name in __all__])
1 change: 1 addition & 0 deletions pyro/contrib/minipyro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyro/contrib/timeseries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions pyro/distributions/spanning_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

NonLazyTensor doesn't exist in new gpytorch releases.

return log_det + log_diag[:-1].sum()

def log_prob(self, edges):
Expand Down
8 changes: 4 additions & 4 deletions pyro/distributions/stable_log_prob.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

keep doouble?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

roots_legendre returns float64 and torch.as_tensor preserves the double dtype.

weights = torch.as_tensor(weights)
log_weights = weights.log()
half_roots = roots * 0.5

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)]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In new pytorch releases list of tensors index gets wrapped in torch.tensor().

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()
)

Expand Down
Loading
Loading