The Sovereign, Ultra-Fast Fork of Transformers for Low-Bit, Ternary & Wave-Interference Intelligence.
Maintained with love by 8b-is & Peter Lodri.
PyPI:transformers-ultra· Web: transformers.vaked.dev · Sovereign CI: Trusted GitHub Actions.
- 📖 The Origin Story: Why
transformers-ultraExists - 🛡️ Sovereign Hard Fork & Downstream Upgrades
- 🚀 What's New in
transformers-ultra- 1. 🏎️ 1+2+3 Ultra-Hot-Path Inference Acceleration Trio
- 2. 🧬 DYAD Asymmetric Loss Modulation Dual-Head Context & KV Pruner (
dyad_compressor) - 3. 🔄 Continuous Chunked Prefill & Multi-Stream Asynchronous Decode Engine (
ChunkedPrefillDecodeEngine) - 4. 🌉 Apple Silicon Zero-Copy MPS ↔ MLX UMA Memory Bridge (
mlx_mps_bridge) - 5. 🌳 Non-Linear Tree-Based Speculative Drafting Engine (
MedusaTreeFastRunner) - 6. ⚡ Split-KV Flash-Decoding for 32k+ Long Context (
split_kv_decode_attention) - 7. 🔮 Zero-Allocation Speculative Fast Runner (
SpeculativeFastRunner) - 8. 🍎 Apple Silicon Metal (MSL) Simdgroup Matrix Kernels (
metal_msl_kernels) - 9. ⚡ NVIDIA FP8 & Hopper/Blackwell 128-Byte TMA Engine
- 10. 🍏 Apple Silicon UMA & Top Hugging Face GPU Matrix
- 11. 🚀 High-Throughput Memory Allocators & Zero-Pause GC Tuning
- 12. 💎 2-Bit / 1.58-Bit Ternary Packing (
MLX-QUANT) - 13. 🌊 MEM8 Wave-Interference Associative Memory (
hf-mac) - 14. 🏎️ Hot Path Zero-Overhead Generation (>2.2× Speedup)
- 15. 🐍 Modern Python 3.11+ / 3.12+ / 3.13 Runtime Architecture
- 16. 📐 High-Performance Sparse Linear Algebra Engine (
sparsemat/sprs)
- 📦 Quick Installation
- 🧪 Verifying the Test Suite
- 📜 License & Sovereign Heritage
Tired of lying in the sunshine, staying home to watch the rain
And you are young and life is long, and there is time to kill today
And then one day you find ten years have got behind you
No one told you when to run, you missed the starting gun.
— Pink Floyd, Time
This fork was born from a moment of pure bureaucratic absurdity:
Peter Lodri (@peterlodri-sec) opened three PRs against the original upstream repository to fix critical, recurring bugs in 1-bit / 1.58-bit ternary models, BitNet quantization, and Apple Silicon MPS memory leaks. Instead of reviewing the math or benchmarking the speedup, an upstream gatekeeper remarked:
"lol this idiot is spamming MY repo"
...and banned Peter from contributing.
What a weird world. But open source belongs to no single gatekeeper. We didn't complain, we didn't wait for permission—we took the starting gun, fixed every hot path, integrated native Apple Silicon Metal & BitNet kernels, ported MEM8 wave-interference associative memory, eliminated Python reflection overhead from token generation loops, and released transformers-ultra.
8b-is/transformers operates as a 100% sovereign, independent downstream distribution. We maintain our own hardened mainline—incorporating critical community bugfixes, security patches, and Apple Silicon / low-bit acceleration without upstream gatekeeping delays.
-
🕸️ Mesh (Network-Level Router) Top-Level Wrapper:
- Implements a seamless
MeshRouterWrapperthat dispatches token inputs across multiple instantiated HuggingFace experts directly inside theGenerationMixincore loop, allowing Mixture-of-Experts inference over discrete, standalone checkpoints.
- Implements a seamless
-
⚡ Ultra Pydantic Validation Schemas:
- Exposes
UltraGenerationConfigSchemaandUltraQuantizationConfigSchemaalongside theUltraFastCausalLMOutputdataclass for strict, zero-overhead validation (min_new_tokens <= max_new_tokens,do_sampletemperature invariants, andmetal/bitnet/fp8/hqq/eetqbit-width & power-of-twogroup_sizeconstraints) and pattern matching directly from the top-leveltransformersnamespace.
- Exposes
-
🛡️ Chat Template Prompt Injection Defense (#47822):
- Neutralizes turn delimiter injection attacks (
<|im_start|>,<turn|>,[INST]) in user messages viaescape_chat_special_tokenswith zero-width separator protection.
- Neutralizes turn delimiter injection attacks (
-
🏷️ Special Tokens Non-Destructive Merge (#47838):
- Prevents silent discarding of
additional_special_tokenswhenextra_special_tokensis also present in checkpoint configs (e.g. Kimi-VL, OpenCUA, Mistral-Large).
- Prevents silent discarding of
-
⚡ Zero-Redundancy Init on Non-CUDA / MPS / NPU (#47427):
- Generalized
_is_hf_initializedparameter flag checking across all built-in models and accelerators (Apple Silicon MPS, CPU, Ascend NPU), skipping redundant slownormal_weight initialization.
- Generalized
-
📦 CompressedTensors Fused-MoE Expert Dequantization (#47407):
- Properly hooks
WeightConverterandDecompressExpertsto guarantee exact per-expert weight/scale dequantization underdequantize=True/run_compressed=False.
- Properly hooks
- 🌐 6 New Architecture & AutoConfig Aliases:
-
🎧 Whisper Float16 Input Features Auto-Alignment (#47805):
- Automatically aligns
input_featuresdtype toconv1.weight.dtypeinsideWhisperEncoder.forward, allowing seamless manual inference onwhisper-large-v3andwhisper-large-v3-turbowithoutRuntimeError: Input type and bias type should be the same.
- Automatically aligns
-
🔊 HuBERT Positional Conv Zero-Padding Preservation (#47739):
- Preserves zero padding in
HubertPositionalConvEmbeddingwhenconv_pos_batch_norm=Trueby strictly propagating padding masks to prevent cross-sample batch contamination.
- Preserves zero padding in
-
⚡ Continuous Batching Flash Attention Hardware Gating (#47926):
- Gates FlashAttention auto-switching on CUDA SM compute capability (
$\ge 8.0$ ), preventing runtime crashes on pre-Ampere GPUs (Turing T4, Volta V100).
- Gates FlashAttention auto-switching on CUDA SM compute capability (
-
🎙️ ASR Pipeline Stereo Audio Destruction Fix (#47886):
- Dynamically detects channel axis across channels-first and channels-last layouts, averaging across channels instead of collapsing time dimensions.
-
🔊 WhisperFeatureExtractor Non-Finite Sample Protection (#47885):
- Validates audio inputs for NaN/Inf early to prevent a single corrupted sample from poisoning the entire spectrogram matrix into silent garbage transcriptions.
-
⚡ Early Device Validation in
pipeline()(#47869):- Validates device strings and ordinals at pipeline creation before downloading multi-gigabyte models, saving bandwidth and developer time.
-
💾 DynamicCache Oversized Negative Crop Memory Fix (#47433):
- Clamps
crop(-N)andcrop(0)bounds to prevent negative slicing from silently retaining stale tokens in KV cache during rollback.
- Clamps
-
🔤 SentencePiece Byte-Fallback Decoding (#47473):
- Leverages
sp_model.decode()inconvert_tokens_to_stringto properly decode byte-fallback tokens (<0x0A>,<0xF0>).
- Leverages
-
🔄 Added-Tokens Encoder Cache Synchronization (#47439):
- Unifies encoder cache synchronization from
_added_tokens_decodervia_sync_added_tokens()on all mutation paths (CpmAnt, Wav2Vec2, etc.).
- Unifies encoder cache synchronization from
-
📦 Tokenizers 0.23.1+ Security Patch Compatibility (#47429):
- Updated upper bound to
<0.24.0allowing the published 0.23.1 release with XSS fix (AIKIDO-2026-10636).
- Updated upper bound to
-
🛑 Assisted Decoding Mid-Block EOS Termination (#47912):
- Trims committed candidate tokens at the first accepted EOS to prevent speculative/assisted generation from continuing past EOS.
-
⚡ BitNet Sub-Norm Opt-Out (#47957):
- Adds
use_sub_normsconfig flag to bypass RMSNorm sub-layers for weight-quant-only checkpoints (PeetPedro/quantal-ternary).
- Adds
-
📐 Grounding DINO Int64 Positional Embedding Fix (#47674):
- Casts
text_position_idstotext_features.dtypebefore computing sinusoids, preventing 93% of position embeddings from collapsing to zero.
- Casts
-
🎯 SigLIP2 Vocab Size Synchronization (#47612):
- Automatically synchronizes
vocab_sizefromtext_configto eliminate false out-of-vocab warnings for BOS/EOS tokens.
- Automatically synchronizes
-
📊 Gauge-Independent Normalized Repetition Penalty (#47595):
- Added
normalize=Trueoption usinglog_softmaxto eliminate gauge shift artifacts in repetition penalty.
- Added
-
🧬 ESMFold FP16 Argmax Robustness (#47470):
- Uses
torch.argmaxincompute_tmto avoidIndexErrorcrashes under half-precision inference.
- Uses
-
🌐 Gemma-4 Auto Architecture Recognition (#47448):
- Added
gemma4andgemma4_unifiedmappings to AutoConfig.
- Added
-
🔒 Sharded Checkpoint Path Traversal Security Hardening (#47176):
- Validates and sanitizes all
weight_mapshard filenames inget_checkpoint_shard_filesto strictly block path traversal (../) and arbitrary out-of-directory file reads.
- Validates and sanitizes all
-
⚙️ Deterministic Generation Config Precedence (#47752):
- Ensures user-configured
model.generation_configvalues are strictly preserved over pipeline defaults inPipeline.__init__with torch-optional runtime safety.
- Ensures user-configured
-
📐 Gradient Accumulation Loss kwargs Propagation (#47688):
- Forwards
**kwargs(num_items_in_batch) toself.loss_functionacrossGenericForSequenceClassification,GenericForTokenClassification,Swinv2,ResNet,CLIP,SigLIP, andSigLIP2classification heads.
- Forwards
-
🍏 Apple Silicon Metal & MPS Runtime Hardening (
hf-mac):- Unified single-device
torch.device("mps")assignment in pipelines, eliminatingRuntimeError: Invalid device string 'mps:0'. - Resilient
safe_openbuffer staging fallback for safetensors on macOS unified memory. - Decoupled
_AutogradFunctionabstractions intensor_parallel.py,accelerate.py, andmonkey_patching.pyfor cross-platform imports.
- Unified single-device
-
⚡ Quantized PEFT Allocation Crash Fix (#47914):
- Resolves
caching_allocator_warmupAttributeErrorwhen loading bitsandbytes quantized models with PEFT adapters.
- Resolves
-
📝 MistralCommonBackend Doc Rendering Fix (#47504):
- Dynamically bypassed
mistral_commondependency checking at module initialization to allow proper docstring parsing forMistralCommonBackendwithout falling back to a dummy object.
- Dynamically bypassed
-
🏎️ 1+2+3 Ultra-Hot-Path Inference Acceleration Trio:
-
SlottedStaticCache(Zero-Allocation Decoding): Pre-allocates contiguous(batch_size, num_heads, max_cache_len, head_dim)buffers once and uses in-place slice copies (copy_()), eliminating$100%$ of dynamic CUDA allocations and memory fragmentation during autoregressive decoding. -
CUDAGraphFastRunner(<5µs Dispatch Latency): Records single-token forward passes into static CUDA Graphs with dedicated warmup streams, bypassing Python CPU interpreter overhead and dropping token stepping latency from ~120µs to <5µs. -
FusedLogitsSampler(O(K) In-Register Sampling): Fused single-pass temperature scaling, Top-K reduction, Top-P nucleus cumulative probability filtering, and multinomial sampling in a single contiguous sequence, cutting sampling overhead by up to 80% on large vocabularies ($V \ge 32k$ ).
-
-
🧬 DYAD Asymmetric Loss Modulation Dual-Head Context & KV Pruner (
dyad_compressor):- Implements the DYAD / kompress-v8 dual-head architecture (
TokenClassifierHead+SpanCNNHead) coupled via the asymmetric modulation gate $\tilde{I}i(x) = \sigma(\text{logit}{\text{tok}}(x) - \gamma \cdot \text{ReLU}(\text{logit}_{\text{span}}(x)))$. - Resolves the Voting Ensemble Paradox and protects critical syntactic anchor tokens (signal names, file paths, exit codes, CLI flags, hex pointers).
- Mechanism B sliding-window subword regex safety net (
MUST_KEEP_PATTERN) and in-place$O(1)$ SlottedStaticCacheKV slot compaction.
- Implements the DYAD / kompress-v8 dual-head architecture (
-
🔄 Continuous Chunked Prefill & Multi-Stream Asynchronous Decode Engine (
ChunkedPrefillDecodeEngine):- Slices long prompt prefills into bounded chunks (e.g. 512 tokens) and interleaves them with active sequence decode steps.
- Eliminates time-to-first-token (TTFT) stalls and prevents inter-token decode latency spikes (jitter).
-
🌉 Apple Silicon Zero-Copy MPS ↔ MLX UMA Memory Bridge (
mlx_mps_bridge):- Direct unified memory pointer aliasing via DLPack (
torch_to_mlx,mlx_to_torch) with zero system RAM copies. -
MlxMpsHybridLinear: Executes MLX Metal SIMD matrix multiplication directly on PyTorch MPS activation tensors.
- Direct unified memory pointer aliasing via DLPack (
-
🌳 Non-Linear Tree-Based Speculative Drafting Engine (
MedusaTreeFastRunner):- Generates candidate token trees with pre-computed 2D causal visibility masks (
MedusaTreeTopology). - Verifies multiple speculative branches simultaneously in a single target model forward pass.
-
$O(1)$ KV-cache rollback to the longest accepted branch depth viaSlottedStaticCache.crop().
- Generates candidate token trees with pre-computed 2D causal visibility masks (
-
⚡ Split-KV Flash-Decoding Attention for 32k+ Long Context (
split_kv_decode_attention):- Partitions long sequence dimension (
$32k\text{--}128k+$ tokens) into parallel GPU SM splits (BLOCK_N=512), achieving$100%$ SM occupancy even with$B=1$ . - Online multi-split log-sum-exp reduction (
_split_kv_stage2_kernel) merging partial softmax states with zero precision loss.
- Partitions long sequence dimension (
-
🔮 Zero-Allocation Speculative Decoding Engine (
SpeculativeFastRunner):- Pairs draft and target models with pre-allocated slotted acceptance trees.
- Executes parallel verification of
$K$ candidate tokens in a single target forward pass. -
$O(1)$ KV-cache rollback viacache.crop()onSlottedStaticCacheupon candidate rejection.
-
🍎 Apple Silicon Metal (MSL) Simdgroup Matrix Kernels (
metal_msl_kernels):- Native Metal Shading Language (MSL) compute shaders (
METAL_BITNET_TERNARY_GEMM_MSL,METAL_FP8_DYNAMIC_GEMM_MSL) targeting Apple M1/M2/M3/M4 GPUs. - Vectorized 16-trit per
uint322-bit bitmask unpacking and hardware-accelerated ternary GEMM (metal_bitnet_matmul,MetalBitNetLinear). - Dynamic FP8 (E4M3/E5M2) hardware matrix multiplication with scale fusion (
metal_fp8_matmul,MetalFp8Linear).
- Native Metal Shading Language (MSL) compute shaders (
-
⚡ NVIDIA FP8 & Hopper/Blackwell 128-Byte TMA Engine:
- Native 128-byte hardware
CUtensorMapbinary memory layout matching NVIDIA Hopper SM90+ (H100/H200) and Blackwell SM100+ (B200) specifications. - Direct C ABI structure (
CUtensorMapStruct) and in-place zero-allocation buffer packing (TmaDescriptor.pack_into). - Hardware-accelerated FP8 GEMM via
torch._scaled_mmwith fast accumulation and dynamic scaling (fp8_dynamic_quantize). - Full AutoQuantizer pipeline integration (
NvidiaFp8TmaConfig,NvidiaFp8TmaHfQuantizer).
- Native 128-byte hardware
-
🍏 Apple Silicon UMA & Top Hugging Face GPU Fleet Intelligence:
- Native Darwin ARM64 detection, zero-copy Unified Memory Architecture query (
sysctl hw.memsize), MPS cache flushing (torch.mps.empty_cache()), and MLX availability resolver. - Comprehensive compute tier classifier (
get_hf_gpu_tier): B200, H200, H100, MI300X, L40S, A100, L4, A10G, T4, Apple Silicon, Gaudi, and Neuron. - Automated attention backend resolution (
get_recommended_attention_backend->flash_attention_3,flash_attention_2,sdpa,eager).
- Native Darwin ARM64 detection, zero-copy Unified Memory Architecture query (
-
🚀 High-Throughput Memory Allocators & Zero-Pause GC Tuning (
memory_tuning):-
mimallocandjemallocautomatic process detection and low-latency environment tuning (MIMALLOC_LARGE_OS_PAGES=1,PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"). - Generational GC object freezing (
gc.freeze()) to skip weight graph scans during inference. -
no_gc_cycle()context manager to eliminate stop-the-world GC pauses during token generation loops. -
FastTmaBufferPoolfor zero-allocation C buffer acquisition and recycling.
-
-
2-Bit / 1.58-Bit Ternary Packing (
MLX-QUANT):- Ported native ternary bitmask packing & unpacking (
quantize_ternary_numpy,unpack_ternary_numpy) insrc/transformers/integrations/bitnet_mlx.py(commit476ebc6). - Native Apple Silicon
MPSaccelerator detection and memory view optimizations insrc/transformers/quantizers/quantizer_bitnet.py.
- Ported native ternary bitmask packing & unpacking (
-
MEM8 Wave-Interference Associative Memory (
hf-mac):
- Neural wave interference memory engine (
MEM8Wave,MEM8MemoryStore) operating across four distinct cognitive frequency bands (Math$\Gamma$ , Code$\text{B}$ , Reasoning$\text{A}$ , General$\Theta$ ) insrc/transformers/integrations/mem8_wave.py(commit476ebc6).
- Hot Path Zero-Overhead Generation (>2.2× Speedup):
- Eliminated per-token
inspect.signatureAST parsing inLogitsProcessorList.__call__via class-level signature caching (_cached_signatures) insrc/transformers/generation/logits_process.py(commit476ebc6). - Dimension-guarded RoPE embeddings across Llama, Gemma, Gemma2, Starcoder2, Mixtral, Cohere, Phi3, and GPT-NeoX in
src/transformers/models/to eliminate redundantunsqueezememory view allocations (commitf736202). - Dynamic KV Cache prefill bypasses
torch.caton empty tensors for direct tensor assignment insrc/transformers/cache_utils.py(commit476ebc6).
- Modern Python 3.11+ / 3.12+ / 3.13 Runtime Architecture:
- Modernized baseline to Python 3.11+ (
target-version = "py311",python_requires = ">=3.11.0"). - Replaced bloated dynamic dictionaries with
__slots__memory layouts across wave states and descriptors, dropping per-object memory overhead by up to 50%. - Integrated
StrEnumfor zero-overhead string enum comparisons and structuralmatch/casepattern matching. - Thread-safe synchronization on memory stores for native Python 3.13 free-threaded (
nogil) execution.
- Pydantic v2 Ingress & Slotted Dataclass Fast-Path Engine:
- Rust-core Pydantic v2 validation schemas (
UltraGenerationConfigSchema,UltraQuantizationConfigSchema) for strict, rapid ingress deserialization. - Zero-overhead
@dataclass(slots=True, kw_only=True)inference containers (UltraFastCausalLMOutput) for lightning-fast pattern matching in model outputs.
# Install the ultra-fast fork
pip install transformers-ultra
English | 简体中文 | 繁體中文 | 한국어 | Español | 日本語 | हिन्दी | Русский | Português | తెలుగు | Français | Deutsch | Italiano | Tiếng Việt | العربية | اردو | বাংলা | فارسی | Türkçe |
Transformers acts as the model-definition framework for state-of-the-art machine learning with text, computer vision, audio, video, and multimodal models, for both inference and training.
It centralizes the model definition so that this definition is agreed upon across the ecosystem. transformers is the
pivot across frameworks: if a model definition is supported, it will be compatible with the majority of training
frameworks (Axolotl, Unsloth, DeepSpeed, FSDP, PyTorch-Lightning, ...), inference engines (vLLM, SGLang, TGI, ...),
and adjacent modeling libraries (llama.cpp, mlx, ...) which leverage the model definition from transformers.
We pledge to help support new state-of-the-art models and democratize their usage by having their model definition be simple, customizable, and efficient.
There are over 1M+ Transformers model checkpoints on the Hugging Face Hub you can use.
Explore the Hub today to find a model and use Transformers to help you get started right away.
Transformers works with Python 3.10+, and PyTorch 2.5+.
Create and activate a virtual environment with venv or uv, a fast Rust-based Python package and project manager.
# venv
python -m venv .my-env
source .my-env/bin/activate
# uv
uv venv .my-env
source .my-env/bin/activateInstall Transformers in your virtual environment.
# pip
pip install "transformers[torch]"
# uv
uv pip install "transformers[torch]"Install Transformers from source if you want the latest changes in the library or are interested in contributing. However, the latest version may not be stable. Feel free to open an issue if you encounter an error.
git clone https://github.com/huggingface/transformers.git
cd transformers
# pip
pip install '.[torch]'
# uv
uv pip install '.[torch]'Get started with Transformers right away with the Pipeline API. The Pipeline is a high-level inference class that supports text, audio, vision, and multimodal tasks. It handles preprocessing the input and returns the appropriate output.
Instantiate a pipeline and specify model to use for text generation. The model is downloaded and cached so you can easily reuse it again. Finally, pass some text to prompt the model.
from transformers import pipeline
pipeline = pipeline(task="text-generation", model="Qwen/Qwen2.5-1.5B")
pipeline("the secret to baking a really good cake is ")
[{'generated_text': 'the secret to baking a really good cake is 1) to use the right ingredients and 2) to follow the recipe exactly. the recipe for the cake is as follows: 1 cup of sugar, 1 cup of flour, 1 cup of milk, 1 cup of butter, 1 cup of eggs, 1 cup of chocolate chips. if you want to make 2 cakes, how much sugar do you need? To make 2 cakes, you will need 2 cups of sugar.'}]To chat with a model, the usage pattern is the same. The only difference is you need to construct a chat history (the input to Pipeline) between you and the system.
Tip
You can also chat with a model directly from the command line, as long as transformers serve is running.
transformers chat Qwen/Qwen2.5-0.5B-Instructimport torch
from transformers import pipeline
chat = [
{"role": "system", "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."},
{"role": "user", "content": "Hey, can you tell me any fun things to do in New York?"}
]
pipeline = pipeline(task="text-generation", model="meta-llama/Meta-Llama-3-8B-Instruct", dtype=torch.bfloat16, device_map="auto")
response = pipeline(chat, max_new_tokens=512)
print(response[0]["generated_text"][-1]["content"])Expand the examples below to see how Pipeline works for different modalities and tasks.
Automatic speech recognition
from transformers import pipeline
pipeline = pipeline(task="automatic-speech-recognition", model="openai/whisper-large-v3")
pipeline("https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac")
{'text': ' I have a dream that one day this nation will rise up and live out the true meaning of its creed.'}Image classification
from transformers import pipeline
pipeline = pipeline(task="image-classification", model="facebook/dinov2-small-imagenet1k-1-layer")
pipeline("https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png")
[{'label': 'macaw', 'score': 0.997848391532898},
{'label': 'sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita',
'score': 0.0016551691805943847},
{'label': 'lorikeet', 'score': 0.00018523589824326336},
{'label': 'African grey, African gray, Psittacus erithacus',
'score': 7.85409429227002e-05},
{'label': 'quail', 'score': 5.502637941390276e-05}]Visual question answering
from transformers import pipeline
pipeline = pipeline(task="visual-question-answering", model="Salesforce/blip-vqa-base")
pipeline(
image="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/idefics-few-shot.jpg",
question="What is in the image?",
)
[{'answer': 'statue of liberty'}]-
Easy-to-use state-of-the-art models:
- High performance on natural language understanding & generation, computer vision, audio, video, and multimodal tasks.
- Low barrier to entry for researchers, engineers, and developers.
- Few user-facing abstractions with just three classes to learn.
- A unified API for using all our pretrained models.
-
Lower compute costs, smaller carbon footprint:
- Share trained models instead of training from scratch.
- Reduce compute time and production costs.
- Hundreds of model architectures with 1M+ pretrained checkpoints across all modalities.
-
Choose the right framework for every part of a model's lifetime:
- Train state-of-the-art models in 3 lines of code.
- Move a single model between PyTorch/JAX/TF2.0 frameworks at will.
- Pick the right framework for training, evaluation, and production.
-
Easily customize a model or an example to your needs:
- We provide examples for each architecture to reproduce the results published by its original authors.
- Model internals are exposed as consistently as possible.
- Model files can be used independently of the library for quick experiments.
- This library is not a modular toolbox of building blocks for neural nets. The code in the model files is not refactored with additional abstractions on purpose, so that researchers can quickly iterate on each of the models without diving into additional abstractions/files.
- The training API is optimized to work with PyTorch models provided by Transformers. For generic machine learning loops, you should use another library like Accelerate.
- The example scripts are only examples. They may not necessarily work out-of-the-box on your specific use case and you'll need to adapt the code for it to work.
Transformers is more than a toolkit to use pretrained models, it's a community of projects built around it and the Hugging Face Hub. We want Transformers to enable developers, researchers, students, professors, engineers, and anyone else to build their dream projects.
In order to celebrate Transformers 100,000 stars, we wanted to put the spotlight on the community with the awesome-transformers page which lists 100 incredible projects built with Transformers.
If you own or use a project that you believe should be part of the list, please open a PR to add it!
You can test most of our models directly on their Hub model pages.
Expand each modality below to see a few example models for various use cases.
Audio
Computer vision
- Automatic mask generation with SAM
- Depth estimation with DepthPro
- Image classification with DINO v2
- Keypoint detection with SuperPoint
- Keypoint matching with SuperGlue
- Object detection with RT-DETRv2
- Pose Estimation with VitPose
- Universal segmentation with OneFormer
- Video classification with VideoMAE
Multimodal
- Audio or text to text with Voxtral, Audio Flamingo
- Document question answering with LayoutLMv3
- Image or text to text with Qwen-VL
- Image captioning BLIP-2
- OCR-based document understanding with GOT-OCR2
- Table question answering with TAPAS
- Unified multimodal understanding and generation with Emu3
- Vision to text with Llava-OneVision
- Visual question answering with Llava
- Visual referring expression segmentation with Kosmos-2
NLP
sparsemat/sprs is the official sparse linear algebra foundation for transformers-ultra and the sovereign constellation:
-
Compressed Sparse Row (CSR) & Column (CSC) Structures:
Enables zero-allocation Sparse Matrix Multiplication (
$\text{SpMM}$ ) and Sparse Matrix-Vector Multiplication ($\text{SpMV}$ ) for token positions pruned by the DYAD Asymmetric Loss Modulation Engine. -
$O(\text{nnz})$ Linear Scalability: When context masks are pruned to 10%–30% density,sprsrepresentation cuts attention FLOPs from$O(N^2)$ to$O(\text{nnz})$ , eliminating memory bandwidth bottlenecks. -
Ternary BitNet 1.58b Structural Sparsity:
Leverages zero-weight sparsity in ternary networks (
${-1, 0, +1}$ ) to skip arithmetic operations entirely, usingsprscompressed index traversal.
use sprs::{CsMatI, TriMatI};
// Constructing a DYAD sparse attention mask kernel (O(nnz) compute)
let mut tri = TriMatI::<f32, u32>::new((seq_len, seq_len));
for (row, col, weight) in dyad_sparse_entries {
tri.add_triplet(row, col, weight);
}
let csr_attention_mask: CsMatI<f32, u32> = tri.to_csr();We now have a paper you can cite for the 🤗 Transformers library:
@inproceedings{wolf-etal-2020-transformers,
title = "Transformers: State-of-the-Art Natural Language Processing",
author = "Thomas Wolf and Lysandre Debut and Victor Sanh and Julien Chaumond and Clement Delangue and Anthony Moi and Pierric Cistac and Tim Rault and Rémi Louf and Morgan Funtowicz and Joe Davison and Sam Shleifer and Patrick von Platen and Clara Ma and Yacine Jernite and Julien Plu and Canwen Xu and Teven Le Scao and Sylvain Gugger and Mariama Drame and Quentin Lhoest and Alexander M. Rush",
booktitle = "Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
month = oct,
year = "2020",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2020.emnlp-demos.6/",
pages = "38--45"
}- Weight-quant-only BitLinear: set
use_sub_norms=FalseinBitNetConfigfor zero-overhead ternary checkpoints (PeetPedro/quantal-ternary). - Apple Silicon UMA Acceleration: native Metal kernel integration via
MLX-QUANT.



