Lightning-AI / Lightning-AI/litgpt

Gradient Clipping Doesn't Work in Finetuning

Open
#2,191 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
13.7k
Forks
1.5k
Avg merge
15h 37m
Merged PRs (30d)
1

Description

This one's frustrating because the config files SHOW a max_norm parameter, but it doesn't actually do anything during finetuning.

# litgpt/finetune/lora.py:560
unsupported = [(train, ["max_tokens", "max_norm", "tie_embeddings", "lr_warmup_fraction"])]

Meanwhile in pretraining:

# litgpt/pretrain.py:360
fabric.clip_gradients(model, optimizer, max_norm=train.max_norm)
Why this is a problem:

Gradient clipping is pretty important for stable training, especially with:

  • Small datasets (where you're more likely to hit bad batches)
  • Long sequences
  • QLoRA (where quantization noise can cause gradient spikes)
  • Any time you're near the edge of numerical stability

The config files in config_hub/finetune/ all have max_norm: set to empty/null. Users will assume this means "no clipping" when it actually means "this parameter is ignored."

The fix:

Just implement it. The code's already there in pretrain.py - copy it over. Make sure it works with:

  • Regular LoRA
  • QLoRA
  • Full finetuning
  • Adapter training

Or if you really don't want to support it, remove it from the configs and document why.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing litgpt/finetune/lora.py around line 560 with the clipping call in litgpt/pretrain.py around line 360. Trace how max_norm is loaded from the finetuning configs, then verify behavior for regular LoRA, QLoRA, full finetuning, and adapter training. Done means max_norm controls clipping in these modes, or is removed from the configs with its unsupported status documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.