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 Byte-Pair-Encoding usage of cuco static-map for storing merge-pairs #13807

Merged
merged 31 commits into from
Aug 17, 2023

Conversation

davidwendt
Copy link
Contributor

@davidwendt davidwendt commented Aug 2, 2023

Description

Switching to use cuco::experimental::static_map for storing the unique merge-pair strings that can be looked up by string_view. This takes advantage of a feature of the static_map that allows storing with one key (index to a string entry) and lookup with a different type (string). The map uses a hash on the string for storing the index but allows lookup by string since the hash of string can resolve the entry and duplicates can be resolved by comparing the string with row entries.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@davidwendt davidwendt added bug Something isn't working 2 - In Progress Currently a work in progress libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change labels Aug 2, 2023
@davidwendt davidwendt self-assigned this Aug 2, 2023
Copy link
Member

@PointKernel PointKernel left a comment

Choose a reason for hiding this comment

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

The code should build properly with the proposed changes. The problem with double_hashing is that we expect users to provide a hasher that can be constructed from an integer (or a seed). In that way, we can minimize the chance of secondary collisions during probing but now I realize it's a too-restrictive requirement. By all means, for a single map with 50% occupancy, linear_probing would probably outperform double_hashing all the time.

cpp/src/text/subword/load_merges_file.cu Outdated Show resolved Hide resolved
cpp/src/text/subword/bpe_tokenizer.cuh Outdated Show resolved Hide resolved
@PointKernel
Copy link
Member

PointKernel commented Aug 2, 2023

I'm looking into other issues (e.g. ! operator and iter->second) in the meantime.

(should be solved in NVIDIA/cuCollections#345)

@github-actions github-actions bot added the CMake CMake build issue label Aug 3, 2023
PointKernel added a commit to NVIDIA/cuCollections that referenced this pull request Aug 6, 2023
This PR fixes issues and adds new features requested by
rapidsai/cudf#13807.

It:

- removes the requirement of the second hasher from double hashing must
be constructible from an integer
- fixes an issue in map iterator `!=` operator
- overloads map iterator access operator
- allows zero capacity container
- adds `capacity_test` back since several corner cases need to be
exercised
Copy link
Member

@PointKernel PointKernel left a comment

Choose a reason for hiding this comment

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

CMake changes to be reverted once rapidsai/rapids-cmake#452 is merged.

cpp/include/nvtext/bpe_tokenize.hpp Outdated Show resolved Hide resolved
cpp/src/text/subword/load_merges_file.cu Outdated Show resolved Hide resolved
cpp/src/text/subword/load_merges_file.cu Outdated Show resolved Hide resolved
@davidwendt davidwendt requested a review from nvdbaranec August 11, 2023 18:36
rapids-bot bot pushed a commit to rapidsai/rapids-cmake that referenced this pull request Aug 11, 2023
This PR fetches the latest cuco to unblock rapidsai/cudf#13807.

Authors:
  - Yunsong Wang (https://github.com/PointKernel)
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Nghia Truong (https://github.com/ttnghia)
  - Robert Maynard (https://github.com/robertmaynard)

URL: #452
@github-actions github-actions bot removed the CMake CMake build issue label Aug 11, 2023
@PointKernel PointKernel removed the request for review from a team August 11, 2023 18:53
Copy link
Member

@PointKernel PointKernel left a comment

Choose a reason for hiding this comment

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

Looks great! 🔥

Heterogeneous lookup in libcudf 🔥

cpp/src/text/subword/bpe_tokenizer.cuh Outdated Show resolved Hide resolved
@davidwendt davidwendt changed the title Fix Byte-Pair-Encoding usage of cuco static-map for storing merge-pairs Fix Byte-Pair-Encoding usage of cuco static-map for storing merge-pairs Aug 14, 2023
@davidwendt davidwendt changed the title Fix Byte-Pair-Encoding usage of cuco static-map for storing merge-pairs Fix Byte-Pair-Encoding usage of cuco static-map for storing merge-pairs Aug 14, 2023
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

This is really nice. Heterogeneous lookup is cool. Can you comment on the performance impact of this change?

cpp/src/text/subword/bpe_tokenizer.cu Outdated Show resolved Hide resolved
cpp/src/text/subword/bpe_tokenizer.cu Outdated Show resolved Hide resolved
cpp/src/text/subword/bpe_tokenizer.cuh Show resolved Hide resolved
@davidwendt davidwendt changed the title Fix Byte-Pair-Encoding usage of cuco static-map for storing merge-pairs Fix Byte-Pair-Encoding usage of cuco static-map for storing merge-pairs Aug 16, 2023
@davidwendt davidwendt requested a review from bdice August 16, 2023 14:55
@davidwendt
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit f543dfa into rapidsai:branch-23.10 Aug 17, 2023
@davidwendt davidwendt deleted the fix-bpe-static-map branch August 17, 2023 15:19
etseidl pushed a commit to etseidl/cudf that referenced this pull request Aug 17, 2023
…rs (rapidsai#13807)

Switching to use `cuco::experimental::static_map` for storing the unique merge-pair strings that can be looked up by `string_view`. This takes advantage of a feature of the `static_map` that allows storing with one key (index to a string entry) and lookup with a different type (string). The map uses a hash on the string for storing the index but allows lookup by string since the hash of string can resolve the entry and duplicates can be resolved by comparing the string with row entries.

Authors:
  - David Wendt (https://github.com/davidwendt)
  - Yunsong Wang (https://github.com/PointKernel)

Approvers:
  - Yunsong Wang (https://github.com/PointKernel)
  - Bradley Dice (https://github.com/bdice)

URL: rapidsai#13807
psamfass added a commit to ROCm/hipCollections that referenced this pull request Nov 21, 2024
Yunsong Wang
Sun Aug 6 15:56:12 2023 -0700
Improve implememtation details in experimental data structures (#345)
This PR fixes issues and adds new features requested by
rapidsai/cudf#13807.

It:

- removes the requirement of the second hasher from double hashing must
be constructible from an integer
- fixes an issue in map iterator `!=` operator
- overloads map iterator access operator
- allows zero capacity container
- adds `capacity_test` back since several corner cases need to be
exercised)
domcharrier pushed a commit to ROCm/hipCollections that referenced this pull request Nov 26, 2024
Yunsong Wang
Sun Aug 6 15:56:12 2023 -0700
Improve implememtation details in experimental data structures (#345)
This PR fixes issues and adds new features requested by
rapidsai/cudf#13807.

It:

- removes the requirement of the second hasher from double hashing must
be constructible from an integer
- fixes an issue in map iterator `!=` operator
- overloads map iterator access operator
- allows zero capacity container
- adds `capacity_test` back since several corner cases need to be
exercised
domcharrier pushed a commit to ROCm/hipDF that referenced this pull request Dec 12, 2024
Yunsong Wang
Sun Aug 6 15:56:12 2023 -0700
Improve implememtation details in experimental data structures (#345)
This PR fixes issues and adds new features requested by
rapidsai/cudf#13807.

It:

- removes the requirement of the second hasher from double hashing must
be constructible from an integer
- fixes an issue in map iterator `!=` operator
- overloads map iterator access operator
- allows zero capacity container
- adds `capacity_test` back since several corner cases need to be
exercised
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team 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.

3 participants