Skip to main content

🥞 x-Metaformer

A PyTorch implementation of "MetaFormer Baselines" with optional extensions.
We support various self-supervised pretraining approaches such as BarlowTwins, MoCoV3 or VICReg (see x_metaformer.pretraining).

Setup

Simply run: pip install x-metaformer

Example

import torch
from x_metaformer import CAFormer, ConvFormer


my_metaformer = CAFormer(
    in_channels=3,
    depths=(3, 3, 9, 3),
    dims=(64, 128, 320, 512),
    multi_query_attention=False,  # share keys and values across query heads
    use_seqpool=True,  # use sequence pooling vom CCT
    init_kernel_size=3,
    init_stride=2,
    drop_path_rate=0.4,
    norm='ln',  # ln, bn, rms (layernorm, batchnorm, rmsnorm)
    use_grn_mlp=True,  # use global response norm in mlps
    use_dual_patchnorm=False,  # norm on both sides for the patch embedding
    use_pos_emb=True,  # use 2d sinusodial positional embeddings
    head_dim=32,
    num_heads=4,
    attn_dropout=0.1,
    proj_dropout=0.1,
    patchmasking_prob=0.05,  # replace 5% of the initial tokens with a </mask> token
    scale_value=1.0, # scale attention logits by this value
    trainable_scale=False, # if scale can be trained
    num_mem_vecs=0, # additional memory vectors (in the attention layers)
    sparse_topk=0,  # sparsify - keep only top k values (in the attention layers)
    l2=False,   # l2 norm on tokens (in the attention layers) 
    improve_locality=False,  # remove attention on own token
    use_starreglu=False  # use gated StarReLU
)

x   = torch.randn(64, 3, 64, 64)  # B C H W
out = my_metaformer(x, return_embeddings=False)  # returns average pooled tokens

Metadata

Release files for x-Metaformer 0.3.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 x-Metaformer 0.3.1
File Size Uploaded Provenance Actions
x-Metaformer-0.3.1.tar.gz 11.6 kB Without provenance Details for x-Metaformer-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for x-Metaformer 0.3.1
File Interpreter ABI Platform Actions
x_Metaformer-0.3.1-py3-none-any.whl Python 3 none any Details for x_Metaformer-0.3.1-py3-none-any.whl

Total release size: 28.0 kB

Release files / x-Metaformer-0.3.1.tar.gz

Download URL x-Metaformer-0.3.1.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bed386ba8dd0ce155866c0504a0ed63406fa5bf05a586ca8370ffe3d6cc2075f
BLAKE2b-256 checksum
How to use checksums
9e94ee62ac48ceb19d7bbf501d200f56f7f893d6a36e5fd9617343bf99a77190
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / x_Metaformer-0.3.1-py3-none-any.whl

Download URL x_Metaformer-0.3.1-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44d719f025113328ed382dfcd005d490e1c87f20cc3e6a8960055f1ef9c9284d
BLAKE2b-256 checksum
How to use checksums
8d559f411fddde3c702192e8c843354ac73f1ed22d6b6a36585c4d2e13829083
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for x-Metaformer 0.3.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.

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