-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[WIP] Make SGD support Cython fused types #6889
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
Conversation
What's interesting about this error is that it gets triggered for |
would be neat to have this @yenchenlin for looking into it |
Hello @agramfort, @jnothman and @MechCoder, I've created a small example here, Any idea? |
I'll have a detailed look soon but it seems fused types and inheritance in Cython don't go well together. See https://groups.google.com/forum/#!topic/cython-users/HPgmlIMabz0 |
Can someone come up with a better idea other than duplication of |
|
Ah, no. It fails at C compilation with just the pyx. |
@yenchenlin @jnothman What do you think of this approach? cdef class LossFunction:
cdef float float_loss(self, float p, float y) nogil:
return 0.
cdef double double_loss(self, double p, double y) nogil:
return 0.
cdef class DerivedLossFunction(LossFunction):
cdef floating _loss(floating p, floating y) nogil:
if floating is float:
....
else:
....
cdef float float_loss(self, float p, float y) nogil:
return _loss(p, y)
cdef double double_loss(self, double p, double y) nogil:
return _loss(p, y) And then in (Of course, this means the method signatures are duplicated twice, but SGD is commonly used and hence it might be worth it) |
As I pointed out in hangouts, I don't think we need fused type support for the loss functions. We need fused type support for |
Also, do we really care that |
Our comments overlapped, but the implication is: no, we don't care. |
@yenchenlin Could you let us know how difficult / easy it is for the fused type support for the |
I suspect we'll find we need to use a templated |
@MechCoder sorry to see this now. Will do! |
I wonder if the situation improved since: this was with Cython ~ v0.20 (also confirmed in v0.23dev) and we are now at v0.28.. Update (2019): It didn't. |
To follow-up with @yenchenlin's experiments:
I have been able to compile your project after having changed Still I get a similar problem when recompiling this branch after rebasing on
To follow up with @rth's comment:
Some problems might have been addressed in the latest release, for instance the ones of the thread mentioned by @MechCoder. |
As #13243 implemented a template for |
Current implementation of
SGDClassifier
andSGDRegressor
doesn't allow the user to specify thedtype
they want and may cause aMemoryError
when the user wants to train the model since it will try to copy input data intonp.float64
. (See #5776).To address the problem, this PR wants to make SGD related algorithms in scikit-learn supports Cython fused types.