Block Transformer: Global-to-Local Language Modeling for Fast Inference

We introduce the Block Transformer which adopts hierarchical global-to-local modeling to autoregressive transformers to mitigate the inference bottlenecks associated with self-attention. Self-attention requires the key-value (KV) cache of all previous sequences to be retrieved from memory at every decoding step to retrieve context information, leading to two primary bottlenecks during batch inference. First, there is a significant delay in obtaining the first token, as the information of the entire prompt must first be processed to prefill the KV cache. Second, computation of subsequent tokens is bottlenecked by the high memory I/O demand of fetching the entire KV cache, which grows linearly with sequence length, incurring quadratic memory reads overall. We design the Block Transformer to strategically mitigate these costs, by incorporating coarsity and locality into an integrated global-to-local architecture. At the lower layers, we aggregate tokens into fixed size blocks to apply attention across the entire sequence at coarse-grained detail, to capture the global context while minimizing KV cache overhead. At upper layers, we apply attention within each block to decode individual tokens, to model fine-grained details with a lightweight local KV cache. We pretrain vanilla and Block Transformers from scratch and demonstrate that Block Transformers reach 10--20x inference throughput compared to vanilla transformers with equivalent perplexity and zero-shot task performance. Code is available at https://github.com/itsnamgyu/block-transformer.

Paper

References (89)

Scroll for more · 38 remaining

Similar papers

Peer review

Reviewer BaSr6/10 · confidence 5/52024-06-30

Summary

This paper proposes a Block Transformer architecture which adopts hierarchical global-to-local modeling to mitigate the computational cost and KV cache memory of Self Attention. Block Transformer isolate the global modeling with three blocks: Embedder, Block Decoder, and Token Decoder. Embedder encodes block information for auto-regressive modeling in Block Decoder. The aggregated information is plugged into Token Decoder for final token-level decoding. Block Transformer shows 10-20x inference improvement under the similar perplexity than traditional global Transformer. This paper gives a detailed ablation about the architecture design of Block Transformer. Besides, the global modeling capability and uptraining strategy is also discussed.

Strengths

1. The paper is well organized and the experiments are solid and comprehensive. 2. Block Transformer trades inference efficiency with model parameters, which is a bold innovation. 3. Block Transformer achieves low-cost inference compared with standard Transformer. 4. The architecture analysis and ablation studies show the effectiveness of Block Transformer design.

Weaknesses

1. Block Transformer uses much bigger model size to compensate for the performance loss. There are countless problem for that, including training partitioning and inference infrastructure. 2. The actual inference efficiency comparison is doubtful. For example, in Table 2, The Decode throughput of Block Transformer is much bigger than standard Transformer under same model size. Since Block Transformer only saves Attention computation and the FFN computation stays the same, I'm confused that why attention computation occupies almost most of the overall computation. 3. The long-sequence modeling capability is not evaluated. Since Block Transformer squeezes the context representation, it is questionable that if Block Transformer can retrieve the global context information. I think some common long-sequence experiments will help, e.g., Needle-in-a-Haystack. 4. The scaling property is not discussed good enough. For example, in Figure 2, there are some results in different model sizes. However, there is not a "scaling law" for Block Transformer. Besides, the scaling does not look promising with my human eye in Figure 2.

Questions

1. Concerns in the Weaknesses part. 2. I'm curious about the inference experiment setting. Are FlashAttention and FlashDecoding techniques used for vanilla Transformer or Block Transformer? I believe it is already a necessary part in 2024 year.

Rating

6

Confidence

5

Soundness

3

Presentation

3

Contribution

3

Limitations

The limitation is discussed.

Reviewer BaSr2024-08-09

Response to Authors' Rebuttal

I appreciate authors' thorough and patient response. I have a better understanding of the experiment setting. However, I still have some of my previous concerns: 1. Measuring the perplexity on PG19 to evaluate the long-sequence modeling capability is still not a good experiment. Since some subsequent works show that H2O and Attention Sink are not good at some long context tasks, including Needle-in-a-Haystack, LongBench, and ZeroScrolls, I don't agree it's a **standard benchmark**. I believe it is a novel and insightful work. But there is still space for improvement. In a nutshell, the paper will look much stronger if the experiment is on a "**modern**" setting, including the latest evaluation settings and kernel techniques. I will keep my initial score.

Authorsrebuttal2024-08-13

Experimental results on the Needle-in-a-Haystack task

