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

Fixed issue with percentile_approx where output tdigests could have uninitialized data at the end. #9931

Merged
merged 3 commits into from
Jan 6, 2022

Conversation

nvdbaranec
Copy link
Contributor

Fixes NVIDIA/spark-rapids#4060

Issue was relatively straightforward. There is a section of code in the bucket generation step that detects "gaps" that would be generated during the reduction step. It was incorrectly indexing into the list of cumulative weights for input values. Fundamental change was to change the TotalWeightIter iterator which was just returning the total weight for an input group into a GroupInfoFunc functor that returns total weight as well as group size info that is used to index cumulative weights correctly.

@nvdbaranec nvdbaranec added bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. 5 - DO NOT MERGE Hold off on merging; see PR for details non-breaking Non-breaking change labels Dec 17, 2021
@nvdbaranec nvdbaranec requested a review from a team as a code owner December 17, 2021 22:06
@codecov
Copy link

codecov bot commented Dec 17, 2021

Codecov Report

Merging #9931 (8963fef) into branch-22.02 (967a333) will decrease coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff                @@
##           branch-22.02    #9931      +/-   ##
================================================
- Coverage         10.49%   10.42%   -0.07%     
================================================
  Files               119      119              
  Lines             20305    20475     +170     
================================================
+ Hits               2130     2134       +4     
- Misses            18175    18341     +166     
Impacted Files Coverage Δ
python/dask_cudf/dask_cudf/sorting.py 92.30% <0.00%> (-0.61%) ⬇️
python/cudf/cudf/__init__.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/frame.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/index.py 0.00% <0.00%> (ø)
python/cudf/cudf/io/parquet.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/series.py 0.00% <0.00%> (ø)
python/cudf/cudf/utils/utils.py 0.00% <0.00%> (ø)
python/cudf/cudf/utils/dtypes.py 0.00% <0.00%> (ø)
python/cudf/cudf/utils/ioutils.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/dataframe.py 0.00% <0.00%> (ø)
... and 15 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 897a9ea...8963fef. Read the comment docs.

@andygrove
Copy link
Contributor

I have tested this patch locally with the RAPIDS Accelerator tests that were originally failing and I have not seen any failures.

@sameerz sameerz changed the title Fixed issue with percentile_approx where output tdigests could have unitialized data at the end. Fixed issue with percentile_approx where output tdigests could have uninitialized data at the end. Dec 21, 2021
@nvdbaranec nvdbaranec removed the 5 - DO NOT MERGE Hold off on merging; see PR for details label Jan 4, 2022
@nvdbaranec
Copy link
Contributor Author

rerun tests

Copy link
Contributor

@vyasr vyasr left a comment

Choose a reason for hiding this comment

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

Looks good to me, seems like it's just fixing a bunch of off by 1 out of bounds accesses. I have a few very minor suggestions, feel free to incorporate or not.

auto const group_start = inner_offsets[outer_offsets[group_index]];
auto const group_end = inner_offsets[outer_offsets[group_index + 1]];
auto const num_weights = group_end - group_start;
auto const last_weight_index = group_end - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit: You could inline this so that you online calculate it when the calculation is false. Should be negligible though since I assume num_weights is almost always nonzero and you're already avoiding actually indexing into cumulative_weights except when needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure the compiler will optimize this correctly, and I think group_end - 1 is a bit on the cryptic side. This code is already drilling through 2 layers of offsets which is confusing to begin with :)

Comment on lines +304 to +306
double total_weight;
size_type group_size, group_start;
thrust::tie(total_weight, group_size, group_start) = group_info(group_index);
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume you need a tie here because of thrust::tuple not supporting structured bindings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. Same as

// NOTE: can't use structured bindings here.

cpp/src/groupby/sort/group_tdigest.cu Outdated Show resolved Hide resolved
cpp/src/groupby/sort/group_tdigest.cu Outdated Show resolved Hide resolved
@nvdbaranec
Copy link
Contributor Author

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 120aa62 into rapidsai:branch-22.02 Jan 6, 2022
@elstehle elstehle mentioned this pull request Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] test_hash_groupby_approx_percentile_long_repeated_keys failed intermittently
4 participants