GeeeekExplorer/transformers-patch

patches for huggingface transformers to save memory

37

stars

14

commits

Python

primary language

May 9, 2026

updated

deep-learning
llm
nlp
pytorch
training
transformer
Browse cluster: Large Language Models and NLP

README

Transformers-Patch 🛠️

Memory optimization patches for HuggingFace Transformers.

Features ✨

  • Memory Reduction - Significantly lowers memory usage in Transformers models

  • Zero Configuration - Works automatically after import

Installation ⚡

pip install git+https://github.com/GeeeekExplorer/transformers-patch.git

Quick Start 🚀

Just import the patch before loading any Transformers models:

import transformers_patch
from transformers import AutoModel

Benchmark 📊

Test Configuration:

  • 8x GPU machine
  • Micro batch size: 1
  • Sequence length: 4096
  • Gradient checkpointing: Disabled
  • Model: Qwen3-8B
Memory ComponentFixed AllocationBefore PatchAfter Patch
Model + Gradients30.5 GB--
ZeRO Optimizer States11.4 GB--
Activations-35.4 GB17.8 GB

50% reduction in activation memory!

Example Usage 📋

See complete example in train.py.

Acknowledgements 🙏

Contributors

GeeeekExplorer

13 commits

cheunglei

1 commits

GeeeekExplorer/transformers-patch

patches for huggingface transformers to save memory

37

stars

14

commits

Python

primary language

May 9, 2026

updated

deep-learning
llm
nlp
pytorch
training
transformer
Browse cluster: Large Language Models and NLP

README

Transformers-Patch 🛠️

Memory optimization patches for HuggingFace Transformers.

Features ✨

  • Memory Reduction - Significantly lowers memory usage in Transformers models

  • Zero Configuration - Works automatically after import

Installation ⚡

pip install git+https://github.com/GeeeekExplorer/transformers-patch.git

Quick Start 🚀

Just import the patch before loading any Transformers models:

import transformers_patch
from transformers import AutoModel

Benchmark 📊

Test Configuration:

  • 8x GPU machine
  • Micro batch size: 1
  • Sequence length: 4096
  • Gradient checkpointing: Disabled
  • Model: Qwen3-8B
Memory ComponentFixed AllocationBefore PatchAfter Patch
Model + Gradients30.5 GB--
ZeRO Optimizer States11.4 GB--
Activations-35.4 GB17.8 GB

50% reduction in activation memory!

Example Usage 📋

See complete example in train.py.

Acknowledgements 🙏

Contributors

GeeeekExplorer

13 commits

cheunglei

1 commits

Languages

Python

100.0%