We appreciate again the acknowledgement for the novelty and insightful contributions of our work. To the best of our knowledge, recent long-context benchmarks like Needle-in-a-Haystack (NIAH), LongBench, and ZeroScrolls typically evaluate instruction-tuned models, as opposed to our pre-trained base models. Nevertheless, we are pleased to share **additional results on the Needle-in-a-Haystack task**. We found that **Block Transformers perform equally or stronger than loss-equivalent vanilla models**, consistently across **(1) needle locations**, **(2) model scales** and **(3) prompt variants**. . ## Experimental settings. Following prior work [1], we construct the context by first sampling 2K-length snippets from concatenated essays written by Paul Graham as the “haystack”, and then inserting a “needle” containing key information in a random location. Following [1], we use this needle format: `The special magic {city} number is: {number}`. - `{city}` is a randomly chosen city name - `{number}` is a random 7-digit number. We then append a prompt that queries to model to retrieve the 7-digit number. We consider two prompt formats: **1. Gemini prompt** Format: `<context>\n{context}\n</context>\n\nWhat is the special magic {city} number?\n\nHere is the magic number from the context:` We mostly followed the NIAH prompt used in Gemini [1], but we excluded the “Don’t give information outside the document or repeat your findings” part, as our models are not instruction-tuned. **2. Verbatim prompt** Format: `<context>\n{context}\n</context>\n\n{question}\n\nThe special magic {city} number is:`. Here, we used the exact same format as that in the needle to query the model. We measured the accuracy by generating 20 new tokens, and considering a prediction correct if the generated text contains the 7-digit number. . ## Experimental results. Note that depth refers to the relative of the location of the needle within the haystack, in percentages. **Gemini prompt** | Depth | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 | Mean | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Vanilla 19M | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.20% | 0.80% | 6.40% | 0.67% | | Vanilla 85M | 21.00% | 16.40% | 21.80% | 27.40% | 36.60% | 28.00% | 26.80% | 40.20% | 41.80% | 37.60% | 22.80% | 29.13% | | Vanilla 300M | 46.20% | 69.00% | 72.80% | 78.60% | 76.40% | 70.40% | 71.80% | 74.80% | 73.80% | 78.40% | 66.20% | 70.76% | | Block 85M | 5.60% | 2.40% | 0.80% | 0.80% | 0.20% | 1.00% | 0.80% | 1.00% | 2.60% | 1.80% | 6.40% | 2.13% | | Block 300M | 23.40% | 52.60% | 52.60% | 46.60% | 46.00% | 49.20% | 58.40% | 70.40% | 64.00% | 53.60% | 18.40% | 48.65% | | Block 800M | 35.80% | 74.00% | 76.40% | 78.40% | 69.80% | 77.40% | 76.40% | 79.00% | 75.20% | 72.80% | 53.60% | 69.89% | | Block 1.2B | 57.20% | 86.60% | 88.80% | 85.60% | 80.40% | 85.20% | 90.40% | 89.20% | 91.00% | 90.40% | 78.80% | 83.96% | **Verbatim prompt** | Depth | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100 | Mean | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | Vanilla 19M | 8.20% | 1.40% | 3.00% | 6.80% | 7.80% | 12.60% | 45.40% | 65.80% | 63.40% | 84.60% | 99.40% | 36.22% | | Vanilla 85M | 95.60% | 99.40% | 99.00% | 99.40% | 99.20% | 99.20% | 99.00% | 99.60% | 99.60% | 99.00% | 95.60% | 98.60% | | Vanilla 300M | 99.60% | 100.00% | 100.00% | 99.80% | 100.00% | 100.00% | 99.80% | 100.00% | 100.00% | 100.00% | 99.80% | 99.91% | | Block 85M | 96.20% | 97.60% | 96.20% | 96.60% | 98.40% | 98.00% | 97.20% | 98.80% | 99.00% | 99.40% | 96.20% | 97.60% | | Block 300M | 90.20% | 99.40% | 99.60% | 99.20% | 98.60% | 99.60% | 99.60% | 99.80% | 99.80% | 99.20% | 99.20% | 98.56% | | Block 800M | 95.20% | 99.40% | 98.80% | 98.80% | 98.80% | 98.80% | 99.00% | 99.40% | 99.20% | 97.40% | 99.60% | 98.58% | | Block 1.2B | 92.60% | 98.40% | 99.40% | 98.80% | 99.60% | 99.60% | 98.80% | 99.80% | 99.80% | 99.20% | 98.00% | 98.55% | . These results confirm that the Block Transformer, like the vanilla models, can effectively retrieve global information contained within the 2K context length. With the Gemini prompt, we observed an accuracy trend that was very similar to the perplexity trend of the vanilla vs block models. Near-perfect performance with the Verbatim prompt supports the long-sequence modeling capabilities of our models even when context information is squeeze into a single embedding. We believe this parity between Vanilla and Block Transformers on 2K context length will extend to 8K and beyond. . We would appreciate it if you could reflect our additional results on FlashDecoding (modern implementation) and NIAH evaluation (modern evaluation) in your final score, as we believe these have adequately addressed your concerns. . [1] Gemini Team, Google. “Gemini 1.5: Unlocking multimodal understanding across millions of tokens of context.”

