Skip to main content

Morphottention

Mathematical Morphology-based self-attention module for PyTorch using Flash-style kernel fusion.

Install

Prebuilt wheels are published for CPython 3.14 on Linux (x86_64, aarch64) and Windows (x86_64). A working CUDA-enabled PyTorch (torch >= 2.12) must already be installed in the environment.

pip install morphottention

Usage

The package exposes an nn.Module (MorphoAttention), a functional entry point (morpho_attention), and the raw autograd bridge (MorphoAttentionFunction). All inputs must be CUDA tensors; the module defaults to float16.

As an nn.Module

import torch
from morphottention import MorphoAttention

attn = MorphoAttention(
    dim=256,       # model dimension D
    num_heads=8,   # number of attention heads H
    cube_m=16,     # hypercube width per head
    scale=1.0,     # softmax temperature
    causal=False,  # casual masking flag
    device="cuda",
)

x = torch.randn(2, 128, 256, dtype=torch.float16, device="cuda")  # (B, N, D)
out = attn(x)          # (B, N, D)
out.sum().backward()

Functional form

from morphottention import morpho_attention

out = morpho_attention(
    x, 
    W_phi, 
    gate_q, 
    gate_k, 
    W_V,
    num_heads=8, cube_m=16, scale=1.0, 
    causal=False,
)

Raw autograd bridge

import torch
from morphottention import MorphoAttentionFunction

B, N, D, H, cube_m = 2, 128, 256, 8, 16

x = torch.randn(B, N, D, dtype=torch.float16, device="cuda", requires_grad=True)
W_phi = torch.randn(D, H * cube_m, dtype=torch.float16, device="cuda", requires_grad=True)
gate_q = torch.ones(H, cube_m, dtype=torch.float16, device="cuda", requires_grad=True)
gate_k = torch.ones(H, cube_m, dtype=torch.float16, device="cuda", requires_grad=True)
W_V = torch.randn(D, D, dtype=torch.float16, device="cuda", requires_grad=True)

out = MorphoAttentionFunction.apply(
    x, W_phi, gate_q, gate_k, W_V,
    H, cube_m, 1.0, False,  # num_heads, cube_m, scale, causal
)  # (B, N, D)
out.sum().backward()

W_phi has shape (D, H * cube_m), W_V has shape (D, D), and gate_q / gate_k each have shape (H, cube_m).

Building from source

Requires the CUDA 13.X toolkit (nvcc) and a matching torch build:

uv sync --package morphottention --no-dev --group build
uv build --package morphottention --wheel --no-build-isolation

License

MIT

Copyright © 2026 Vedran Hrabar.

Metadata

Release files for morphottention 0.2.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 morphottention 0.2.1
File Size Uploaded
morphottention-0.2.1.tar.gz 19.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for morphottention 0.2.1
File
morphottention-0.2.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
morphottention-0.2.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
morphottention-0.2.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 Details
morphottention-0.2.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
morphottention-0.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
morphottention-0.2.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
morphottention-0.2.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
morphottention-0.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
morphottention-0.2.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details

Total release size: 270.8 MB

Release files / morphottention-0.2.1.tar.gz

Download URL morphottention-0.2.1.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
580343ed47707e22224a77599ee1652380afd65d67a367ff4d3467f2d65769f0
BLAKE2b-256 checksum
How to use checksums
7f9fa6a1bfdb85e8aaae3af0e72e61b9b10644732d7582cddaee6fe44a579fea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp314-cp314-win_amd64.whl

Download URL morphottention-0.2.1-cp314-cp314-win_amd64.whl
Size 193.7 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
3ba555dbc16bcbb23652f1eccd9159d2adfca8550eb65be5b7a99badd36c637b
BLAKE2b-256 checksum
How to use checksums
8c3320454c7eaf6b2a6cb68b769a7da810a6ecb3cb4334e9cccba1dc81c4200d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL morphottention-0.2.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 46.2 MB
Tags CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
cc185a28cfb731a9c17d1ffe7be6b6cfb7dba2bfba6ec9f3c13b7293493494ce
BLAKE2b-256 checksum
How to use checksums
344eda168aad6c39041682e3e6c0d5e4b2bb9b025eab17dfece6423762664332
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL morphottention-0.2.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 43.9 MB
Tags CPython 3.14 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
2776eeab791dbb5c31b04d4bc2ea8f8a4d9a7a09cc09f244f5128ec02661a456
BLAKE2b-256 checksum
How to use checksums
584ad0105b19ec2f6b878ce56a1930d3133e912afd424ff58a73ee7a11503d39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp313-cp313-win_amd64.whl

Download URL morphottention-0.2.1-cp313-cp313-win_amd64.whl
Size 191.7 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
a3c85c8ee5818767119e324e2bffda19df33810c8f3f754decc16359644f4656
BLAKE2b-256 checksum
How to use checksums
819832f7c0e0a922b211e7f2ee6053fc0e969edf1271fea0f184e5a9b2954f0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL morphottention-0.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 46.2 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
637bbd0beb7e1ddef48945e1b5d4d0b3b964a71d1996c11def2a72a6b79abb7b
BLAKE2b-256 checksum
How to use checksums
4467c956d90471b8c64c952ab1c0a245a522f4542ac3f174dae300671126cfca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL morphottention-0.2.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 43.9 MB
Tags CPython 3.13 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
a30ff72706d8805651c46a06762e531bcb98202062aac98c7548d5ff4d307f96
BLAKE2b-256 checksum
How to use checksums
ba340366c8f75b6e23363be0d2a61ec2f8eeb8093f9550c49614b6af18f95e79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp312-cp312-win_amd64.whl

Download URL morphottention-0.2.1-cp312-cp312-win_amd64.whl
Size 191.7 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
d76be371b5f72ac9866105bcbe282a8477841b4a3da4bd8cda6d3c37f090a53e
BLAKE2b-256 checksum
How to use checksums
d0e16c152ee0828975832cda57fb404cc643246de7187d70d34da636cbdcb43b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL morphottention-0.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 46.2 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1ec02b1f7e7b66e1990b8619ced8ce6da803862473ec8f8a571fa0599a9d7bb8
BLAKE2b-256 checksum
How to use checksums
ceeacbfe8cd7b42073801e6c66f1e0266e73be88389b45f944063a95fd46e3e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release files / morphottention-0.2.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL morphottention-0.2.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 43.9 MB
Tags CPython 3.12 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
ec591974a276f7200ad77cd7abd88269460860f66774d31d4d26b8125713d40f
BLAKE2b-256 checksum
How to use checksums
20813ce1721f2357106a3e550ee8b9165bd93039bc8f24bd2b8008bd09f82481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

10 release files

0.1.0

4 release files

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