---
title: "~Don't~ Repeat Yourself"
description: "Hugging Face's Transformers library intentionally departs from the traditional \"Don't repeat yourself\" (DRY) software design principle by adopting a single model file policy. This architecture places all code required for a model's forward pass into a dedicated file, avoiding centralized shared modules for components like attention mechanisms. Because machine learning research evolves rapidly and published model architectures remain static, isolating code protects individual models from breaking changes and lowers contribution barriers for the open-source community. To maintain consistency without manually syncing duplicated code across successor models, the library uses automated tooling driven by Copied from comments. While this approach complicates unified API enforcement and component-wide research integration, Transformers validates API consistency by running approximately 20,000 automated tests daily."
---

# ~Don't~ Repeat Yourself

huggingface.co · Patrick von Platen · Apr 5, 2022

**Type:** Explainer

## Summary

Hugging Face's Transformers library intentionally departs from the traditional "Don't repeat yourself" (DRY) software design principle by adopting a single model file policy. This architecture places all code required for a model's forward pass into a dedicated file, avoiding centralized shared modules for components like attention mechanisms. Because machine learning research evolves rapidly and published model architectures remain static, isolating code protects individual models from breaking changes and lowers contribution barriers for the open-source community. To maintain consistency without manually syncing duplicated code across successor models, the library uses automated tooling driven by Copied from comments. While this approach complicates unified API enforcement and component-wide research integration, Transformers validates API consistency by running approximately 20,000 automated tests daily.

## Context

Traditional DRY architecture centralizes shared logic into common abstractions, but rapid evolution and static published architectures in machine learning mean common abstractions can cause brittle cross-model dependencies and demotivating test failures for open-source contributors.

## Approach / What changed

Transformers implements a single model file policy containing all forward-pass code within each model's file. Maintainers keep successor models synchronized with predecessors via a copying mechanism using '# Copied from' annotations and automated update tools, while running approximately 20,000 daily tests to maintain a unified API.

## Takeaways

- The single model file policy places all forward-pass logic in a single file per model, preventing bug fixes or additions in one model from triggering failures across other models.
- To balance single-file isolation with maintainability across successor architectures, Transformers marks identical functions with '# Copied from' statements and uses automated tools to sync updates.
- Decoupling model files complicates the integration of research that modifies only a single sub-component across all existing architectures, and it requires around 20,000 daily tests to ensure API consistency.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Machine Learning](https://yomu.fyi/topic/machine-learning), [Open Source](https://yomu.fyi/topic/open-source), [Python](https://yomu.fyi/topic/python)

- Source: [huggingface.co](https://huggingface.co/blog/transformers-design-philosophy)
- Source URL: https://huggingface.co/blog/transformers-design-philosophy
- Ingested by Yomu: 2026-08-27T15:08:49.609Z

[Read original post](https://huggingface.co/blog/transformers-design-philosophy)
