DailyGlimpse

Why Hugging Face Transformers Breaks the 'Don't Repeat Yourself' Rule

AI
April 26, 2026 · 5:39 PM
Why Hugging Face Transformers Breaks the 'Don't Repeat Yourself' Rule

The Hugging Face Transformers library deliberately forgoes the classic software engineering principle "Don't Repeat Yourself" (DRY) in favor of a "single model file" policy. This means each model's forward pass code lives entirely in one file, even if it means duplicating attention mechanisms across dozens of models. The team's reasoning is rooted in community needs, the speed of ML research, and the static nature of published models.

1. Built for the open-source community – By keeping model code self-contained, contributors can fix bugs or add new models without worrying about breaking unrelated architectures. Reviewers can easily verify that only the new model is affected.

2. Modeling code is the product – Many users read and modify source code, not just documentation. A single file makes it easier to understand and adapt a model, which is critical for a library forked over 10,000 times and cited thousands of times.

3. ML evolves at breakneck speed – Attention mechanisms and other components change rapidly. Abstracting them into central files would require constant renaming and rethinking. Model-specific naming within each file avoids this confusion.

4. ML models are static – Once published, models rarely change. Duplicating code across files incurs no maintenance burden, and it keeps each model's implementation self-contained.

While this approach increases code duplication, the team argues it's a deliberate trade-off for clarity, community contribution, and adaptability in a fast-moving field. The result: a library that prioritizes human readability over computational perfection.