-
Notifications
You must be signed in to change notification settings - Fork 104
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
sigma type & doc #72
sigma type & doc #72
Conversation
Hello Guillaume! Thanks for the PR. I think the sigma type should be checked for all classes... That includes OT-CFM, SB-CFM, FM, Stochastic Interpolants. @josephdviviano what do you think? We want to ensure that sigma is a float as when it is an int, we get a bug. |
I think we want to make sure |
@atong01 I just tested it, and it is working with float64 even if sigma is initialized as int, float or tensor (32 or 64). |
@atong01 Maybe a better solution would be to make the type of sigma_t to match the type of x within the |
But they already have the same type, since torch works with mixed precision. conditional-flow-matching/torchcfm/conditional_flow_matching.py Lines 34 to 36 in 21cd0c8
A simple fix is replacing L34 with |
I think I don't fully understand how the code works. Just a moment. But initial thoughts:
|
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.
I'm not entirely sure what the correct solution is but I don't want part of it to include the type casting in the @property
, sorry to be annoying about this.
@@ -54,7 +54,14 @@ def __init__(self, sigma: float = 0.0): | |||
---------- | |||
sigma : float | |||
""" | |||
self.sigma = sigma | |||
self._sigma = sigma |
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.
Why aren't we enforcing the type here?
My concern is that self.sigma != self._sigma
, which will lead to very very confusing bugs.
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.
I agree with @atong01 - you can use x
to typecast all other variables if required so that types don't change magically for the user. I stand by what I said before though, I.e., sigma should be enforced to be a particular type if required, and the property should not do any typecasting.
if isinstance(self._sigma, int): | ||
return float(self._sigma) | ||
else: | ||
return self._sigma |
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.
I don't think we should do this for reasons I've explained -- I think it is confusing. If we need sigma to always be a float we should typecast/typecheck in the init, or, we should write the logic such that for any input, the typing is conserved.
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.
Yes good point, I agree that it becomes confusing. I think we should just fix L34 mentioned above, as it does not work for type(t) = int
, this way we don't have to typecheck sigma in the init or with the @property
.
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.
OK. I'm not sure if this is intentional but you are type checking sigma
-- maybe you want to remove this as well?
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.
I just changed it, thanks for pointing it out.
I let @josephdviviano decide when this PR is ready as he has more knowledge than me on how to fix a variable's type. @guillaumehu once this PR is ready, please prepare a test to add to the add_tests branch (or to this PR but I would prefer all tests within the same PR). I have made tests for all classes within torchcfm and we need a test on sigma's type as well. |
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.
Approved with a comment :)
""" | ||
self._sigma = sigma | ||
|
||
@property |
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 good. One comment - the @property
method is useful for allowing one to "get" a variable, without allowing the user to change it. So if someone did
obj = FlowMatcher(sigma=1.0)
obj.sigma = 2
they would get an error. They could be doing something like obj._sigma = 2
to overwrite the property, but they would be very intentionally doing this. So it's mostly a way of telling the user how to not shoot themselves in the foot.
If you think it would be bad practice for people to be overwriting the obj.sigma
property, then adding the @property
logic back in still makes sense (sans the type casting).
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.
Thank you @josephdviviano for the clarification! I am not sure what is the best for sigma, I think it is fine for now if we keep it like this, but happy to make the change if someone thinks otherwise.
Adding docstrings for the
__init__
ofOTPlanSampler
, and fixing issue #56 by checking the type of sigma during initialization.