[feat][fsdp] Add QLoRA and Gemma 4 training support - #1968
Conversation
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.
There was a problem hiding this comment.
Code Review
This pull request introduces support for FSDP QLoRA (4-bit base-weight quantization with LoRA adapters) using bitsandbytes, including configuration options, validation rules, and documentation/examples (specifically for Gemma 4 E2B). It updates model loading and FSDP sharding logic to handle 4-bit quantized weights, and fixes embedding wrapping behavior in FSDP. The reviewer noted that while FSDPPolicyWorkerBase supports 4-bit quantization, FSDPRefWorkerBase in fsdp_worker.py does not yet pass these parameters to HFModelWrapper, which could cause the reference model to load in full precision during RL training and lead to high memory usage or OOM.
a4e1a88 to
fbd41bb
Compare
fbd41bb to
f9538e3
Compare
7b60403 to
c5282bd
Compare
Signed-off-by: Bruno Volpato <brunocvcunha@gmail.com>
- Disable FSDP parameter casting for opaque Params4bit storage - Cover multi-rank policy and document preserved BF16 compute
b579c24 to
d615efe
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit d615efe. Configure here.
Single-rank 4-bit models skip FSDP wrapping, so native CPU offload cannot apply. Fail fast and direct users to the existing manual phase-offload path.

Summary
Add opt-in bitsandbytes 4-bit loading for FSDP policy and reference models so SkyRL can train LoRA adapters against a quantized base model in SFT and RL. Include a runnable Gemma 4 E2B single-GPU example.
Changes
model.bitsandbytes_4bitwith NF4/FP4 and double-quantization controls.Params4bitoff the meta-device path and avoid redundant single-rank FSDP wrapping.language_model_onlyLoRA adapters to the language model.qloraextra, configuration tests, wrap-policy coverage, docs, and example script.New behavior is disabled by default.
Repro
After accepting the Gemma license on Hugging Face:
Validation
212 passed)uv lock --check(1, 2, 262144)1402 passed, 5 skipped, 5 deselected)4.2274to1.1558; finite gradients throughout2.7891to1.1067Single-rank and colocated RL paths were validated on a 16 GB RTX 5070 Ti. Multi-rank FSDP2 was validated with two Gloo ranks sharing that GPU; separate-GPU NCCL remains untested locally.