[feat][fsdp] Add QLoRA and Gemma 4 training support - #1968
Open
bvolpato wants to merge 3 commits into
Open
Conversation
bvolpato
marked this pull request as ready for review
August 2, 2026 00:52
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for FSDP QLoRA by integrating 4-bit base-weight quantization using bitsandbytes. It adds the necessary configuration options, updates model loading and wrapping logic, handles in-place sharding for 4-bit parameters, and ensures embeddings within wrapped parent modules are not redundantly wrapped. Feedback on the changes includes addressing a regex bug in LoRA exclusions when exclude_modules is empty, optimizing module traversal in apply_fsdp2 to a single pass, and replacing configuration assertions with explicit ValueError exceptions to prevent issues if Python is run with optimization flags.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add opt-in bitsandbytes 4-bit loading for FSDP policy training so SkyRL can train LoRA adapters against a quantized base model in SFT and RL. Include a runnable Gemma 4 E2B example for small single-GPU experiments.
Changes
model.bitsandbytes_4bitconfig with NF4/FP4 and double-quantization controls.Params4bitthrough the meta device.language_model_onlyLoRA adapters to the language model so text-only vLLM sync excludes audio and vision towers.flash_attnselection and use SDPA plus a Gemma-safe FSDP boundary in the example.qloradependency extra, config tests, wrap-policy regression coverage, and SFT docs.Repro
After accepting the Gemma license on Hugging Face:
Extra config arguments can reduce this to a one-step smoke:
bash examples/train/sft/run_sft_gemma4_e2b_qlora.sh \ 'train_dataset_splits=["train[:1]"]' \ max_length=64 \ num_steps=1 \ disable_cache=true \ num_workers=0Testing
uv run --isolated --extra dev --extra skyrl-train pytest tests/train/test_sft_config.py tests/backends/skyrl_train/distributed/test_fsdp_utils.py -q(62 passed)uv run --isolated --extra dev pre-commit run --all-files(Ruff, Black, gitleaks passed)uv run --isolated --extra fsdp --extra qlora --extra dev pytest -q tests/backends/skyrl_train/models/test_models.py(4 passed)all-linearand explicit LoRA targets: 276 and 50 language-model adapters respectively, with zero audio or vision tower adapters.1.0, advantage1.0, policy loss-1.0, and finite grad norm6.78125; process exited 0.unsloth/gemma-4-E2B-itmirror on a 16 GB RTX 5070 Ti: 200 distinct training examples, plus a disjoint 31-example held-out set. Held-out loss fell from4.2274before training to1.1885at step 50 and1.1558at step 100; gradients stayed finite and all optimizer steps completed.(1, 4, 262144).2.7434to0.8364with finite gradients.2.7891before training to1.1250at step 50 and1.1067at step 100.Did this cause any problems?
Rollback by reverting this commit. New behavior is disabled by default.