Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Fixed RAG sharding to include remainder of rows #3836

Merged
merged 2 commits into from
Jul 22, 2021
Merged

Fixed RAG sharding to include remainder of rows #3836

merged 2 commits into from
Jul 22, 2021

Conversation

lukesalamone
Copy link
Contributor

Patch description
This patch addresses a bug while generating embeddings. Previously, sharding skipped over the remainder of rows if the number of rows was not divisible by the number of shards. This patch simply distributes the remainder over the first few shards. For example,

# assume I want 3 shards out of 8 rows
rows: 1 2 3 4 5 6 7 8
previously: [1 2] [3 4] [5 6]
now: [1 2 3] [4 5 6] [7 8]

Testing steps

Just run generate_dense_embeddings.py with a passages.tsv file whose number of passages isn't divisible by the number of shards.

for i in `seq 0 49`; do /usr/bin/python generate_dense_embeddings.py \
-mf zoo:hallucination/bart_rag_turn_dtt/model \
--dpr-model True \
--passages-file passages.tsv \
--outfile test_embeddings/out \
--num-shards 50 \
--shard-id $i -bs 32; done

In my case I had 462356 passages which means for 50 shards the last 6 will be ignored.

23:59:50 | Shard 1 of 50 encoding psg index 9247 to 18494, out of 462356
23:59:50 | Encoded 320 out of 9247 passages
23:59:51 | Encoded 640 out of 9247 passages
23:59:52 | Encoded 960 out of 9247 passages
23:59:52 | Encoded 1280 out of 9247 passages
23:59:53 | Encoded 1600 out of 9247 passages
23:59:53 | Encoded 1920 out of 9247 passages
23:59:54 | Encoded 2240 out of 9247 passages
23:59:54 | Encoded 2560 out of 9247 passages
23:59:55 | Encoded 2880 out of 9247 passages
23:59:56 | Encoded 3200 out of 9247 passages
23:59:56 | Encoded 3520 out of 9247 passages
23:59:57 | Encoded 3840 out of 9247 passages
23:59:57 | Encoded 4160 out of 9247 passages
23:59:58 | Encoded 4480 out of 9247 passages
23:59:59 | Encoded 4800 out of 9247 passages
23:59:59 | Encoded 5120 out of 9247 passages
00:00:00 | Encoded 5440 out of 9247 passages
00:00:00 | Encoded 5760 out of 9247 passages
00:00:01 | Encoded 6080 out of 9247 passages
00:00:02 | Encoded 6400 out of 9247 passages
00:00:02 | Encoded 6720 out of 9247 passages
00:00:03 | Encoded 7040 out of 9247 passages
00:00:03 | Encoded 7360 out of 9247 passages
00:00:04 | Encoded 7680 out of 9247 passages
00:00:05 | Encoded 8000 out of 9247 passages
00:00:05 | Encoded 8320 out of 9247 passages
00:00:06 | Encoded 8640 out of 9247 passages
00:00:06 | Encoded 8960 out of 9247 passages

@facebook-github-bot
Copy link

Hi @lukesalamone!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Copy link
Contributor

@klshuster klshuster left a comment

Choose a reason for hiding this comment

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

this looks great, thanks for your contribution!

@klshuster klshuster merged commit 53b8a8c into facebookresearch:master Jul 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants