Feat: support LoRA for embedding layer#8222
Feat: support LoRA for embedding layer#8222Beichen-Ma wants to merge 39 commits intosgl-project:mainfrom
Conversation
…stream/main' into feat-lora-embedding
There was a problem hiding this comment.
Summary of Changes
Hello @Beichen-Ma, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly extends the LoRA (Low-Rank Adaptation) functionality to support embedding layers, enabling more efficient fine-tuning of models that modify their input embeddings or introduce new vocabulary tokens. It involves substantial changes across the LoRA management, memory allocation, and layer application components, along with new testing infrastructure to ensure correctness.
Highlights
- LoRA for Embedding Layers: Introduced
VocabParallelEmbeddingWithLoRAto enable LoRA (Low-Rank Adaptation) for embedding layers (embed_tokens). This new class handles the application of LoRA transformations and manages 'added tokens' (new vocabulary tokens introduced by LoRA adapters). - LoRA Manager and Memory Pool Updates: The
LoRAManagerandLoRAMemoryPoolhave been significantly updated to support embedding-specific LoRA weights. This includes new data structures (lora_embeddings_modules,new_embeddings_buffer,embedding_A_buffer,embedding_B_buffer) and logic to load, manage, and apply these weights efficiently, especially considering tensor parallelism. - Dynamic Vocabulary Extension: The
LoRAAdapternow tracksnew_embeddingsandextra_vocab_size, allowing LoRA adapters to extend the model's vocabulary with new tokens. The system dynamically handles these added tokens during the embedding lookup process. - CUDA Graph Compatibility: Added a check to disable CUDA graphs when embedding LoRA is used, as it is currently not supported with CUDA graphs. Users will be prompted to use
--disable-cuda-graphif an embedding LoRA adapter is detected. - Comprehensive Unit and Integration Tests: A new unit test file (
test_lora_layer.py) has been added to thoroughly validate theVocabParallelEmbeddingWithLoRAfunctionality, including various configurations and comparisons against manually computed outputs. Integration tests with the SRT runner using a real-world embedding LoRA adapter are also included.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This PR introduces LoRA support for embedding layers. The changes are comprehensive, including updates to the LoRA manager, memory pool, and layer implementations. The addition of unit and integration tests is valuable. However, there are a few critical issues related to potential runtime errors (UnboundLocalError and TypeError) that need to be addressed, as well as a suggestion to improve error handling.
lifuhuang
left a comment
There was a problem hiding this comment.
Thank you for the contribution! ❤️
…support both linear and embedding weights; Refined the test file name.
…to feat-lora-embedding
|
Hi @Beichen-Ma , can you attach the final perf result to the PR description?
|
Sure, I added the perf result in the description. |
|
@Beichen-Ma What's the status for this PR? Is it ready for merging, or do we need further implementation on lm_head? |
I added perf benchmark results to the description and it's waiting for review. The lm_head implementation will be in separate PR and is blocked by this one. |
| TestFile("lora/test_multi_lora_backend.py", 60), | ||
| TestFile("lora/test_lora_cuda_graph.py", 250), | ||
| TestFile("lora/test_lora_update.py", 400), | ||
| # TestFile("lora/test_lora_embedding_layer.py", 100), |
There was a problem hiding this comment.
So this test cannot pass by now?
Motivation
Integrate LoRA functionality to VocabParallelEmbedding to support efficient parameter fine-tuning.
Modifications
Update LoRA Manager:
embed_tokens) inLoRAManager, including logic to update LoRA weight names, adapters, and memory buffers for embeddings.Embedding Support Enhancements:
new_embeddingsandextra_vocab_size) inLoRAclass to manage embeddings and extra vocabulary size.Memory Pool Updates:
LoRAMemoryPoolto handle embedding-specific buffers (new_embeddings_buffer,embedding_A_buffer,embedding_B_buffer) and added methods to initialize and manage these buffers.prepare_lora_batchandload_lora_weight_to_buffermethods to include embedding modules in the batch preparation and weight loading processes.Unit Tests:
Benchmark
Checklist