Skip to main content

Philosophy

Transformers is a PyTorch-first library. Hugging Face aims for models that are faithful to their papers, easy to use, and easy to hack.

Adapted for this playbook from the πŸ€— Transformers documentation by Hugging Face. Official page: https://huggingface.co/docs/transformers/philosophy. Images Β© Hugging Face (documentation-images) unless noted. This is not a substitute for the upstream docs β€” verify against the current version.

Covers Hugging Face pages: philosophy

Who it is for​

  • Researchers and educators extending architectures
  • Practitioners fine-tuning, evaluating or serving models
  • Engineers who want a pretrained model with a predictable API

Three core classes​

ClassRole
ConfigurationHyperparameters (layers, hidden size, …)
Modeltorch.nn.Module wrapped by PreTrainedModel
PreprocessorTokenizer, image/video processor, feature extractor, or multimodal processor

All support:

  • from_pretrained() β€” download/cache/load from Hub or disk
  • save_pretrained() β€” write a local folder
  • push_to_hub() β€” share to the Hub

High-level APIs​

  • pipeline β€” task inference with sensible defaults
  • Trainer β€” train / fine-tune PyTorch models with mixed precision, compile, FlashAttention, distributed helpers

Core tenets (Hugging Face)​

From the official philosophy (also expanded in the Transformers tenets space):

  1. Source of truth β€” faithful to official results and intended behaviour
  2. One model, one file β€” core logic readable top-to-bottom
  3. Code is the product β€” optimise for reading and diffing
  4. Standardise, don’t abstract β€” model-specific behaviour stays in the model
  5. DRY* (repeat when it helps users) β€” end-user modelling files stay self-contained; infra is factored out
  6. Minimal user API β€” few code paths, predictable kwargs
  7. Backwards compatibility β€” Hub artefacts keep working
  8. Consistent public surface β€” naming, outputs, diagnostics aligned

Modular Transformers​

Contributors write a small modular_*.py shard; the library expands it into the visible modeling_*.py users read. That preserves β€œone model, one file” without boilerplate drift. See Hugging Face’s modular transformers guide.

Enterprise takeaway​

Standardising on Transformers reduces vendor lock-in at the definition layer: the same checkpoint can move between research notebooks, Trainer jobs and production engines that consume Hugging Face model definitions.

Discussion

Comments​

Share feedback or questions about this page. No account required.

Loading comments…