Add LoRA support and configuration to F2LLM #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #7
lora_config.py.arguments.pyto include LoRA parameters.model.pyto apply LoRA if enabled during model initialization.run.pyto prepare LoRA configuration based on user arguments.This pull request introduces comprehensive support for LoRA (Low-Rank Adaptation) parameter-efficient fine-tuning in the F2LLM codebase, enabling users to efficiently adapt large language models with minimal computational resources. It adds LoRA configuration options, integration with the training and model initialization workflow, utilities for applying LoRA, and a full test suite to verify correct LoRA behavior. Documentation has also been updated to guide users through LoRA usage and benefits.
LoRA Integration and Configuration:
lora_config.pymodule implementing theLoRAConfigdataclass and utility functions to configure and apply LoRA adapters using the PEFT library. This includes sensible defaults for common transformer architectures and exposes all major LoRA hyperparameters.F2LLMclass inmodel.pyto support LoRA-enabled initialization, including fallback for flash attention, and to apply LoRA adapters if enabled via configuration.Argsclass inarguments.pyand the training pipeline inrun.pyto accept and propagate LoRA-specific hyperparameters, allowing LoRA to be toggled and configured via the config file or command line. [1] [2] [3]utils.pyto save only LoRA adapter weights when using LoRA, reducing checkpoint size and storage requirements.Testing and Validation:
test_lora.pytest suite to validate LoRA integration, including tests for model initialization, parameter reduction, forward pass correctness, gradient flow, checkpoint saving/loading, configuration flexibility, and end-to-end training workflow.Documentation and Usability:
README.mdwith detailed instructions for enabling and configuring LoRA, explanations of LoRA parameters, usage examples, and a guide to loading LoRA fine-tuned models.peftas a dependency inrequirements.txtto support LoRA functionality.tokenize_data_qwen.pyandconfigs/config.jsonto use Hugging Face model identifiers for improved clarity and reproducibility. [1] [2]These changes make it easy to enable, configure, and test LoRA fine-tuning for F2LLM models, providing significant improvements in efficiency and flexibility for model adaptation workflows.- Added
test_lora.pyfor validating LoRA implementation.requirements.txtto ensure necessary dependencies are included.tokenize_data_qwen.pyfor better model compatibility.utils.pyfor LoRA models.