Skip to main content

Multi-Modality

LM-INFINITE: SIMPLE ON-THE-FLY LENGTH GENERALIZATION FOR LARGE LANGUAGE MODELS

LM-Infinite is a solution proposed by Chi Han, Qifan Wang, Wenhan Xiong, Yu Chen, Heng Ji, and Sinong Wang to address the length generalization failure of Large Language Models (LLMs) on long sequences. LLMs, such as Transformer-based models, have shown impressive performance in various domains but struggle when it comes to longer reasoning processes or understanding larger contexts. Current pre-training schemes truncate training sequences to a fixed length, and even with relative positional encoding, LLMs struggle to generate coherent texts or perform downstream tasks after longer contexts.

The authors investigate the main out-of-distribution factors contributing to this problem and propose LM-Infinite as an efficient solution. LM-Infinite only requires a Λ-shaped attention mask and a distance limit, without any parameter updates or learning. It can be applied to different LLMs using relative-position encoding methods. LM-Infinite demonstrates consistent fluency and generation quality for sequences as long as 32k tokens on datasets like ArXiv and OpenWebText2, with a decoding speedup of 2.72x. Furthermore, it continues to perform well on inputs much longer than training lengths in downstream tasks like passkey retrieval, where vanilla models fail immediately.

Paper Link


Appreciation

  • Lucidrains
  • Agorians

Install

pip install lm-infinite

Usage

import torch
from infinite.main import LMInfinite

d_model = 512
seq_len = 100
n_global = 100
l_pretrain = 50


#sample
q = torch.randn(1, seq_len, d_model)
k = torch.randn(1, seq_len, d_model)
v = torch.randn(1, seq_len, d_model)


#llm infinite mode
model = LMInfinite(
    d_model,
    n_global,
    l_pretrain
)

#forwad pass
output = model(q, k, v)
print(output.shape)

Architecture

Todo

License

MIT

Citations

@misc{2308.16137,
Author = {Chi Han and Qifan Wang and Wenhan Xiong and Yu Chen and Heng Ji and Sinong Wang},
Title = {LM-Infinite: Simple On-the-Fly Length Generalization for Large Language Models},
Year = {2023},
Eprint = {arXiv:2308.16137},
}

Metadata

Release files for lm-infinite 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lm-infinite 0.0.2
File Size Uploaded
lm_infinite-0.0.2.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lm-infinite 0.0.2
File Interpreter ABI Platform
lm_infinite-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 kB

Release files / lm_infinite-0.0.2.tar.gz

Download URL lm_infinite-0.0.2.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c30096228b43e80b671867db31ac8bb40936240edc0da8dc28c8708f0e0c072d
BLAKE2b-256 checksum
How to use checksums
38686daec5fa8456a95bb12030f47d04970fbd53e8bf928ce459ab3f584b5f29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.0 Darwin/22.4.0

Release files / lm_infinite-0.0.2-py3-none-any.whl

Download URL lm_infinite-0.0.2-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a22b5fca8cc509bfd8a82a8dbfff6ff2bef744134b006df8ed176b260e2e89f
BLAKE2b-256 checksum
How to use checksums
8cd990fd1d20caa9952293342ecb6ae5b0cd05edd2c7ab6ab931072df8afd8c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.0 Darwin/22.4.0

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 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