-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix algorithm of spreading vectors over shards #3374
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,7 @@ void GpuIcmEncoder::encode( | |
| size_t n, | ||
| size_t ils_iters) const { | ||
| size_t nshards = shards->size(); | ||
| size_t shard_size = (n + nshards - 1) / nshards; | ||
| size_t base_shard_size = n / nshards; | ||
|
|
||
| auto codebooks = lsq->codebooks.data(); | ||
| auto M = lsq->M; | ||
|
|
@@ -94,8 +94,14 @@ void GpuIcmEncoder::encode( | |
|
|
||
| // split input data | ||
| auto fn = [=](int idx, IcmEncoderImpl* encoder) { | ||
| size_t i0 = idx * shard_size; | ||
| size_t ni = std::min(shard_size, n - i0); | ||
| size_t i0 = idx * base_shard_size + std::min(size_t(idx), n % nshards); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as my previous comment, you can verify it over the case |
||
| size_t ni = base_shard_size; | ||
| if (ni < n % nshards) { | ||
| ++ni; | ||
| } | ||
| if (ni <= 0) { // only if n < nshards | ||
| return; | ||
| } | ||
| auto xi = x + i0 * d; | ||
| auto ci = codes + i0 * M; | ||
| std::mt19937 geni(idx + seed); // different seed for each shard | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it (n / nshards) or (n - 1)/ nshards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
integer computing, round down already.
remain = n - nshards * base_shard_size, then0 <= remain < nshards, so each shard takes at leastbase_shard_sizevectors, and the firstremainshards takes one extra vector each.