Skip to content
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

Fix Segmentation Fault and ZeroDivisionError in Group Lasso #292

Merged
merged 17 commits into from
Apr 8, 2024

Conversation

Badr-MOUFAD
Copy link
Collaborator

Context

I run unittest of skglm and got an error for celer namely segmentation fault.
The tests were run on a Mac. Surprisingly, the problem doesn't arise for Linux (no errors in skglm CI)

Contributions of the PR

After debugging, the segmentation fault (out of bound index) comes from an un initialized variable.
Other errors, due to changes of scikit-learn API, were fixed as well.

@@ -418,8 +418,11 @@ cpdef celer_grp(
&inc) / lc_groups[g]
norm_wg += w[j] ** 2
norm_wg = sqrt(norm_wg)
bst_scal = max(0.,
if norm_wg != 0.:
bst_scal = max(0.,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm perhaps lacking context about the code, namely I ignore the purpose of bst_scal.

I just followed commun sense to handle the case of norm w being zero.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bst_scal is for BockSofthThresholding scaling : the formula for the BST of wg at level lambda is:
wg * max(0, 1 - lambda / norm(wg)) aka 0 if norm(wg) < lambda, and (1 - lambda/norm(wg)) wg otherwise

I'm curious, how do you end up with a vanishing wg after a gradient step ? This should not happen with probability 1, I'm guessing a 0 group X_g ?

@@ -89,7 +89,7 @@ cpdef floating dnorm_grp(

else: # scaling only with features in C
for g_idx in range(ws_size):
if weights[g] == INFINITY:
if weights[g_idx] == INFINITY:
continue

g = C[g_idx]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure that it's not g (defined L95, so def should be moved above) which should be used here? weights has size n_groups, not ws_size

Copy link
Collaborator Author

@Badr-MOUFAD Badr-MOUFAD Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right,
We can insert line 95 right after Line 91 and keep the rest as it is

@codecov-commenter
Copy link

codecov-commenter commented Mar 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.53%. Comparing base (c1b564c) to head (138bd97).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #292   +/-   ##
=======================================
  Coverage   88.53%   88.53%           
=======================================
  Files          15       15           
  Lines        1143     1143           
  Branches      127      127           
=======================================
  Hits         1012     1012           
  Misses        101      101           
  Partials       30       30           
Flag Coverage Δ
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
celer/dropin_sklearn.py 95.95% <ø> (ø)
celer/tests/test_mtl.py 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1b564c...138bd97. Read the comment docs.

@Badr-MOUFAD
Copy link
Collaborator Author

@mathurinm, don't mind the 10 files diff, it is just GitHub glitch

@mathurinm
Copy link
Owner

@Badr-MOUFAD my solution in that case is to merge main into the branch, now it is reduced to 3 files

@mathurinm mathurinm merged commit 1df21cf into mathurinm:main Apr 8, 2024
6 checks passed
@mathurinm
Copy link
Owner

Thanks @Badr-MOUFAD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants