vit-pytorch
Vision Transformer (ViT) - Pytorch
What it is and what it does
vit-pytorch is a collection of PyTorch implementations of Vision Transformer architectures and related vision models. It provides the core ViT model alongside numerous variants—SimpleViT, NaViT, CaiT, Token-to-Token ViT, LeViT, MobileViT, and others—each addressing different efficiency or accuracy trade-offs. The package also includes support for self-supervised learning techniques like masked autoencoders and masked image modeling, as well as knowledge distillation from convolutional networks.
The library is designed for researchers and practitioners building image classification systems with transformers. It depends on torch for computation, torchvision for standard vision utilities, and einops for flexible tensor reshaping. Models are instantiated with configurable parameters (patch size, embedding dimension, depth, attention heads, dropout rates) and accept batches of images as input, returning class predictions or intermediate representations.
Use it for:
- Train a vision transformer from scratch on a custom image classification dataset using the base ViT or SimpleViT variant
- Distill knowledge from a pretrained ResNet or other CNN teacher into a smaller, faster ViT student model
- Implement masked image modeling or masked autoencoder pretraining for self-supervised representation learning
- Experiment with variable-resolution image batching using NaViT for faster training on mixed-size datasets
- Deploy efficient vision models on resource-constrained devices using MobileViT or LeViT variants
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides PyTorch implementations of Vision Transformer (ViT) and related transformer-based vision models for image classification and self-supervised learning tasks.
Yes. The package is actively maintained, has low install friction, carries permissive MIT licensing, and offers a comprehensive suite of transformer vision models backed by recent research. It is well-suited for both research prototyping and production image classification systems. No known vulnerabilities.
Install
vit-pytorch on PyPI
pip
pip install vit-pytorchuv
uv add vit-pytorchpoetry
poetry add vit-pytorchInstalling vit-pytorch
Before you install
Low install friction with a pure Python wheel. Actively maintained with a recent release. Depends on torch and torchvision, which are standard deep learning libraries, plus einops for tensor operations.
License in practice
MIT License permits free use, modification, and distribution with minimal restrictions—suitable for both research and commercial projects.
Quickstart
pip install vit-pytorch
import torch
from vit_pytorch import ViT
v = ViT(
image_size=256,
patch_size=32,
num_classes=1000,
dim=1024,
depth=6,
heads=16,
mlp_dim=2048
)
img = torch.randn(1, 3, 256, 256)
preds = v(img)
Requires torch and torchvision to be installed; GPU recommended for practical training but not required for inference on small batches.
Verify before relying
- Whether pretrained model weights are included or must be sourced separately
- GPU memory requirements for different model variants and batch sizes
- Training time and convergence characteristics compared to CNN baselines
Package facts
| License | MIT License Copyright (c) 2020 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — einops, torch, torchvision |
| Maintenance | actively maintained — 12 days since the last release |
| First released | |
| Downloads | 184,548/month — #10,033 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: vit_pytorch-1.24.2-py3-none-any.whl
Keywords: artificial intelligence, attention mechanism, image recognition
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
conformerProvides PyTorch implementations of the…
permissive · top 15,000 on PyPI
timmTimm provides a large collection of pretrained…
permissive · top 5,000 on PyPI
vector-quantize-pytorchImplements vector quantization layers for…
permissive · top 5,000 on PyPI
x-transformersx-transformers provides modular transformer…
permissive · top 5,000 on PyPI
rotary-embedding-torchImplements rotary positional embeddings for…
permissive · top 15,000 on PyPI
CoLT5-attentionImplements conditionally routed efficient…
permissive · top 15,000 on PyPI
local-attentionImplements local windowed attention for…
permissive · top 15,000 on PyPI
axial-positional-embeddingProvides axial positional embeddings for…
permissive · top 15,000 on PyPI
rfdetrRF-DETR is a transformer-based object…
permissive · top 15,000 on PyPI
ema-pytorchMaintains an exponential moving average (EMA)…
permissive · top 15,000 on PyPI