-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Sag handle numerical error outside of cython #13389
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
Sag handle numerical error outside of cython #13389
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.
looks good.
just a couple of minor comments.
Also can you run the benchmark #13316 with this change ?
sklearn/linear_model/sag_fast.pyx.tp
Outdated
Hide resolved
Running the same #13316 benchmark, I now get:
|
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
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
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 really weird performance bug. Have you tried to re-run your benchmark with this PR to confirm that it fixes the performance issue observed with the threading backend?
Can you try to compile this extension without branch prediction to confirm that the GIL acquisition is caused by this as suggested in #13316 (comment)? That sounds really weird to me.
just look a bit above :) |
This is strange indeed but if you comment the if something_not_finite:
with gil:
raise error bloks, the issue disappears, although the condition is never met (because no error is raised) |
@ogrisel I tried disabling scikit-learn/sklearn/linear_model/sgd_fast.pyx Lines 758 to 762 in 7b26762
then further along the way: scikit-learn/sklearn/linear_model/sgd_fast.pyx Lines 795 to 798 in 7b26762
|
these are just hints but I think it does not disable branch prediction. Branch prediction is done by the cpu. I can't see how to disable it. |
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.
nitpick but otherwise looks good to me!
I suppose we might want to set prefer="threads"
for LogisticRegressionCV
when the saga solver is used but this should probably be done elsewhere.
So much better. Thank you @pierreglaser |
)" This reverts commit b6c2b95.
)" This reverts commit b6c2b95.
Closes #13316
Cython's gcc branch prediction directive make
sag
unnecessarily fight for the GIL at a high frequency in case an error needs to be raised. This severely impacts the performance of parallelsag
calls using ajoblib
"threading"
backend.I propose to handle numerical error "C-style", by propagating return codes and breaking out of for-loops. An error is raised once and for all after
sag
, insag_solver
.Note that I need to manually break out of for-loops and not simply return -1 after the check, as returning requires the GIL, so the same problem would happen.
@jeremiedbb followed the issue during last sprint.