Skip to main content

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.1

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.1
File Size Uploaded Provenance Actions
vimod-0.1.1.tar.gz 9.8 kB Without provenance Details for vimod-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 23.1 kB

Release files / vimod-0.1.1.tar.gz

Download URL vimod-0.1.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d845f1b51dd6a304c84909964d45787d3976b97ac3c1720e104a291fc1061743
BLAKE2b-256 checksum
How to use checksums
0b977a26901490959ab732778bf65e896e52509635d00fd59107cc68f3f9e455
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.1-py3-none-any.whl

Download URL vimod-0.1.1-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4665fc313c6ada73078d69994a1e38936b0ef37bafe46089dfca0c8c764161a
BLAKE2b-256 checksum
How to use checksums
20dc8cbf7f75f058d454c1d63c4bd6309acaa172e46ab640a02012141e07f69a
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.1

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.1 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