Volver al blog
LoRA: La Revolución de Eficiencia en el Fine-Tuning de Modelos de Lenguaje

LoRA: La Revolución de Eficiencia en el Fine-Tuning de Modelos de Lenguaje

Full fine-tuning feels intuitive: take a pretrained model, train it on your data, update every weight. But intuitive doesn’t scale. When you’re fine-tuning a 175 billion parameter model like GPT-3, you’re not updating a few weights—you’re storing and serving 175 billion updated weights. For every task. That’s not adaptation; it’s duplication.

El fine-tuning completo se siente intuitivo: toma un modelo pre-entrenado, entrénalo con tus datos, actualiza cada peso. Pero intuitivo no escala. Cuando haces fine-tuning de un modelo de 175 mil millones de parámetros como GPT-3, no estás actualizando unos pocos pesos—estás almacenando y sirviendo 175 mil millones de pesos actualizados. Para cada tarea. Eso no es adaptación; es duplicación.

LoRA (Low-Rank Adaptation), introduced by Edward Hu and colleagues at Microsoft Research in 2021, flips this on its head. The key insight: pretrained language models have a low intrinsic rank for their adaptation tasks. Instead of updating every weight, LoRA freezes the original weights and injects trainable rank decomposition matrices into each Transformer layer.

LoRA (Low-Rank Adaptation), introducido por Edward Hu y colegas en Microsoft Research en 2021, invierte esto. La idea clave: los modelos de lenguaje pre-entrenados tienen un rank intrínseco bajo para sus tareas de adaptación. En lugar de actualizar cada peso, LoRA congela los pesos originales e inyecta matrices de descomposición de rank entrenables en cada capa del Transformer.

The math is elegant. For a pre-trained weight matrix W of shape (d, k), LoRA adds two smaller matrices: A of shape (r, k) and B of shape (d, r), where r is the rank—typically 8, 16, or 32. The forward pass computes W + BA instead of W. During training, only A and B are updated. The result: a 10,000x reduction in trainable parameters and 3x less GPU memory compared to full fine-tuning.

La matemática es elegante. Para una matriz de pesos pre-entrenada W de forma (d, k), LoRA añade dos matrices más pequeñas: A de forma (r, k) y B de forma (d, r), donde r es el rank—típicamente 8, 16, o 32. El forward pass computa W + BA en lugar de W. Durante el entrenamiento, solo A y B se actualizan. El resultado: una reducción de 10,000x en parámetros entrenables y 3x menos memoria GPU comparada con fine-tuning completo.

A 65 billion parameter model—previously requiring multiple A100s—can now be fine-tuned on a single 48GB GPU. That’s not a incremental improvement. It’s the difference between impossible and practical. The constraint shifted from compute to creativity. If you can fit the model in memory, you can adapt it.

Un modelo de 65 mil millones de parámetros—que antes requería múltiples A100s—ahora puede hacer fine-tuning en una sola GPU de 48GB. Eso no es una mejora incremental. Es la diferencia entre imposible y práctico. La restricción cambió de compute a creatividad. Si puedes poner el modelo en memoria, puedes adaptarlo.

QLoRA (Dettmers et al., 2023) pushes this further. It quantizes the pretrained model to 4-bit NormalFloat (NF4) precision—an information-theoretically optimal data type for normally distributed weights—while training LoRA adapters in higher precision. The approach fine-tuned the Guanaco family of models, achieving 99.3% of ChatGPT’s performance on the Vicuna benchmark with just 24 hours of training on a single consumer GPU. Small models, big results.

QLoRA (Dettmers et al., 2023) lleva esto más allá. Cuantiza el modelo pre-entrenado a 4-bit NormalFloat (NF4)—un tipo de dato óptimo desde la teoría de la información para pesos con distribución normal—mientras entrena adaptadores LoRA en mayor precisión. El enfoque fine-tunéo la familia Guanaco, logrando 99.3% del rendimiento de ChatGPT en el benchmark Vicuna con solo 24 horas de entrenamiento en una sola GPU de consumo. Modelos pequeños, resultados grandes.

The PEFT library on Hugging Face packages LoRA, prefix tuning, and prompt tuning into a unified API. Fine-tuning a Llama 3 8B model takes minutes, not days. The adapters are small—often less than 1% of model size—and can be swapped at runtime. One model, many personas.

La librería PEFT en Hugging Face empaqueta LoRA, prefix tuning y prompt tuning en una API unificada. Fine-tuning de un modelo Llama 3 8B toma minutos, no días. Los adaptadores son pequeños—típicamente menos del 1% del tamaño del modelo—y pueden ser intercambiados en runtime. Un modelo, muchas personas.

For agentic systems, this is infrastructure. When your agent needs to adapt to a new domain—legal, medical, financial—LoRA gives you a path that doesn’t require retraining from scratch. The adapter stores what changed, not what stayed the same. Your system fine-tunes on deployment, not at build time.

Para sistemas agénticos, esto es infraestructura. Cuando tu agente necesita adaptarse a un nuevo dominio—legal, médico, financiero—LoRA te da un camino que no requiere reentrenar desde cero. El adaptador guarda lo que cambió, no lo que permaneció igual. Tu sistema hace fine-tuning en deploy, no en build time.


References

Referencias

  • Hu, E. J., Shen, Y., Wallis, P., Allen-Zhu, Y., Li, Y., Wang, S., & Chen, W. (2021). *LoRA: Low-Rank Adaptation of Large Language Models*. arXiv:2106.09685. arxiv.org/abs/2106.09685
  • Dettmers, T., Pagnoni, A., Holtzman, A., & Zettlemoyer, L. (2023). *QLoRA: Efficient Finetuning of Quantized LLMs*. arXiv:2305.14314. arxiv.org/abs/2305.14314
  • PEFT library: github.com/huggingface/peft
  • Hu, E. J., Shen, Y., Wallis, P., Allen-Zhu, Y., Li, Y., Wang, S., & Chen, W. (2021). *LoRA: Low-Rank Adaptation of Large Language Models*. arXiv:2106.09685. arxiv.org/abs/2106.09685
  • Dettmers, T., Pagnoni, A., Holtzman, A., & Zettlemoyer, L. (2023). *QLoRA: Efficient Finetuning of Quantized LLMs*. arXiv:2305.14314. arxiv.org/abs/2305.14314
  • Librería PEFT: github.com/huggingface/peft
Compartir