-
-
Notifications
You must be signed in to change notification settings - Fork 986
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
Type annotate broadcast, condition, do, enum messengers #3295
Conversation
@@ -76,7 +78,11 @@ def _pyro_sample(self, msg): | |||
intervention = self.data[msg["name"]] | |||
msg["name"] = msg["name"] + "__CF" # mangle old name | |||
|
|||
if isinstance(intervention, (numbers.Number, torch.Tensor)): | |||
if isinstance(intervention, numbers.Number): | |||
msg["value"] = torch.tensor(intervention) |
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.
It might be a good idea to constrain msg["value"]
to be torch.Tensor
because in many places it is expected to be a torch.Tensor
by attempting to access torch.Tensor
attributes.
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.
@eb8680 can you make sure this is safe? We don't want to break any Chirho code.
|
||
# if this site has any ancestors, choose ancestors from diagonal approximation | ||
thin_sample = fat_sample | ||
if thin_sample.shape != target_shape: | ||
index = [Ellipsis] + [slice(None)] * (len(thin_sample.shape) - 1) | ||
index: List[Any] = [Ellipsis] + [slice(None)] * (len(thin_sample.shape) - 1) |
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.
This can be narrowed down once we annotate Vindex
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.
Looks great, and like it was hard work getting this to check. typing_extensions
sure makes things easy.
I just have a couple comments about change paranoia.
@@ -27,7 +28,7 @@ class TorchDistributionMixin(Distribution): | |||
from :class:`TorchDistributionMixin`. | |||
""" | |||
|
|||
def __call__(self, sample_shape: torch.Size = torch.Size()) -> torch.Tensor: | |||
def __call__(self, sample_shape: Tuple[int] = torch.Size()) -> torch.Tensor: |
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.
Are you sure this is safe? There are a few places in Pyro where an actual torch.Size
object is required, as it has special methods like .numel
. Just checking 🙂
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.
Actually, not sure about it. Changed it back and adjusted elsewhere to convert tuple arguments into torch.Size
@@ -76,7 +78,11 @@ def _pyro_sample(self, msg): | |||
intervention = self.data[msg["name"]] | |||
msg["name"] = msg["name"] + "__CF" # mangle old name | |||
|
|||
if isinstance(intervention, (numbers.Number, torch.Tensor)): | |||
if isinstance(intervention, numbers.Number): | |||
msg["value"] = torch.tensor(intervention) |
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.
@eb8680 can you make sure this is safe? We don't want to break any Chirho code.
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.
LGTM, @ordabayevy is this ready to merge?
No description provided.