skillfed

vit-pytorch

Vision Transformer (ViT) - Pytorch

vit-pytorch v1.24.2 184.5K downloads/30d#10,033 on PyPI
Permissive 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) Active released

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-pytorch

uv

uv add vit-pytorch

poetry

poetry add vit-pytorch

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

vision transformer pytorchimage classification transformervit implementationtransformer vision modelsself-supervised vision learningmasked image modelingattention-based image recognition
transformer-visionself-supervised-learningknowledge-distillation

More Artificial Intelligence packages

Further reading