-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix lint formatting and mypy checks #3453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
52ae7d4
a4cdef1
afdc732
5f3e3f7
b40db87
b6814a0
850c82c
fb8668c
524b979
b06eb00
ea50d79
5c698ff
f4709fb
c99a897
c0ee224
5507926
ff3dd89
5aea156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ | |
| Processing Systems. 2016. | ||
| """ | ||
|
|
||
|
|
||
| import argparse | ||
| import math | ||
| import os | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -204,6 +202,8 @@ def z_pres_prior_p(opt_step, time_step): | |
|
|
||
| # Viz sample from prior. | ||
| if args.viz: | ||
| import visdom | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Visdom is not actively supported - made the import lazy.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we just replace this with some matplotlib equivalent?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)))) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
|
|
||
| Taken from: http://forestdb.org/models/schelling.html | ||
| """ | ||
|
|
||
| import argparse | ||
|
|
||
| import torch | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
|
|
||
| Taken from: http://forestdb.org/models/schelling-falsebelief.html | ||
| """ | ||
|
|
||
| import argparse | ||
|
|
||
| import torch | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ | |
|
|
||
| Authors: Fritz Obermeyer, Alexander Rush | ||
| """ | ||
|
|
||
| import functools | ||
|
|
||
| import pyro | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return log_det + log_diag[:-1].sum() | ||
|
|
||
| def log_prob(self, edges): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep doouble?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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)] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In new pytorch releases list of tensors index gets wrapped in |
||
| 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() | ||
| ) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.