Skip to main content

Multihead Temporal Latent Attention implementation

Project description

MTLA: Multi-head Temporal Latent Attention

MTLA

Multi-head Temporal Latent Attention
Keqi Deng, Philip C. Woodland
Paper: https://arxiv.org/abs/2505.13544

About

MTLA is a novel attention mechanism building on DeepSeek MLA, with a key innovation: temporal compression of the key-value cache. This enables more efficient self-attention and significantly reduces memory footprint during inference, making it particularly valuable for decoder-only architectures such as LLMs. Built on PyTorch, this project also serves as an open-source, decoder-only toolkit for end-to-end speech and language processing, covering tasks such as text summarisation, speech translation, speech recognition, spoken language understanding, and so on, with fully featured setup recipes.

Key Features

Supported Attention Mechanisms

  • Attention: Multi-head Attention (MHA), Multi-Query Attention (MQA), Grouped-Query Attention (GQA), Multi-head Latent Attention (MLA), and Multi-head Temporal Latent Attention (MTLA)
  • Positional Encoding: Rotary Position Embedding (RoPE), and Decoupled Rotary Position Embedding

Complete Setup Recipes

  • Tasks: speech translation (MuST-C), speech recognition (AMI), spoken language understanding (SLURP), and text summarisation (XSum)
  • Data Processing: Fairseq-style Fbank feature extraction and compression into zip file, and ESPnet2-style speech data processing with raw audio saved in flac or ark format
  • Feature Extraction: Fbank online/offline extraction, and self-supervised learning representations as features, using upstream models in S3PRL

Evaluation

  • Parallel Inference: Fairseq-style parallel beam search over batches containing multiple data samples
  • Quality Evaluation: BLEU, WER, classification accuracy, and ROUGE (ROUGE-1, ROUGE-2, and ROUGE-L)
  • Efficiency Evaluation: inference time spent, and GPU memory (including activation memory and the storage of key-value cache) consumed on inference

Installation and Usage

  • If you only need the Python MTLA module, simply clone this repository and refer to the following example:
    import torch
    from MTLA import MultiheadTemporalLatentAttention
    
    batch, length, dim = 2, 64, 512
    x = torch.randn(batch, length, dim)
    pos = torch.arange(0, length).float().view(1, -1) # Position information
    model = MultiheadTemporalLatentAttention(
        embed_dim=dim, # Model dimension
        num_heads=8,  # Attention heads of queries
    )
    y = model(query=x, key=x, value=x, position=pos)
    assert y.shape == x.shape
    
  • If you intend to run the full experiments, please install the project as described below before proceeding to the examples in the experiments directory.
    • PyTorch version >= 1.10.0
    • Python version >= 3.8
    cd experiments/tools/fairseq
    pip install --editable ./
    

Citation

If you use this codebase, or otherwise find our work valuable, please cite MTLA:

@article{mtla,
  title={Multi-head Temporal Latent Attention},
  author={Deng, Keqi and Woodland, Philip C},
  journal={arXiv preprint arXiv:2505.13544},
  year={2025}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mtla-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mtla-0.1.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file mtla-0.1.0.tar.gz.

File metadata

  • Download URL: mtla-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for mtla-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ab2bb6e8d4cc8cac06ff9f1fc0cca488280821baa53554be9128f814b9ee76a0
MD5 b4afe5bd24ffc14bb7f06f365260bfba
BLAKE2b-256 78bae40cae5dc4c1e03e1d157a53d3aca83de7c4ebe58f42f8522861f03a1da1

See more details on using hashes here.

File details

Details for the file mtla-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mtla-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for mtla-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb62934fbd507b7eb93e01a896b3e3e49214fe2fbee6950ad5852b72fc844e66
MD5 50651bfd0beb6f03b23d9b8dbbb9d76b
BLAKE2b-256 851472c4f2a4685f2a2d5b4b611664f994c0c26b53a826c92e3b6ed90da9b7db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page