diff --git a/src/beanmachine/ppl/experimental/inference_compilation/ic_infer.py b/src/beanmachine/ppl/experimental/inference_compilation/ic_infer.py index 688a0bbd15..1bfc93a285 100644 --- a/src/beanmachine/ppl/experimental/inference_compilation/ic_infer.py +++ b/src/beanmachine/ppl/experimental/inference_compilation/ic_infer.py @@ -117,6 +117,7 @@ def do_adaptation( loss = -(proposal_distribution.log_prob(node_var.value)) optimizer.zero_grad() loss.backward() + # pyre-fixme[20]: Argument `closure` expected. optimizer.step() @@ -419,7 +420,6 @@ def _proposer_func( raise Exception("No observation embedding network found!") obs_vec = torch.stack(obs_nodes, dim=0).flatten() - # pyre-fixme obs_embedding = obs_embedding_net.forward(obs_vec) node_embedding_nets = self._node_embedding_nets @@ -429,7 +429,6 @@ def _proposer_func( mb_embedding = torch.zeros(self._MB_EMBEDDING_DIM) mb_nodes = list( map( - # pyre-fixme[29]: `Union[Tensor, nn.Module]` is not a function. lambda mb_node: node_embedding_nets(mb_node).forward( utils.ensure_1d( world.get_node_in_world_raise_error(mb_node).value @@ -449,15 +448,11 @@ def _proposer_func( mb_vec = torch.stack(mb_nodes, dim=0).unsqueeze(1) # TODO: try pooling rather than just slicing out last hidden mb_embedding = utils.ensure_1d( - # pyre-fixme[29]: `Union[Tensor, nn.Module]` is not a function. - mb_embedding_nets(node) - .forward(mb_vec)[0][-1, :, :] - .squeeze() + mb_embedding_nets(node).forward(mb_vec)[0][-1, :, :].squeeze() ) node_proposal_param_nets = self._node_proposal_param_nets if node_proposal_param_nets is None: raise Exception("No node proposal parameter networks found!") - # pyre-fixme[29]: `Union[Tensor, nn.Module]` is not a function. param_vec = node_proposal_param_nets(node).forward( torch.cat((mb_embedding, obs_embedding)) ) @@ -475,9 +470,7 @@ def _proposal_distribution_for_node( """ node_var = self.world_.get_node_in_world_raise_error(node) distribution = node_var.distribution - # pyre-fixme sample_val = distribution.sample() - # pyre-fixme support = distribution.support ndim = sample_val.dim() diff --git a/src/beanmachine/ppl/experimental/neutra/iaflayer.py b/src/beanmachine/ppl/experimental/neutra/iaflayer.py index b62005fd5c..0f119c4b89 100644 --- a/src/beanmachine/ppl/experimental/neutra/iaflayer.py +++ b/src/beanmachine/ppl/experimental/neutra/iaflayer.py @@ -84,6 +84,10 @@ def __init__( self.loga_max_clip_ = loga_max_clip self.stable_ = stable + # pyre-fixme[14]: `get_parameter` overrides method defined in `Module` + # inconsistently. + # pyre-fixme[15]: `get_parameter` overrides method defined in `Module` + # inconsistently. def get_parameter(self, x: Tensor) -> Tuple[Tensor, Tensor]: """ diff --git a/src/beanmachine/ppl/experimental/neutra/maskedlinear.py b/src/beanmachine/ppl/experimental/neutra/maskedlinear.py index 72d16e862d..d739e8a35b 100644 --- a/src/beanmachine/ppl/experimental/neutra/maskedlinear.py +++ b/src/beanmachine/ppl/experimental/neutra/maskedlinear.py @@ -67,6 +67,7 @@ def set_mask(self, mask: Tensor) -> None: raise ValueError("Dimension mismatches between mask and layer.") self.mask.data.copy_(mask.t()) + # pyre-fixme[14]: `forward` overrides method defined in `Linear` inconsistently. def forward(self, input_: Tensor) -> Tensor: """ the forward method that does the masked linear computation diff --git a/src/beanmachine/ppl/experimental/vi/mean_field_variational_approximation.py b/src/beanmachine/ppl/experimental/vi/mean_field_variational_approximation.py index 163e00e230..8b95fa2341 100644 --- a/src/beanmachine/ppl/experimental/vi/mean_field_variational_approximation.py +++ b/src/beanmachine/ppl/experimental/vi/mean_field_variational_approximation.py @@ -63,7 +63,7 @@ def __init__( if not base_args: base_args = {} - event_shape = target_dist.event_shape # pyre-ignore[16] + event_shape = target_dist.event_shape # form independent product distribution of `base_dist` for `event_shape` if len(event_shape) == 0: self.base_args = base_args @@ -105,14 +105,14 @@ def _base_dist(**kwargs): ) # unwrap nested independents before setting transform - support = target_dist.support # pyre-ignore[16] + support = target_dist.support while isinstance(support, constraints.independent): support = support.base_constraint self._transform = biject_to(support) super().__init__( - self.new_dist.batch_shape, # pyre-ignore - self.new_dist.event_shape, # pyre-ignore + self.new_dist.batch_shape, + self.new_dist.event_shape, validate_args=validate_args, ) diff --git a/src/beanmachine/ppl/inference/compositional_infer.py b/src/beanmachine/ppl/inference/compositional_infer.py index 882c20322f..13dd8da453 100644 --- a/src/beanmachine/ppl/inference/compositional_infer.py +++ b/src/beanmachine/ppl/inference/compositional_infer.py @@ -59,7 +59,6 @@ def get_proposers( proposers = [] for node in target_rvs: if node not in self._proposers: - # pyre-ignore[16] support = world.get_variable(node).distribution.support if any( is_constraint_eq( diff --git a/src/beanmachine/ppl/inference/proposer/base_single_site_proposer.py b/src/beanmachine/ppl/inference/proposer/base_single_site_proposer.py index f94e7e597e..dfdc01db3e 100644 --- a/src/beanmachine/ppl/inference/proposer/base_single_site_proposer.py +++ b/src/beanmachine/ppl/inference/proposer/base_single_site_proposer.py @@ -32,7 +32,6 @@ def propose(self, world: World): """ proposal_dist = forward_dist = self.get_proposal_distribution(world) old_value = world[self.node] - # pyre-ignore[20] proposed_value = proposal_dist.sample() new_world = world.replace({self.node: proposed_value}) backward_dist = self.get_proposal_distribution(new_world) diff --git a/src/beanmachine/ppl/inference/proposer/single_site_random_walk_proposer.py b/src/beanmachine/ppl/inference/proposer/single_site_random_walk_proposer.py index 5f09cb18ee..4db964cc7b 100644 --- a/src/beanmachine/ppl/inference/proposer/single_site_random_walk_proposer.py +++ b/src/beanmachine/ppl/inference/proposer/single_site_random_walk_proposer.py @@ -44,7 +44,7 @@ def do_adaptation(self, world, accept_log_prob, *args, **kwargs) -> None: def get_proposal_distribution(self, world: World) -> dist.Distribution: """Propose a new value for self.node using the prior distribution.""" node = world.get_variable(self.node) - node_support = node.distribution.support # pyre-ignore [16] + node_support = node.distribution.support if is_constraint_eq(node_support, dist.constraints.real): return dist.Normal(node.value, self.step_size) diff --git a/src/beanmachine/ppl/inference/single_site_nmc.py b/src/beanmachine/ppl/inference/single_site_nmc.py index 41822e8b55..6587f42c8a 100644 --- a/src/beanmachine/ppl/inference/single_site_nmc.py +++ b/src/beanmachine/ppl/inference/single_site_nmc.py @@ -70,7 +70,7 @@ def _init_nmc_proposer(self, node: RVIdentifier, world: World) -> BaseProposer: of NMC proposer will be chosen based on a node's support. """ distribution = world.get_variable(node).distribution - support = distribution.support # pyre-ignore + support = distribution.support if is_constraint_eq(support, dist.constraints.real): return SingleSiteRealSpaceNMCProposer(node, self.alpha, self.beta) elif is_constraint_eq(support, dist.constraints.greater_than): diff --git a/src/beanmachine/ppl/legacy/inference/proposer/single_site_newtonian_monte_carlo_proposer.py b/src/beanmachine/ppl/legacy/inference/proposer/single_site_newtonian_monte_carlo_proposer.py index ccc48a8aa0..f4c6ebbfba 100644 --- a/src/beanmachine/ppl/legacy/inference/proposer/single_site_newtonian_monte_carlo_proposer.py +++ b/src/beanmachine/ppl/legacy/inference/proposer/single_site_newtonian_monte_carlo_proposer.py @@ -89,7 +89,6 @@ def get_proposal_distribution( that was used or needs to be used to find the proposal distribution """ if node not in self.proposers_: - # pyre-fixme node_distribution_support = node_var.distribution.support if world.get_transforms_for_node( node diff --git a/src/beanmachine/ppl/legacy/inference/proposer/single_site_random_walk_proposer.py b/src/beanmachine/ppl/legacy/inference/proposer/single_site_random_walk_proposer.py index 6f1c8180ab..ebc175d3c3 100644 --- a/src/beanmachine/ppl/legacy/inference/proposer/single_site_random_walk_proposer.py +++ b/src/beanmachine/ppl/legacy/inference/proposer/single_site_random_walk_proposer.py @@ -108,7 +108,6 @@ def get_proposal_distribution( if world.get_transforms_for_node( node ).transform_type != TransformType.NONE or is_constraint_eq( - # pyre-fixme node_distribution.support, dist.constraints.real, ): diff --git a/src/beanmachine/ppl/legacy/inference/proposer/single_site_uniform_proposer.py b/src/beanmachine/ppl/legacy/inference/proposer/single_site_uniform_proposer.py index 24f4f2da2e..96e9ff1b27 100644 --- a/src/beanmachine/ppl/legacy/inference/proposer/single_site_uniform_proposer.py +++ b/src/beanmachine/ppl/legacy/inference/proposer/single_site_uniform_proposer.py @@ -46,7 +46,6 @@ def get_proposal_distribution( node_distribution = node_var.distribution if ( is_constraint_eq( - # pyre-fixme node_distribution.support, dist.constraints.boolean, ) diff --git a/src/beanmachine/ppl/legacy/world/variable.py b/src/beanmachine/ppl/legacy/world/variable.py index 6a2064ebca..20072ca7c6 100644 --- a/src/beanmachine/ppl/legacy/world/variable.py +++ b/src/beanmachine/ppl/legacy/world/variable.py @@ -94,7 +94,6 @@ def bar(self): @property def is_discrete(self) -> bool: - # pyre-fixme return self.distribution.support.is_discrete def __post_init__(self) -> None: diff --git a/src/beanmachine/ppl/world/utils.py b/src/beanmachine/ppl/world/utils.py index 915f22c57e..e2e783529f 100644 --- a/src/beanmachine/ppl/world/utils.py +++ b/src/beanmachine/ppl/world/utils.py @@ -101,7 +101,6 @@ def get_default_transforms(distribution: Distribution) -> dist.Transform: :returns: a Transform that need to be applied to the distribution to transform it from constrained space into unconstrained space """ - # pyre-fixme if distribution.support.is_discrete: return dist.transforms.identity_transform else: @@ -115,11 +114,9 @@ def initialize_value(distribution: Distribution, initialize_from_prior: bool = F :param initialize_from_prior: if true, returns sample from prior :returns: the value to the set the Variable value to """ - # pyre-fixme sample_val = distribution.sample() if initialize_from_prior: return sample_val - # pyre-fixme support = distribution.support if isinstance(support, dist.constraints.independent): support = support.base_constraint diff --git a/src/beanmachine/ppl/world/world.py b/src/beanmachine/ppl/world/world.py index 5f49b7c979..4b08433d42 100644 --- a/src/beanmachine/ppl/world/world.py +++ b/src/beanmachine/ppl/world/world.py @@ -206,10 +206,8 @@ def enumerate_node(self, node: RVIdentifier) -> torch.Tensor: A tensor enumerating the support of the node. """ distribution = self._variables[node].distribution - # pyre-ignore[16] if not distribution.has_enumerate_support: raise ValueError(str(node) + " is not enumerable") - # pyre-ignore[16] return distribution.enumerate_support() def _run_node(