Practical overview
When it fits
Use it when you want a modifiable PyTorch implementation for experimenting with hierarchical sequence processing, rather than a hosted model or a ready-made end-user application.
Who it is for
- Researchers exploring hierarchical or sequence-length-reduced transformer architectures.
- Developers prototyping autoregressive or non-autoregressive language-model configurations in PyTorch.
- Developers experimenting with transformer processing of tokenized image inputs.
Documented uses
- Configure a language model with sequence shortening and a chosen transformer depth.
- Explore nested hourglass structures or a Funnel Transformer-like configuration.
- Try non-autoregressive prediction using a non-causal setting and input mask.
- Process tokenized image features with linear up/downsampling.
Requirements & limits
The implementation is available in a public GitHub repository under the MIT license; the README documents installation through pip.
- The hierarchy is configured through shortening factors and a depth tuple, which can also be nested.
- The language-model class returns position-wise logits in the README examples.
- The image example uses
HourglassTransformerwithupdown_sample_type='linear', rather than the language-model class. - The README identifies shift padding for naive downsampling as a TODO.
- Non-autoregressive support is demonstrated, but the README says results were not presented in the paper.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install the package and configure a language model
Set up the documented package and define an HourglassTransformerLM with a chosen sequence length and hierarchy.
Before you start
- Python and PyTorch, as used in the README example.
- A development environment in which the package can be installed with pip.
Steps
Install the package with the command below.
pip install hourglass-transformer-pytorchImport
HourglassTransformerLMfromhourglass_transformer_pytorchand importtorch.Set model parameters such as
num_tokens,dim,max_seq_len,shorten_factoranddepth; the README example uses 256 tokens, dimension 512, maximum sequence length 1024, shortening factor 2 and depth(4, 2, 4).Supply a token tensor to the model; the README illustrates a
(1, 1024)integer tensor and describes logits shaped(1, 1024, 256).
Expected outcome
A configured language-model instance and the documented pattern for obtaining per-position token logits.
Guide limitations
- The README example uses randomly generated token IDs; it does not document data preparation or training this model configuration.
- The repository notes a TODO for shift padding when using naive downsampling.
Configure a non-autoregressive language-model example
Adapt the README's model configuration for non-autoregressive sequence prediction.
Before you start
- Python and PyTorch.
- Token IDs and a mask shaped for the input sequence, following the README example.
Steps
Create an
HourglassTransformerLMwith the chosen vocabulary size, dimensions, maximum sequence length, shortening factor and depth.Set
causal=False, as shown in the README.Create the input token tensor and a boolean mask, then pass both to the model as
model(x, mask=mask).
Expected outcome
The documented example returns logits for each input position, with output shape `(1, 1024, 20000)` for its stated parameters.
Guide limitations
- The README says results for non-autoregressive use were not presented in the paper.
- This is a configuration example; it does not specify a training or evaluation procedure.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 18 October 2026
- Original website title
- lucidrains/hourglass-transformer-pytorch · Official homepage title · retained in its source language

