{"id":28438,"library":"vit-pytorch","title":"ViT PyTorch","description":"A PyTorch implementation of the Vision Transformer (ViT) and related vision transformer architectures. Current version 1.20.4, actively maintained with frequent releases.","status":"active","version":"1.20.4","language":"python","source_language":"en","source_url":"https://github.com/lucidrains/vit-pytorch","tags":["vision-transformer","pytorch","vit","attention","image-classification"],"install":[{"cmd":"pip install vit-pytorch","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for tensor operations and neural network modules.","package":"torch","optional":false},{"reason":"Required for rearrange and reduce operations used in the transformer.","package":"einops","optional":false}],"imports":[{"note":"Old import path no longer works; use top-level import.","wrong":"from vit_pytorch.vit import ViT","symbol":"ViT","correct":"from vit_pytorch import ViT"}],"quickstart":{"code":"import torch\nfrom vit_pytorch import ViT\n\nv = ViT(\n    image_size=256,\n    patch_size=32,\n    num_classes=1000,\n    dim=1024,\n    depth=6,\n    heads=16,\n    mlp_dim=2048,\n    dropout=0.1,\n    emb_dropout=0.1\n)\n\nimg = torch.randn(1, 3, 256, 256)\npreds = v(img)  # (1, 1000)","lang":"python","description":"Basic instantiation and forward pass of a Vision Transformer."},"warnings":[{"fix":"Use 'pip install vit-pytorch' and 'from vit_pytorch import ViT'.","message":"In version 1.0.0, the package was renamed from 'vit_pytorch' to 'vit-pytorch' on PyPI, but the import remains 'vit_pytorch'. Ensure you install with 'vit-pytorch' but import with 'vit_pytorch'.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use 'from vit_pytorch import ViT'.","message":"Common mistake: using the wrong import path. Many users try 'from vit_pytorch.vit import ViT' which fails. The correct import is 'from vit_pytorch import ViT'.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Upgrade to the latest version with 'pip install --upgrade vit-pytorch' and use 'from vit_pytorch import ViT'.","cause":"Using an older version where the API was different or the package was not properly installed.","error":"ImportError: cannot import name 'ViT' from 'vit_pytorch'"},{"fix":"Install with 'pip install vit-pytorch' (hyphen) and import with 'import vit_pytorch' (underscore).","cause":"Installed the wrong package name ('vit-pytorch' vs 'vit_pytorch') or not installed at all.","error":"ModuleNotFoundError: No module named 'vit_pytorch'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}