Reviewer BaSr2024-08-14

I'm pleased to see that Block Transformer can effectively retrieve global information contained within the 2K context length, that is a strong indicator for long-context capability. I will increase my score to 6.

Reviewer 769s6/10 · confidence 4/52024-07-10

Summary

The authors introduced the Block Transformer architecture to address the self-attention bottleneck. This is achieved by grouping input tokens into fixed-size blocks and applying self-attention at a corser level throughout the model. At the output layer, a token decoder predicts individual tokens from the block. The authors found that this hierarchical global-to-local modeling approach results in 10 to 20 times faster inference compared to vanilla transformers with similar perplexity.

Strengths

- The topic of improving the efficiency of LLMs and making them more affordable is crucial and timely. Furthermore, as sequences scale, the self-attention bottleneck increases. - The authors conducted extensive experiments and ablations with a modern setup. The evaluation includes perplexities and zero-shot downstream tasks. The models were trained for a significant number of tokens (300B, which is more than an epoch on the Pile), making the result more trustworthy. - The paper is well-written and easy to follow.

Weaknesses

- The concept appears similar to that of the Funnel Transformer [1], with the main exception that the aggregation happens only once at the token level. - The Pareto front of the decoding throughput is only improved with batch sizes greater than 32, which may not often be the case. - The higher inference throughput comes at the cost of more training compute and memory. The proposed methods perform worse than the vanilla model at an equivalent size. [1] Dai, Zihang, et al. "Funnel-transformer: Filtering out sequential redundancy for efficient language processing." Advances in neural information processing systems 33 (2020): 4271-4282.

Questions

- Is the baseline using FlashAttention2 [2] and MQA/GQA [3] ? These two modifications have become standard and significantly reduce the bottleneck of the attention. - Could you explain the differences between your methods and the Funnel Transformer? - Given the Funnel Transformer and the many other sparse attention, do you maintain your claim that you "are the first to recognize the central role and inference-time benefits of both global and local modeling in autoregressive transformers, particularly the significance of local modules"? [2] Dao, Tri. "Flashattention-2: Faster attention with better parallelism and work partitioning." arXiv preprint arXiv:2307.08691 (2023). [3] Ainslie, Joshua, et al. "Gqa: Training generalized multi-query transformer models from multi-head checkpoints." arXiv preprint arXiv:2305.13245 (2023).

Rating

6

Confidence

4

Soundness

3

Presentation

3

Contribution

2

Limitations

Yes.

Reviewer unsu5/10 · confidence 2/52024-07-11

Summary

The paper introduces the Block Transformer architecture, which aims to improve inference speed in autoregressive language models by adopting a hierarchical global-to-local approach. The architecture separates the global context modeling into lower layers and local detailed interactions into upper layers, thus reducing the self-attention bottleneck. The authors demonstrate significant improvements in inference throughput without compromising perplexity.

Strengths

1. The experiments in this paper are extensive, covering a variety of model parameters. 2. The proposed Block Transformer demonstrates improvements in computational efficiency, which is crucial for scaling up to longer sequences.

Weaknesses

