Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Upgrade deprecated APIs in PyTorch 1.11 & clean out some legacy codes (
Browse files Browse the repository at this point in the history
…#1378)

Summary:
Pull Request resolved: #1378

PyTorch 1.11 was released last Thursday, which introduces a few Deprecation Warnings that were [caught by our CI](https://github.com/facebookresearch/beanmachine/runs/5507917348?check_suite_focus=true). This diff addresses those warnings by updating the relevant function calls.

It also caught my attention that some of the warnings come from our legacy inference module, which was kept around when we did the migration just in case "something happens." Now that the new inference has been out for a while, we can begin to clean out the legacy modules. In this diff I still kept some algorithms around because there are still some modules that depends on them -- in theory it should be safe to swap all of them out with the new implementation, though it's probably do that in a separate diff.

Reviewed By: jpchen

Differential Revision: D34833587

fbshipit-source-id: 6ef0456766236c9851ee079304dfd324b112f5a2
  • Loading branch information
horizon-blue authored and facebook-github-bot committed Mar 15, 2022
1 parent 99361b2 commit b13e4e3
Show file tree
Hide file tree
Showing 17 changed files with 9 additions and 2,177 deletions.
3 changes: 1 addition & 2 deletions src/beanmachine/ppl/experimental/tests/gp/inference_test.py
Expand Up @@ -14,7 +14,6 @@
from beanmachine.ppl.experimental.gp import likelihoods
from beanmachine.ppl.experimental.gp.kernels import PeriodicKernel, ScaleKernel
from beanmachine.ppl.experimental.gp.models import SimpleGP
from beanmachine.ppl.legacy.inference import SingleSiteNoUTurnSampler
from gpytorch.distributions import MultivariateNormal


Expand Down Expand Up @@ -78,7 +77,7 @@ def test_simple_regression(self):
self.lengthscale_prior(),
self.period_length_prior(),
]
samples = SingleSiteNoUTurnSampler().infer(
samples = bm.SingleSiteNoUTurnSampler().infer(
queries, obs, n_samples, num_chains=1
)

Expand Down
3 changes: 1 addition & 2 deletions src/beanmachine/ppl/experimental/tests/gp/models_test.py
Expand Up @@ -10,7 +10,6 @@
import torch.distributions as dist
from beanmachine.ppl.experimental.gp import kernels, likelihoods
from beanmachine.ppl.experimental.gp.models import BoTorchGP, SimpleGP
from beanmachine.ppl.legacy.inference import SingleSiteNoUTurnSampler
from botorch.posteriors.gpytorch import GPyTorchPosterior


Expand All @@ -34,7 +33,7 @@ def mean():

def test_infer(self):
self.model.train()
SingleSiteNoUTurnSampler().infer([self.p()], {}, num_samples=2, num_chains=1)
bm.SingleSiteNoUTurnSampler().infer([self.p()], {}, num_samples=2, num_chains=1)

def test_load_and_predict(self):
self.model.eval()
Expand Down
2 changes: 1 addition & 1 deletion src/beanmachine/ppl/experimental/tests/vi/vi_test.py
Expand Up @@ -450,7 +450,7 @@ def w():
def q_y():
weights = w()
data = x()
p = torch.sigmoid(data @ weights.T)
p = torch.sigmoid(data @ weights)
return dist.Bernoulli(p)

opt_params = VariationalInference().infer(
Expand Down
Expand Up @@ -137,11 +137,11 @@ def get_proposal_distribution(self, world: World) -> dist.Distribution:
# flip(flip(H^-1)) = flip((L^-1)') @ flip(L^-1)
# H^-1 = flip(L^-1)' @ flip(L^-1)
# flip(L^-1)' is the lower triangular cholesky factor for H^-1.
L_inv = torch.triangular_solve(
torch.eye(L.size(-1)).to(dtype=neg_hessian.dtype, device=node_device),
L_inv = torch.linalg.solve_triangular(
L,
torch.eye(L.size(-1)).to(dtype=neg_hessian.dtype, device=node_device),
upper=False,
).solution
)
L_chol = L_inv.flip([0, 1]).T
distance = torch.cholesky_solve(first_gradient.unsqueeze(1), L).t()
proposal_args = _ProposalArgs(
Expand Down
15 changes: 0 additions & 15 deletions src/beanmachine/ppl/legacy/inference/__init__.py
Expand Up @@ -8,33 +8,18 @@
from beanmachine.ppl.legacy.inference.single_site_ancestral_mh import (
SingleSiteAncestralMetropolisHastings,
)
from beanmachine.ppl.legacy.inference.single_site_hamiltonian_monte_carlo import (
SingleSiteHamiltonianMonteCarlo,
)
from beanmachine.ppl.legacy.inference.single_site_newtonian_monte_carlo import (
SingleSiteNewtonianMonteCarlo,
)
from beanmachine.ppl.legacy.inference.single_site_no_u_turn_sampler import (
SingleSiteNoUTurnSampler,
)
from beanmachine.ppl.legacy.inference.single_site_random_walk import (
SingleSiteRandomWalk,
)
from beanmachine.ppl.legacy.inference.single_site_uniform_mh import (
SingleSiteUniformMetropolisHastings,
)


__all__ = [
"CompositionalInference",
"RejectionSampling",
"SingleSiteAncestralMetropolisHastings",
"SingleSiteHamiltonianMonteCarlo",
"SingleSiteNewtonianMonteCarlo",
"SingleSiteNoUTurnSampler",
"SingleSiteRandomWalk",
"SingleSiteUniformMetropolisHastings",
"Predictive",
"empirical",
"simulate",
]
8 changes: 0 additions & 8 deletions src/beanmachine/ppl/legacy/inference/proposer/__init__.py
Expand Up @@ -9,17 +9,9 @@
from beanmachine.ppl.legacy.inference.proposer.single_site_newtonian_monte_carlo_proposer import (
SingleSiteNewtonianMonteCarloProposer,
)
from beanmachine.ppl.legacy.inference.proposer.single_site_no_u_turn_sampler_proposer import (
SingleSiteNoUTurnSamplerProposer,
)
from beanmachine.ppl.legacy.inference.proposer.single_site_uniform_proposer import (
SingleSiteUniformProposer,
)


__all__ = [
"SingleSiteAncestralProposer",
"SingleSiteNewtonianMonteCarloProposer",
"SingleSiteNoUTurnSamplerProposer",
"SingleSiteUniformProposer",
]

0 comments on commit b13e4e3

Please sign in to comment.