Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 7 min read Deep dive hardMaster

GaLore: Advancing Large Model Training on Consumer-grade Hardware

GaLore cuts LLM training memory by projecting gradients into a low-rank subspace before the optimizer sees them, reporting over 82.5% reduction in optimizer-state memory and enabling 7B Llama-style models to train on a single RTX 4090. Periodic subspace switching preserves full-parameter learning, and combining the projection with 8-bit quantized optimizer states (via bitsandbytes) saves further memory. It is available in Hugging Face Transformers 4.39+ through optimizers like galore_adamw, galore_adamw_8bit and galore_adafactor with optim_target_modules, plus layer-wise variants that apply updates per layer via PyTorch post-accumulation hooks.

Assumes: Adam optimizerLLM training basicsquantizationPyTorch

Related posts

  • Fine-tuning 20B LLMs with RLHF on a 24GB consumer GPU

    Hugging Face hardMaster

    Combining trl with peft and bitsandbytes makes RLHF fine-tuning of a 20B-parameter LLM feasible on a single 24GB consumer GPU. The approach loads the active model in 8-bit using LLM.int8(), trains only small LoRA adapters to shrink optimizer state, and obtains reference logits for PPO from the same model by disabling the adapters, so no second model copy is needed. Memory rules of thumb are 4/2/1 GB per billion parameters in fp32/fp16/int8, plus 8 bytes per parameter for AdamW. A gpt-neox-20b model was fine-tuned on IMDB, its adapters were merged, and it was then RL-tuned to generate positive reviews. The main cost is speed, since adapters make forward and backward passes roughly twice as slow.

  • Make LLM Fine-tuning 2x faster with Unsloth and 🤗 TRL

    Hugging Face mediumAdept

    Unsloth speeds up QLoRA fine-tuning of Llama and Mistral-family models by rewriting PyTorch modules as Triton kernels with manually derived backpropagation. Because no approximations are made, it claims 0% accuracy loss relative to standard QLoRA. Across 59 benchmark runs on A100 and T4 GPUs, it ran 1.5–3.9x faster than Hugging Face transformers and used up to 74% less VRAM. Code examples show loading pre-quantized 4-bit models with FastLanguageModel, attaching LoRA adapters, and training with TRL's SFTTrainer or DPOTrainer.

  • Making LLMs lighter with AutoGPTQ and transformers

    Hugging Face mediumAdept

    AutoGPTQ is now integrated into Hugging Face Transformers (via Optimum), letting users quantize and run LLMs at 8, 4, 3 or 2 bits with the GPTQ post-training method. GPTQ needs a calibration dataset and quantizes only the weights: int4 weights are dequantized on the fly in a fused kernel while compute stays in fp16. That gives nearly 4x memory savings with negligible accuracy loss at 4-bit. On an A100 at batch size 1, Llama-2-7B with the exllama kernel dropped peak memory from about 29 GB to 10.5 GB with slightly better per-token latency than fp16. Text-Generation-Inference can now serve a 70B model on a single 80GB GPU and PEFT adapters can be fine-tuned on top, but the kernels slow down at larger batch sizes and W4A8 or Triton kernels remain open work.

  • Making LLMs even more accessible with bitsandbytes, 4-bit quantization and QLoRA

    Hugging Face mediumAdept

    bitsandbytes now integrates 4-bit quantization into Hugging Face transformers, letting most accelerate-loadable models (text, vision, multimodal) run in 4-bit and be fine-tuned via QLoRA, which backpropagates through a frozen 4-bit base model into LoRA adapters. QLoRA stores weights in NF4 and dequantizes to bfloat16 for compute, adds double quantization (saving ~0.4 bits per parameter) and paged optimizers, and matches 16-bit fine-tuning while fitting a 33B model on a 24GB GPU or 65B on a 48GB GPU. The post explains FP8/FP4 bit layouts and shows BitsAndBytesConfig usage. Recommended defaults are NF4 for precision, double quant for memory pressure, and a 16-bit compute dtype for speed.

  • Fine-tuning Llama 2 70B using PyTorch FSDP

    Hugging Face hardMaster

    Full fine-tuning of Llama 2 70B across two nodes of 8×A100 80GB GPUs with PyTorch FSDP, Hugging Face Accelerate, Transformers and TRL, addressing three obstacles. CPU RAM exhaustion (~2TB if every rank loads the model) is avoided by loading weights only on rank 0 via the meta device and broadcasting with sync_module_states. Slow, NCCL-timeout-prone checkpointing is fixed by saving intermediate checkpoints as SHARDED_STATE_DICT and switching to FULL_STATE_DICT only for the final save. Flash Attention V2 (kernel fusion, tiling, online softmax) plus gradient checkpointing cut VRAM and time; the run finished in ~13.5 hours, with a paged AdamW optimizer needed on a single node.

The quest for software engineering knowledge.

Look:
Layout: