Skip to content
Back to skills

Layerwise Lr Decay

ASecurity

Applies different learning rates to transformer encoder vs task-specific head, with no weight decay on bias and LayerNorm.

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
documentationpython

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill layerwise-lr-decay --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Layerwise Lr Decay?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Layerwise Lr Decay
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-layerwise-lr-decay/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-layerwise-lr-decay)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: nlp-layerwise-lr-decay
description: >
  Applies different learning rates to transformer encoder vs task-specific head, with no weight decay on bias and LayerNorm.
---
# Layer-wise Learning Rate Decay

## Overview

Pretrained transformer layers need gentle updates to preserve knowledge, while the randomly initialized task head needs aggressive learning. Use a lower learning rate for the encoder and a higher one for the decoder/head. Exclude bias and LayerNorm parameters from weight decay to prevent underfitting.

## Quick Start

```python
def get_optimizer_params(model, encoder_lr=2e-5, decoder_lr=1e-3, weight_decay=0.01):
    no_decay = ["bias", "LayerNorm.bias", "LayerNorm.weight"]
    params = [
        {"params": [p for n, p in model.model.named_parameters()
                     if not any(nd in n for nd in no_decay)],
         "lr": encoder_lr, "weight_decay": weight_decay},
        {"params": [p for n, p in model.model.named_parameters()
                     if any(nd in n for nd in no_decay)],
         "lr": encoder_lr, "weight_decay": 0.0},
        {"params": [p for n, p in model.named_parameters()
                     if "model" not in n],
         "lr": decoder_lr, "weight_decay": 0.0},
    ]
    return params
```

## Workflow

1. Split parameters into encoder (pretrained) and decoder (new head) groups
2. Within encoder, separate decay and no-decay parameters
3. Assign lower LR to encoder (~2e-5), higher to decoder (~1e-3)
4. Pass parameter groups to AdamW optimizer

## Key Decisions

- **LR ratio**: Typically 10-100x between head and encoder
- **No decay on bias/LayerNorm**: Standard practice; prevents regularizing normalization params
- **Per-layer decay**: For deeper control, multiply LR by 0.95^(N-layer) from top to bottom

## References

- Feedback Prize - English Language Learning (Kaggle)
- Source: [fb3-deberta-v3-base-baseline-train](https://www.kaggle.com/code/yasufuminakama/fb3-deberta-v3-base-baseline-train)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.