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

Workaround thrust-copy-if limit in wordpiece-tokenizer #12168

Merged
merged 14 commits into from
Nov 28, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions cpp/src/text/subword/wordpiece_tokenizer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,19 @@ void wordpiece_tokenizer::tokenize(uvector_pair& cps_and_offsets, rmm::cuda_stre
// Repurpose the input array for the token ids. In the worst case, each code point ends up being a
// token so this will always have enough memory to store the contiguous tokens.
uint32_t* contiguous_token_ids = device_code_points;
thrust::copy_if(rmm::exec_policy(stream),
device_token_ids.begin(),
device_token_ids.end(),
contiguous_token_ids,
copy_if_fn{});
auto const copy_size = // thrust::copy_if limited to copying int-max values
std::min(device_token_ids.size(), static_cast<std::size_t>(std::numeric_limits<int>::max()));
auto ids_itr = device_token_ids.begin();
auto const ids_end = device_token_ids.end();
while (ids_itr != ids_end) {
auto const copy_end = static_cast<std::size_t>(std::distance(ids_itr, ids_end)) <= copy_size
davidwendt marked this conversation as resolved.
Show resolved Hide resolved
? ids_end
: ids_itr + copy_size;
auto const end_itr = thrust::copy_if(
rmm::exec_policy(stream), ids_itr, copy_end, contiguous_token_ids, copy_if_fn{});
contiguous_token_ids += std::distance(contiguous_token_ids, end_itr);
davidwendt marked this conversation as resolved.
Show resolved Hide resolved
ids_itr = copy_end;
}

// Repurpose start word indices since it is the same size and type as the required output.
uint32_t* token_id_counts = device_start_word_indices;
Expand Down