Hugging FacesystemProblem & solution
Retrieval Augmented Generation with Huggingface Transformers and Ray
Summary
Huggingface Transformers added the Retrieval Augmented Generation architecture to combine standard sequence-to-sequence models with external document retrieval for knowledge-intensive tasks. Scaling RAG fine-tuning across multiple GPUs previously created bottlenecks because the torch.distributed implementation forced the single rank 0 worker to handle all retrieval index lookups. To resolve this synchronization bottleneck, Ray was integrated into the contextual document retrieval mechanism using stateful actor abstractions. Dedicated Ray processes separate from the training workers now load the large index and process retrieval requests concurrently. This architectural separation delivers up to a 2x speedup per retrieval call and removes the strict dependency on PyTorch for training.
Context
When scaling RAG fine-tuning via data-parallel training routines, naive document retrieval lookups become a bottleneck. The document index is too large for every training worker to load its own copy into memory, and the previous torch.distributed implementation latched onto the training process group, forcing the rank 0 worker to synchronously receive all worker inputs, query the index, and return results.
Approach / What changed
Ray was integrated into RAG's document retrieval mechanism using stateful actor abstractions. Separate Ray actor processes load the document index and handle retrieval queries independently from training workers, avoiding the single-worker bottleneck and decoupling retrieval from PyTorch.
Takeaways
The torch.distributed retrieval setup created a synchronization bottleneck because rank 0 handled all worker index queries.
Ray stateful actors allow multiple dedicated processes separate from training workers to load the index and process queries concurrently.
In 4-GPU benchmarks with batch size 8 over 500 steps, four Ray retrieval processes lowered retrieval time from 3.438 to 1.66 seconds per call.
Source and freshness
- Source
- huggingface.co
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.