Skip to main content

vimod

vimod

What is this?

vimod provides clean, modular building blocks for custom Vision Transformers in PyTorch. No model zoos, no pretrained weights, no heavy frameworks - just readable, production-grade components designed to be mixed, matched, and hacked on.

Quickstart

pip install vimod

Examples

See full example codes in examples.

Transformer Block with Pre-Norm and DropPath

class Block(nn.Module):
    def __init__(self, dim, heads, drop_path=0.0):
        super().__init__()
        self.attn = Attention(dim, heads, pre_norm_layer=nn.LayerNorm)
        self.mlp = MLP(dim, pre_norm_layer=nn.LayerNorm)
        self.drop_path = DropPath(drop_path)

    def forward(self, x):
        x = x + self.drop_path(self.attn(x))
        x = x + self.drop_path(self.mlp(x))
        return x

ViT Architecture with Patch Embedding, Positional Embedding, and Classification Head

class ViT(nn.Module):
    def __init__(self, image_size, patch_size, dim, depth, heads, num_classes):
        super().__init__()
        grid = image_size // patch_size

        self.patch_embed = PatchEmbed(3, dim, patch_size)
        self.pos_embed = SinCosPosEmbed(dim, grid)
        self.blocks = Stack(Block, depth=depth, dim=dim, heads=heads, drop_path=0.1)
        self.head = MeanPoolHead(dim, num_classes)

    def forward(self, x):
        x = self.patch_embed(x)
        x = self.pos_embed(x)
        x = self.blocks(x)
        return self.head(x)

Optimizer with proper Weight Decay Handling

optimizer = Optimizer(model, torch.optim.AdamW, lr=3e-4, weight_decay=0.05)

Modules

Module What it does
PatchEmbed Projects image patches into token embeddings.
PrefixTokens Prepends learned prefix tokens (e.g., class or register tokens).
LearnedAbsolutePosEmbed Adds learned absolute position embeddings to tokens.
SinCosPosEmbed Adds fixed 2D sinusoidal position codes to tokens.
RoPE2D Applies axial 2D rotary position embeddings to queries and keys.
Attention Supports MHA, GQA, pre-norm, QK-norm, and RoPE integration.
MLP / SwiGLU Feed-forward blocks with optional pre-norm and activation layers.
MeanPoolHead Mean-pools spatial tokens and projects to output classes.
DropPath Applies per-sample stochastic depth (drop path).
Stack Repeats any block class for a specified depth.
Optimizer Wraps any torch.optim class with automatic weight-decay grouping.

Changelog

0.1.0

  • Initial release: PatchEmbed, LearnedAbsolutePosEmbed, SinCosPosEmbed, RoPE2D, Attention, MLP, SwiGLU, MeanPoolHead, PrefixTokens, DropPath, Stack, Optimizer

⭐ Support the Project

Find it useful? Drop a star ⭐ to help others discover it.

License

The project is licensed under the Apache License 2.0.

Metadata

Release files for vimod 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vimod 0.1.0
File Size Uploaded Provenance Actions
vimod-0.1.0.tar.gz 58.1 kB Without provenance Details for vimod-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vimod 0.1.0
File Interpreter ABI Platform Actions
vimod-0.1.0-py3-none-any.whl Python 3 none any Details for vimod-0.1.0-py3-none-any.whl

Total release size: 64.6 kB

Release files / vimod-0.1.0.tar.gz

Download URL vimod-0.1.0.tar.gz
Size 58.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b41d93b24450901df74ac157fbbc0874eeab74ee54adfbf7b3a1ae796364f995
BLAKE2b-256 checksum
How to use checksums
c5f0cd1fa876888a05838531dd272684f68e8142b5f94cdabbca0cadf5bc03ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / vimod-0.1.0-py3-none-any.whl

Download URL vimod-0.1.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed4bd3aa451088dbb0c96246f1b5597d7230a3b2b102082ad4a6b518fef7032d
BLAKE2b-256 checksum
How to use checksums
57c83e3a5ebacdd0391bfa6afbc477634889ad8e7ae6004e82593e7ac3b9a236
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for vimod 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page