Practical overview
When it fits
Use it when you want Python/PyTorch model components and documented examples for experimenting with gMLP on token sequences or image classification, rather than a hosted inference service or a complete training pipeline.
Who it is for
- PyTorch developers prototyping masked-language-modeling architectures.
- Computer-vision developers building gMLP image-classification models.
- Researchers comparing gMLP configurations, including optional attention or experimental multi-head settings.
Documented uses
- Configure a token-sequence gMLP and obtain per-position vocabulary logits.
- Configure a vision gMLP and obtain image-classification logits.
- Explore optional attention dimensions or prototype the README's experimental multi-head sequence setup.
Requirements & limits
The repository is public and identifies the project as MIT-licensed. The README gives `pip install g-mlp-pytorch` as the installation command.
- The examples provide model construction and forward-pass outputs, but do not document a complete training or evaluation workflow.
- The vision examples support non-square image and patch dimensions as well as square dimensions.
- The README describes the multi-head approach as experimental, unlike its standard masked-language-modeling and vision examples.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Build a masked-language-modeling gMLP
Create a token-sequence gMLP and obtain vocabulary logits for an input sequence.
Before you start
- Python and PyTorch
- Install the package with
pip install g-mlp-pytorch
Steps
Import
torch,torch.nn, andgMLPfromg_mlp_pytorch.Construct
gMLPwith vocabulary size, dimension, depth and sequence length; the example also setscirculant_matrix=Trueand usesnn.Tanh()for the spatial-gate activation.Create a token tensor with the configured sequence length, as in the README example.
Pass the tensor to the model to produce logits shaped as batch, sequence length and vocabulary size.
Expected outcome
A configured gMLP returns per-token vocabulary logits for a masked-language-modeling experiment.
Guide limitations
- The example demonstrates model construction and a forward pass, not a training or evaluation procedure.
- The shown token tensor is randomly generated rather than drawn from a dataset.
Build an image-classification gMLP
Configure the vision model and obtain class logits for an image-shaped tensor.
Before you start
- Python and PyTorch
- Install the package with
pip install g-mlp-pytorch
Steps
Import
torchandgMLPVisionfromg_mlp_pytorch.Set image size, patch size, number of classes, model dimension and depth when constructing
gMLPVision.Create an image tensor matching the configured dimensions, as in the documented example.
Pass the tensor to the model to produce class logits.
Expected outcome
A gMLPVision model returns one class-logit vector per input image.
Guide limitations
- The README shows a forward-pass example, not a training or evaluation workflow.
- The example uses a randomly generated tensor rather than a labeled image dataset.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 16 October 2026
- Original website title
- lucidrains/g-mlp-pytorch · Official homepage title · retained in its source language

