-
Notifications
You must be signed in to change notification settings - Fork 246
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
Add default values to constraints to make grad propogate properly #872
Conversation
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 is a great idea, especially since constraints do the checking.
Could I suggest a different interface, so as to be compatible with PyTorch, where we might need to know precision and device placement?
class Constraint:
def default_like(self, prototype):
raise NotImplementedError
class Positive(Constraint):
def default_like(self, prototype):
return np.ones(prototype.shape, dtype=prototype.dtype)
This is similar to torch.zeros_like()
and similar functions. If you're ok with this, I'd like to copy this pattern in PyTorch/Pyro. We could alternatively name this .feasible_like()
.
Thanks, @fritzo! I'll update the api. It looks reasonable to me. |
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.
Hmm I think I prefer .feasible_like()
over .default_like()
, since the former evokes the language of constraints. @fehiepsi do you have a preference?
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! Mind if I port these to PyTorch, or would you like to?
Thanks for reviewing and valuable feedbacks, @fritzo! I would appreciate if you port those to PyTorch. :) |
Fixes #871.
In pyro-ppl/pyro#2447, @fritzo proposed to implement a safe_mask function, but it seems to me that this is an easier to implement solution.