**Major Weakness** As I understand it (please correct me if I'm wrong), the primary difference between Block Transformer and MEGABYTE [1] is whether the input is a token or a byte. The architecture of Block Transformer is nearly identical to that of MEGABYTE, which significantly limits the novelty and contribution of this work. [1] MEGABYTE: Modeling Million-byte Sequences with Multiscale Transformers

Questions

None

Rating

5

Confidence

2

Soundness

3

Presentation

3

Contribution

1

Limitations

As discussed above.

Reviewer Ht4c6/10 · confidence 3/52024-07-13

Summary

This paper introduces Block Transformer, which is a new architecture that adopts hierarchical global-to-local modeling to autoregressive transformers to mitigate the inference bottlenecks brought by applying self-attention on the global context. In detail, Block Transformer mainly includes three different components: (1) Embedder, which aggregates each block into an input block embedding; (2) Block decoder, which applies self-attention on the full sequence of blocks (rather than tokens) to model global context; (3) Token decoder, which applies self-attention on the sequence of tokens within each block to model local context and decode individual tokens. Evaluation shows that the Block Transformer architecture demonstrates significant gains in inference throughput compared to vanilla transformers with similar perplexity.

Strengths

- The paper explores an important and interesting research direction. - The improvement on inference throughput achieved by Block Transformer is significant. - The paper is generally well-written.

Weaknesses

- Block Transformer needs two or three times more parameters than vanilla transformers to achieve similar perplexity. - It is unclear that, after scaling up vanilla transformers to 7B or 13B level, whether Block Transformer can still achieve similar perplexity with two or three times more parameters. - More evaluation is required to demonstrate that Block Transformer can effectively leverage full context. While the paper evaluates the perplexity of token positions within a 2K context window to show that Block Transformer can effectively leverage at least 2K tokens of context, experiments on longer contexts that are no shorter than 8K or 16K is also important to show that Block Transformer can indeed effectively leverage global information.

Questions

None beyond the above.

Rating

6

Confidence

3

Soundness

3

Presentation

3

Contribution

3

Limitations

The limitation section of this paper is rather comprehensive.

Reviewer unsu2024-08-08

Given that the experiments are indeed extensive, I will increase my score from 3 to 5.

Authorsrebuttal2024-08-09

Thank you for acknowledging our extensive experiments which support the autoregressive inference benefits of our architecture, particularly that of local modeling, which was not fully studied or exploited in previous work. Please let us know if you have any further questions or concerns regarding the novelty of our work. We are committed to ensuring our contributions are clearly communicated.

Reviewer 769s2024-08-09

Thank you for the detailed rebuttal. Overall, I am pleased with the answers and clarifications provided, and I have adjusted my score accordingly. **W1.** I appreciate the clarification on the key difference between the proposed architecture and Pooling Transformers that is the locality in the decoding layers. I agree that local attention will significantly reduce computational requirements, particularly for long sequences. **W2.** I am satisfied with the provided numbers and suggest adding the table to the appendix. Figs. 7a and 8a do not show a clear Pareto front improvement at a batch size of 1, in contrast to Figs. 7b and 8b at a batch size of 32. I recommend extending these figures to include larger models to highlight the improvement. Additionally, I suggest revising the statement Lines 746-749: "At a batch size of 1, parameter IO has a much greater impact on throughput compared to KV cache IO, resulting in slightly lower throughput for block model. However, as the model sizes increase beyond a certain point, the increased KV cache memory causes this trend to reverse." Specifying that this trend reverses between 300M and 1.2B parameters may be helpful. **W3.** I am satisfied with the response. **Q1.** Thank you for the additional experiments on FlashAttention and GQA. **Q3.** Based on your response to **Q1**, I now have a better understanding of your claim. I appreciate your commitment to clarifying the sentence.

Authorsrebuttal2024-08-09

Thank you for acknowledging our comments, and providing additional detailed feedback on our manuscript. We are glad that we could clarify the novelty and contribution of our work, and further show the generality of our results to practical settings and state-of-the-art implementations. We will include the additional analysis and clarifications in our final paper, with further results on more batch sizes and model sizes.

Reviewer Ht4c2024-08-13

Thanks for the detailed response with clarifications and additional experiments. I believe my concerns of W1 and W3 are mostly addressed, however I still think it is critical to scale models up to at least 7B level for more solid evaluation. So I will be keeping my score the same.

Authorsrebuttal2024-08-13

Thank you for acknowledging our comments. We are glad that your concerns regarding parameter requirements and long context capabilities have been addressed. We acknowledge the value of 7B parameter experiments, but they were infeasible within our scope. Based on the consistent and significant improvement in throughput from 33M to 1.4B parameters, we believe our work is a solid proof-of-concept for hierarchical global-to-local modeling, demonstrating its significant real-world benefits in subword-level autoregressive inference. This can serve as the foundation for future work, including scaling studies and advanced uptraining schemes (Appendix A), and enable novel research directions which exploit the hierarchical structure, e.g., adaptive computation by dynamically allocating block lengths based on token difficulty.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC