-
Notifications
You must be signed in to change notification settings - Fork 60
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
NumberProxy is no Number #272
Comments
Makes total sense to me to follow lightning-thunder/thunder/core/jit_ext.py Lines 708 to 712 in 2578766
|
Removing the base types could require developers think carefully about their code and might remove the opportunity for some errors. I see a couple challenges with actually doing this:
There is already some code today that explicitly reasons about NumberProxies vs. Numbers, and it just queries for an object being a NumberProxy first. I guess what motivates this is that there'd be no opportunity to mistakenly identify a NumberProxy as a Number, and all the conversions to a Number would have to be explicit? |
That's a good point and I don't know the answer there yet. I would hope that it's just going to be some type check changes, which is what I'm pushing for in this issue anyway.
This sounds like a very reasonable thing to add.
Yes that's the intention. It's too easy for existing code base to accidentally treat NumberProxy as a number. |
Sounds good! I think trying it and seeing what breaks would be a good start |
In the prototype PR #262 I managed to pass the CI at least. But there's a few hacky things I did that I'm not super happy with.
Two trickier topic:
|
What about supporting
It would also be very surprising to me if these changes were causing OOMs because they shouldn't use any device memory |
I think you mean It's common to have something like |
Yep! We're on the same page.
I think so? This might be best to review over a VC with a shared Colab notebook! |
Fixes #272. Changes in this PR: Removing the inheritance of Number kinds in NumberProxy derivatives. The motivation is to avoid mistakenly identify a NumberProxy as Numbers. Specifically, we are removing complex / int / float from the inheritance of ComplexProxy / IntegerProxy / FloatProxy. changing existing checks from isinstance(x, Number) to isinstance(x, (Number, NumberProxy)). Handling proper type promotion in NumberProxy's binary/unary operations. Co-authored-by: Thomas Viehmann <tv@beamnet.de>
🚀 Feature
Derivatives of
NumberProxy
should not inherit fromNumber
directly.Motivation
It's error prone to have derivatives of
NumberProxy
identified asNumber
at the same time. We would want to identifyNumberProxy
as dynamic value, so interpreter would know not to bake in numbers or accidentally constant fold things away.Pitch
We should remove the inheritance of
float
fromFloatProxy
here:lightning-thunder/thunder/core/proxies.py
Line 973 in 34d21e1
Same thing would apply to
IntegerProxy
/ComplexProxy
. After this change, we will be able to distinguishNumberProxy
from constant number in the program.Alternatives
Alternative: we'll have to update existing checks where
isinstance(x, Number)
tonot isinstance(x, NumberProxy) and isinstance(x, Number)
to properly identify runtime values. The worse part is, if we miss anything in the code base, it'll ended up as an unintended behavior (like bake in static number) and possibly a silent wrong result.comparing to the proposed approach here, if we change the inheritance hierarchy, existing legacy check
isinstance(x, Number)
would return false and we would NOT treating aNumberProxy
as a regular compile time constant. This likely would lead us to some different code path where we'll try to use it as aTensorProxy
instead, that'll give us an exception, which is much easier to patch.Additional context
This is an incremental work supporting #262
The text was updated successfully, but these errors were encountered: