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 categorical test in python #4326

Merged
merged 10 commits into from
Nov 15, 2021

Conversation

levsnv
Copy link
Contributor

@levsnv levsnv commented Nov 4, 2021

Current test has three issues in categorical data generation:

  1. train data and test data are numerically very different. In this case, during testing, only the first few categories are exercised (low sensitivity)
  2. during categorical conversion, columns are normalized row-wise instead of feature-wise. It doesn't lead to significantly different results, but just doesn't make sense
  3. test data does not contain invalid categories

This PR fully fixes 1. and 2 and partially fixes 3.
Since FIL currently does not handle all kinds of invalid categories gracefully, only test ones it can so far.

The test can be tested by the following changes:

--- a/cpp/src/fil/internal.cuh
+++ b/cpp/src/fil/internal.cuh
@@ -348,7 +348,7 @@ struct categorical_sets {
     // features with similar categorical feature count, we may consider
     // storing node ID within nodes with same feature ID and look up
     // {.max_matching, .first_node_offset} = ...[feature_id]
-    return category <= max_matching[node.fid()] && fetch_bit(bits + node.set(), category);
+    return category <= max_matching[node.fid()] ? fetch_bit(bits + node.set(), category) : 1;
   }
   static int sizeof_mask_from_max_matching(int max_matching)
   {

This will help test #4314

@levsnv levsnv requested a review from a team as a code owner November 4, 2021 07:23
@levsnv levsnv requested a review from canonizer November 4, 2021 07:23
@github-actions github-actions bot added the Cython / Python Cython or Python issue label Nov 4, 2021
@levsnv levsnv added non-breaking Non-breaking change tests Unit testing for project labels Nov 4, 2021
@levsnv levsnv added Tech Debt Issues related to debt bug Something isn't working labels Nov 4, 2021
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
@dantegd
Copy link
Member

dantegd commented Nov 4, 2021

rerun tests

python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
@levsnv levsnv added 4 - Waiting on Author Waiting for author to respond to review and removed 4 - Waiting on Reviewer Waiting for reviewer to review or respond labels Nov 8, 2021
@caryr35 caryr35 added this to PR-WIP in v21.12 Release via automation Nov 8, 2021
@caryr35 caryr35 moved this from PR-WIP to PR-Needs review in v21.12 Release Nov 8, 2021
@levsnv levsnv requested a review from canonizer November 9, 2021 04:09
@levsnv levsnv removed the 4 - Waiting on Author Waiting for author to respond to review label Nov 9, 2021
@levsnv levsnv added the 4 - Waiting on Reviewer Waiting for reviewer to review or respond label Nov 9, 2021
Copy link
Contributor

@canonizer canonizer left a comment

Choose a reason for hiding this comment

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

Approved, provided that the comments are addressed.

There are still many comments, but they are mostly technical and about documentation.

python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
python/cuml/test/test_fil.py Outdated Show resolved Hide resolved
@dantegd
Copy link
Member

dantegd commented Nov 10, 2021

rerun tests

@levsnv levsnv added 3 - Ready for Review Ready for review by team 4 - Waiting on Author Waiting for author to respond to review and removed 4 - Waiting on Reviewer Waiting for reviewer to review or respond 3 - Ready for Review Ready for review by team labels Nov 11, 2021
@levsnv
Copy link
Contributor Author

levsnv commented Nov 11, 2021

I need to fix the lightgbm test failures

@levsnv levsnv removed the 4 - Waiting on Author Waiting for author to respond to review label Nov 12, 2021
@levsnv
Copy link
Contributor Author

levsnv commented Nov 12, 2021

rerun tests

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (branch-21.12@cfd536c). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff               @@
##             branch-21.12    #4326   +/-   ##
===============================================
  Coverage                ?   85.99%           
===============================================
  Files                   ?      231           
  Lines                   ?    18714           
  Branches                ?        0           
===============================================
  Hits                    ?    16093           
  Misses                  ?     2621           
  Partials                ?        0           
Flag Coverage Δ
dask 46.96% <0.00%> (?)
non-dask 78.68% <0.00%> (?)

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


Continue to review full report at Codecov.

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

v21.12 Release automation moved this from PR-Needs review to PR-Reviewer approved Nov 15, 2021
@wphicks
Copy link
Contributor

wphicks commented Nov 15, 2021

@gpucibot merge

@rapids-bot rapids-bot bot merged commit f4c098c into rapidsai:branch-21.12 Nov 15, 2021
v21.12 Release automation moved this from PR-Reviewer approved to Done Nov 15, 2021
rapids-bot bot pushed a commit that referenced this pull request Nov 15, 2021
…provided to FIL model (#4314)

Fix potential CUDA context poison due to invalid global read when negative categories provided at inference:

now equivalent to non-matching.
FIL now converts dummy nodes to numerical on import
and never generates max_matching == -1 categorical features in test.
FIL will still generate empty categorical nodes in test (a non-empty bits vector which contains only zeros), export them as dummy numerical nodes and import again as dummy numerical nodes. If a feature only contains dummy numerical nodes, it will be deemed a numerical feature (same as for non-dummy numerical nodes or a mix thereof). Therefore, categorical feature max_matching == -1 is still prevented.

CI failures
```
Test Result (2 failures / +2)
cuml.test.test_fil.test_lightgbm[5-2]
cuml.test.test_fil.test_lightgbm[5-5]
```
will be resolved by #4326

Authors:
  - Levs Dolgovs (https://github.com/levsnv)

Approvers:
  - Andy Adinets (https://github.com/canonizer)
  - William Hicks (https://github.com/wphicks)

URL: #4314
vimarsh6739 pushed a commit to vimarsh6739/cuml that referenced this pull request Oct 9, 2023
Current test has three issues in categorical data generation:
1. train data and test data are numerically very different. In this case, during testing, only the first few categories are exercised (low sensitivity)
2. during categorical conversion, columns are normalized row-wise instead of feature-wise. It doesn't lead to significantly different results, but just doesn't make sense
3. test data does not contain invalid categories

This PR fully fixes 1. and 2 and partially fixes 3.
Since FIL currently does not handle all kinds of invalid categories gracefully, only test ones it can so far.

The test can be tested by the following changes:
```diff
--- a/cpp/src/fil/internal.cuh
+++ b/cpp/src/fil/internal.cuh
@@ -348,7 +348,7 @@ struct categorical_sets {
     // features with similar categorical feature count, we may consider
     // storing node ID within nodes with same feature ID and look up
     // {.max_matching, .first_node_offset} = ...[feature_id]
-    return category <= max_matching[node.fid()] && fetch_bit(bits + node.set(), category);
+    return category <= max_matching[node.fid()] ? fetch_bit(bits + node.set(), category) : 1;
   }
   static int sizeof_mask_from_max_matching(int max_matching)
   {

```
This will help test rapidsai#4314

Authors:
  - Levs Dolgovs (https://github.com/levsnv)

Approvers:
  - Andy Adinets (https://github.com/canonizer)
  - William Hicks (https://github.com/wphicks)

URL: rapidsai#4326
vimarsh6739 pushed a commit to vimarsh6739/cuml that referenced this pull request Oct 9, 2023
…provided to FIL model (rapidsai#4314)

Fix potential CUDA context poison due to invalid global read when negative categories provided at inference:

now equivalent to non-matching.
FIL now converts dummy nodes to numerical on import
and never generates max_matching == -1 categorical features in test.
FIL will still generate empty categorical nodes in test (a non-empty bits vector which contains only zeros), export them as dummy numerical nodes and import again as dummy numerical nodes. If a feature only contains dummy numerical nodes, it will be deemed a numerical feature (same as for non-dummy numerical nodes or a mix thereof). Therefore, categorical feature max_matching == -1 is still prevented.

CI failures
```
Test Result (2 failures / +2)
cuml.test.test_fil.test_lightgbm[5-2]
cuml.test.test_fil.test_lightgbm[5-5]
```
will be resolved by rapidsai#4326

Authors:
  - Levs Dolgovs (https://github.com/levsnv)

Approvers:
  - Andy Adinets (https://github.com/canonizer)
  - William Hicks (https://github.com/wphicks)

URL: rapidsai#4314
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Cython / Python Cython or Python issue non-breaking Non-breaking change Tech Debt Issues related to debt tests Unit testing for project
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants