Mathematical Morphology-based self-attention module for PyTorch (CUDA) using Flash-style kernel fusion.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file morphottention-0.2.0.tar.gz.
File metadata
- Download URL: morphottention-0.2.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48b2f37172ea11547621802aa0c426d38489c8dffe867e79e650d9f77e165e61
|
|
| MD5 |
90b4210e422480e9754e85684eeabc2f
|
|
| BLAKE2b-256 |
1ad1e821d1a73f72d1366d4e7f837db899d46d69571806e0a762501da28134ca
|
Provenance
The following attestation bundles were made for morphottention-0.2.0.tar.gz:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0.tar.gz -
Subject digest:
48b2f37172ea11547621802aa0c426d38489c8dffe867e79e650d9f77e165e61 - Sigstore transparency entry: 2035398254
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 247.2 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94c79a18238f858d8ed95f4271a3b5973c688586099305258980a095620aa5b1
|
|
| MD5 |
1c5bbdb746f1f3a9caf21dfce82ea9e1
|
|
| BLAKE2b-256 |
7ad1a1f0854618f5912450b4f535377bf58dff31385b36fb27d18dbb831507e7
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp314-cp314-win_amd64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp314-cp314-win_amd64.whl -
Subject digest:
94c79a18238f858d8ed95f4271a3b5973c688586099305258980a095620aa5b1 - Sigstore transparency entry: 2035400482
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 46.2 MB
- Tags: CPython 3.14, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
033449484d08ffa92c8d57013bb62966428a1b5a3df14f7fd16ce09fe4f932ed
|
|
| MD5 |
273d2f149e42e1144d6c9a8afccfcc86
|
|
| BLAKE2b-256 |
0e95eca2242c8725f302fa744a9d276fd44eb576af8ba865de56de537695e295
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
033449484d08ffa92c8d57013bb62966428a1b5a3df14f7fd16ce09fe4f932ed - Sigstore transparency entry: 2035398786
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 43.9 MB
- Tags: CPython 3.14, manylinux: glibc 2.24+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e615f37b39a0158385088dc269f9aefaebf9f839b9935f221da9f592897950fb
|
|
| MD5 |
1fb32284aac1ef6441e56d961b6b641a
|
|
| BLAKE2b-256 |
8dc6bf4bdd01745bb0c8839e1e6790c010ec16a66564fc17403452078c922e6f
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
e615f37b39a0158385088dc269f9aefaebf9f839b9935f221da9f592897950fb - Sigstore transparency entry: 2035400024
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 244.8 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba7b32256a2f53290f7305aed588c436867897d2a5c376fe773d47e9723e3ddc
|
|
| MD5 |
b365cbd1409850a636c05775d15fe8ba
|
|
| BLAKE2b-256 |
ccda2499fc0240311e8d83da5fc206e723f362368eed48d4932945dd48ae227d
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp313-cp313-win_amd64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp313-cp313-win_amd64.whl -
Subject digest:
ba7b32256a2f53290f7305aed588c436867897d2a5c376fe773d47e9723e3ddc - Sigstore transparency entry: 2035399507
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 46.2 MB
- Tags: CPython 3.13, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca801a1f8a330377773c2112042974ae8507c79c2267a4aa2c4e4f596fa2a027
|
|
| MD5 |
1fe8e03113e388daba14aa66c5778dc9
|
|
| BLAKE2b-256 |
043d43a0f92067a5d97e3eb641c7e1f98261db62ef4e75ed3a0d7e318241f594
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
ca801a1f8a330377773c2112042974ae8507c79c2267a4aa2c4e4f596fa2a027 - Sigstore transparency entry: 2035398521
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 43.9 MB
- Tags: CPython 3.13, manylinux: glibc 2.24+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da82ef989fa40bfce38d932e1310942f7a28073af1f1ac636d9c323a965e61d9
|
|
| MD5 |
45feb6a1baf79b3b8584823dfc3b8e99
|
|
| BLAKE2b-256 |
7380986ad628b48bfd597c3ef9bbe0e6bc3f56faa1ea31105c69254a396313b4
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
da82ef989fa40bfce38d932e1310942f7a28073af1f1ac636d9c323a965e61d9 - Sigstore transparency entry: 2035398974
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 244.8 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94dfb919580e762c0e3f79b99baa328de520d5686d1488a0976de83a62a306ea
|
|
| MD5 |
119b8f11aa209265e5bc2c18cdf24d9f
|
|
| BLAKE2b-256 |
70d08573b41500ef7799237e1332bcaf9d4e1c7b57cf3a5db6e096b69fb11692
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp312-cp312-win_amd64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp312-cp312-win_amd64.whl -
Subject digest:
94dfb919580e762c0e3f79b99baa328de520d5686d1488a0976de83a62a306ea - Sigstore transparency entry: 2035399239
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 46.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ea7b65d713cb3f6b0753e1099c281bfdca9b534070dd27b610c3711be2a5847
|
|
| MD5 |
10ec922066e18f9bf4b1275422cf48ff
|
|
| BLAKE2b-256 |
da130a1b0da12969b4d6a3707ab6cb9c33c1c0c1be5fe2fe659a54a837b69e47
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
9ea7b65d713cb3f6b0753e1099c281bfdca9b534070dd27b610c3711be2a5847 - Sigstore transparency entry: 2035400216
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file morphottention-0.2.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: morphottention-0.2.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 43.9 MB
- Tags: CPython 3.12, manylinux: glibc 2.24+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
389d27bf314ca598e74faa548644b60d0ea032081f2b12df5827f27afe9e6cc6
|
|
| MD5 |
300f15d67199faf91df8c2f22f5e6f17
|
|
| BLAKE2b-256 |
982eb2f57760aadf1aa244c9ece2919584829d976c29e87eda9f939656c0054f
|
Provenance
The following attestation bundles were made for morphottention-0.2.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
publish-pypi.yml on vhrabar/Morphottention
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
morphottention-0.2.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
389d27bf314ca598e74faa548644b60d0ea032081f2b12df5827f27afe9e6cc6 - Sigstore transparency entry: 2035399746
- Sigstore integration time:
-
Permalink:
vhrabar/Morphottention@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@90630b41d0e96a2f9e86f40c6ba40069df04c346 -
Trigger Event:
workflow_run
-
Statement type: