Skip to main content

torchblocks-vp

torchblocks-vp is a typed PyTorch building-block library with a registry-driven API for assembling neural architectures out of interchangeable modules.

PyPI package name:

pip install torchblocks-vp

Import name:

import torchblocks

The package is meant for projects that want pluggable model components without copying the same attention, norm, feedforward, or adapter code into every application.

Design goals

torchblocks-vp is built around a few principles:

  • reusable blocks instead of one fixed architecture
  • explicit registration and lookup
  • publishable, typed interfaces
  • easy extension from downstream packages

It works especially well in codebases where model components should be configurable from TOML or Python configs.

Registry API

The central API is:

  • register(category, name)
  • get(category, name)
  • list_modules(category=None)

Example:

import torch
import torch.nn as nn

from torchblocks import get, register


@register("feedforward", "my_ff")
class MyFeedForward(nn.Module):
    def __init__(self, d_model: int, dim_ff: int, dropout: float = 0.1) -> None:
        super().__init__()
        self.net = nn.Sequential(
            nn.Linear(d_model, dim_ff),
            nn.GELU(),
            nn.Dropout(dropout),
            nn.Linear(dim_ff, d_model),
        )

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        return self.net(x)


ff_cls = get("feedforward", "my_ff")

This allows applications to select blocks dynamically without importing implementation modules directly everywhere.

Included module families

Attention

Registered attention modules:

  • gqa
  • mha
  • cross

These cover grouped-query attention, standard multi-head self-attention, and cross-attention.

Feedforward

Registered feedforward modules:

  • swiglu
  • gelu

Normalization

Registered norm modules:

  • rmsnorm
  • layernorm

Adapters

Registered adapter modules:

  • language_conditioned
  • bottleneck
  • none

Convolution

Registered convolution modules:

  • local
  • none

Position

Registered positional module:

  • rope

Installation

Requirements:

  • Python >=3.14
  • PyTorch >=2.0

Install from PyPI:

pip install torchblocks-vp

Common usage pattern

Most downstream code uses the registry as a factory layer:

from typing import cast

from torchblocks import get

norm_cls = get("norm", "rmsnorm")
ff_cls = get("feedforward", "swiglu")

norm = norm_cls(768)
ff = ff_cls(768, 3072, dropout=0.1)

Applications can keep architectural choices in config files while the runtime maps names to modules.

Included implementations

The current package exports the registry and auto-registers the bundled modules on import.

Implemented classes include:

  • GroupedQueryAttention
  • MultiHeadAttention
  • CrossAttention
  • SwiGLUFeedForward
  • GeLUFeedForward
  • RMSNorm
  • LayerNorm
  • LanguageConditionedAdapter
  • BottleneckAdapter
  • NoAdapter
  • LocalConvModule
  • NoConv
  • RotaryEmbedding

Helper functions:

  • rotate_half
  • apply_rotary_emb

Extending the package

You do not need to modify torchblocks-vp itself to add new blocks. A downstream package can register its own modules at startup:

from torchblocks import register


@register("attention", "my_attention")
class MyAttention(...):
    ...

As long as the constructor and forward signature match what the consuming model expects, the registry is enough.

Why the package is split out

Keeping these blocks in their own package helps with:

  • reuse across multiple models
  • cleaner application packages
  • separate publishing and versioning
  • stronger type boundaries between architecture code and task code

That matters in this repository because the libraries are published independently rather than bundled into one monolithic distribution.

Metadata

Release files for torchblocks-vp 3.0.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 torchblocks-vp 3.0.0
File Size Uploaded Provenance Actions
torchblocks_vp-3.0.0.tar.gz 9.3 kB Without provenance Details for torchblocks_vp-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for torchblocks-vp 3.0.0
File Interpreter ABI Platform Actions
torchblocks_vp-3.0.0-py3-none-any.whl Python 3 none any Details for torchblocks_vp-3.0.0-py3-none-any.whl

Total release size: 19.1 kB

Release files / torchblocks_vp-3.0.0.tar.gz

Download URL torchblocks_vp-3.0.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8cb70d7d766466c1524e28f04bc7424d53c30d36d3cf3fd90c3d556c5dfd875f
BLAKE2b-256 checksum
How to use checksums
017123e7a4017075447c112c15990311f55bff63a8bfc0ca9f6ed91691e32ae2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / torchblocks_vp-3.0.0-py3-none-any.whl

Download URL torchblocks_vp-3.0.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef9d59111700734bcc0e217def42ad393eae646c9aef2be26d2998d3a33744b2
BLAKE2b-256 checksum
How to use checksums
4cf4602b612ffb76effe6f51bd2bd43e90ba12f76435622b835e4a4a2adef826
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for torchblocks-vp 3.0.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.

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