## SentenceVAE: Enable Next-sentence Prediction for Large Language Models with Faster Speed, Higher Accuracy and Longer Context

Hongjun An 1,2 * , Yifan Chen 1,2 * , Zhe Sun 1,2† &amp;Xuelong Li 1,2‡

1 School of Artificial Intelligence, OPtics and ElectroNics (iOPEN), Northwestern Polytechnical University 2 Institute of Artificial Intelligence (TeleAI), China Telecom

## Abstract

Current large language models (LLMs) primarily utilize nexttoken prediction method for inference, which significantly impedes their processing speed. In this paper, we introduce a novel inference methodology termed next-sentence prediction, aiming at enhancing the inference efficiency of LLMs. We present Sentence Variational Autoencoder (SentenceVAE), which includes a Sentence Encoder to compress multiple tokens in a sentence into a single token, and a Sentence Decoder to reconstruct it. By integrating SentenceVAE into the input and output layers of LLMs, we develop Sentencelevel LLMs (SLLMs) that employ a sentence-by-sentence inference method. In addition, the SentenceVAE module of SLLMs can maintain the integrity of the original semantic content by segmenting the context into sentences, thereby improving accuracy while boosting inference speed. Moreover, compared to previous LLMs, SLLMs process fewer tokens over equivalent context length, significantly reducing memory demands for self-attention computation and facilitating the handling of longer context. Extensive experiments on Wanjuan dataset have revealed that the proposed method can accelerate inference speed by 204 ∼ 365%, reduce perplexity (PPL) to 46 ∼ 75% of its original metric, and decrease memory overhead by 86 ∼ 91% for the equivalent context length, compared to previous token-by-token methods.

## Introduction

Large language models (LLMs) have demonstrated remarkable proficiency in understanding human intent through the acquisition of knowledge from vast and diverse datasets. These models provide rich and accurate responses, making them essential for applications such as machine translation (Zhang, Haddow, and Birch 2023; Wang et al. 2023), chatbots (Islam and Moushi 2024; Wang et al. 2024), and question-answering systems (Singhal et al. 2023; Lazaridou et al. 2022). The predominant method to inference in LLMs involves next-token prediction, where the model generates tokens sequentially. While this token-by-token generation method has achieved significant performance, it is inherently limited in producing only one token per inference step. This constraint introduces considerable computational overhead,

* These authors contributed equally.

† Corresponding author: sunzhe@nwpu.edu.cn

‡ Corresponding author: li@nwpu.edu.cn

## Word-Level Token

Word-Level Token

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00655v5-figure-9944ddad-5959-4a3e-a342-ecd90a88d142.jpg)

Figure 1: The schematic form of SentenceVAE. It clearly illustrates that the encoder of SentenceV AE can compress the information contained within a sentence into a single token, and the decoder can restore the compressed token back to its original sentence form.

prolonging the inference process and impeding the scalability and operational efficiency of LLMs. Consequently, there is a critical need to explore alternative methods that can improve the inference speed while preserving or even enhancing the accuracy and responsiveness of LLMs.

To enhance the inference speed of LLMs, Gloeckle et al. (Gloeckle et al. 2024) proposed training LLMs to predict multiple tokens simultaneously, aiming to accelerate the inference process. However, the number of tokens predicted simultaneously is fixed, resulting in a rigid and inflexible partitioning of the input context. For example, when set to five, the input is invariably segmented into non-overlapping sequences of five tokens, regardless of the context's underlying structure, potentially compromising inference accuracy.

To enhance inference speed while preserving or even enhancing accuracy, we explore method for adaptively selecting the optimal number of predicted tokens based on the semantic content of the text. Consequently, we introduce Sentence Variational Autoencoder (SentenceVAE), which comprises a sentence encoder and a sentence decoder. The schematic of SentenceVAE is illustrated in Fig. 1. The sentence encoder is designed to condense the information of an entire sentence into a single token, while the sentence decoder reconstructs this compressed token back into a sentence. By seamlessly incorporating the encoder and decoder components of SentenceVAE into the input and output layers of LLMs, these enhanced models are capable of performing next-sentence prediction. This integration not only enriches the models' capabilities but also accelerates the inference speed, leading to improved efficiency in language understanding and generation. Moreover, since SentenceVAE segments text at the sentence level, the semantic integrity is better preserved, ensuring the accuracy of the inferrence. Specifically, prior to inputting text into LLMs, SentenceV AE segments the text into sentences and utilizes the sentence encoder to compress the information contained within each sentence into a single token. These compressed tokens are then fed as input to the LLMs. The LLMs predict their output based on these compressed tokens. Finally, the sentence decoder decodes the predicted token into the final output of the LLMs.

The contribution of the proposed method can be described as follows:

- · Wepropose SentenceVAE, a model capable of compressing the information content of a sentence into a single token and expanding such tokens to reconstruct sentences with high informational fidelity.
- · We embed the encoder and decoder components of SentenceVAE into the input and output layers of LLMs, enabling these models to implement an effective inference method for next-sentence prediction.
- · Extensive experiments conducted on various LLMs have demonstrated that the proposed method not only accelerates inference speed, but also improves accuracy, and reduces memory usage, enabling the model to handle longer contexts with the same device memory.

## Related Work

Large language models: recently, LLMs have achieved remarkable performance in the field of natural language processing (NLP). However, these models typically possess a vast number of parameters from billions to hundreds of billions, exemplified by models such as TeleChat (1B-52B)

from TeleAI (Wang et al. 2024; Li et al. 2024b), Llama (7B405B) from Meta (Touvron et al. 2023a,b), InternLM (1.8B20B) from Shanghai AI Lab (Cai et al. 2024), etc. The sheer magnitude of these parameters renders the inference process computationally intensive and time-consuming. Moreover, most LLMs employ a one-token prediction method, where the model predicts only one token at a time. This tokenby-token method further exacerbates the inference time of LLMs. As a result, accelerating the inference speed of LLMs while preserving or enhancing their accuracy presents a significant challenge for researchers.

Multi token prediction: the transformer model enables the parallel processing of sequences through its selfattention mechanism, providing a technical foundation for the implementation of multi-token prediction (Vaswani et al. 2017). The BERT model utilizes bidirectional encoder representations to capture contextual information, further solidifying the basis for the implementation of multi-token prediction (Devlin et al. 2018). The T5 model incorporates multi-token prediction during the training process for the first time, significantly enhancing the coherence and quality of the generated text (Raffel et al. 2020). The Better &amp; Faster LLMs apply multi-token prediction to LLMs, allowing them to directly predict multiple tokens in a single inference step, thereby reducing the number of inference iterations and associated computational costs (Gloeckle et al. 2024). However, the number of predicted tokens is fixed, which may inadvertently combine unrelated tokens. This can result in the merging of unrelated tokens, disrupting the original sentence structure and consequently reducing inference accuracy.

Encoder-decoder model: the concept of an encoder is introduced by Yann LeCun in his doctoral dissertation (Le Cun 1987), wherein he posited that an encoder could transform input data into shorter representations without losing the core information, thereby providing a foundational approach to compressing high-dimensional data. The Variational Autoencoder (VAE) model introduces the use of hidden variables between the encoder and decoder to learn the data distribution, laying the groundwork for deep-learningbased encoders and decoders (Kingma and Welling 2013). Sutskever et al. introduces the encoder-decoder framework into the field of deep learning, utilizing recurrent neural networks (RNNs) as both the encoder and decoder for sequence-to-sequence (Seq2Seq) learning, demonstrating exceptional performance in machine translation tasks (Sutskever, Vinyals, and Le 2014). The SegNet applies the encoder-decoder model to the field of image segmentation, significantly enhancing segmentation performance (Badrinarayanan, Kendall, and Cipolla 2017). Subsequently, the encoder-decoder model has achieved great success in various domains including machine translation (Cho et al. 2014; Makin, Moses, and Chang 2020), text-to-speech conversion (Li et al. 2020), computational imaging (Chen et al. 2023; Li et al. 2024a), and beyond, fully demonstrating the capability of the encoder-decoder architecture to efficiently compress and restore data.

By leveraging the advantages of multi-token prediction and the encoder-decoder model, we propose SentenceVAE. SentenceVAE is capable of compressing the information

Figure 2: (a) The schematic form of published LLMs. (b) The schematic form of SLLMs, which embedded with SentenceVAEs. It can be clearly seen that, unlike the next-token inference method employed by published LLMs, the proposed method adopts a next-sentence prediction method, which significantly reduces the number of inference iterations and the overall inference cost.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00655v5-figure-6c363d81-fb3c-4d5b-a178-a5eeaa6e5ebb.jpg)

contained within a sentence into a single token, enabling next-sentence prediction and significantly accelerating the inference speed of LLMs. Additionally, our method divides the context into sentences without compromising the original semantics, accelerating the inference speed of LLMs while ensuring inference accuracy.

## Sentence Variational Autoencoder (SentenceVAE)

## Method

We revisited the mechanisms underlying human interaction. Typically, when individuals prepare to speak, they have already formulated the semantic content of an entire sentence in their minds. However, due to the limitations of the vocal cords, which are relatively inefficient organs for sound production, speakers are compelled to articulate sentences word-by-word, much like the token-by-token generation method of LLMs. Similarly, listeners tend to comprehend sentences holistically, rather than word-by-word. This suggests that sentences are the fundamental units of comprehension in natural language. Inspired by this, we developed the Sentence Variational Autoencoder (SentenceVAE), which includes a Sentence Encoder to compress a sentence into a single token and a Sentence Decoder to reconstruct it. By integrating SentenceVAE into LLMs, these models can operate within a more efficient sentence-level embedding space, enabling next-sentence prediction. This method significantly reduces the number of tokens for the same context length, thereby improving the model's inference speed and reducing the memory usage required for self-attention calculation, enabling the model to handle longer contexts. Additionally, by understanding language at the sentence level, the model demonstrates improved accuracy.

Our SentenceVAE primarily consists of a Sentence Encoder and a Sentence Decoder. The encoder encodes multiple word-level tokens from a sentence into a single sentencelevel token, while the decoder reconstructs this sentencelevel token back into the original sequence of word-level tokens. To ensure that the multiple tokens input to the encoder come from individual sentences, we propose a specialized sentence segmentation mechanism. Additionally, we introduce a feature fusion mechanism, which enable the encoder to encode variable-length token sequences into a single sentence-level token.

Sentence Segmentation Mechanism: to ensure that all word-level tokens input to the sentence encoder per time come from a single sentence, we use regular matching to split sentences by punctuation marks such as "," , "." , "?" , "!" before tokenizing. Let the original string be S , and after partitioning, the set { s i | 1 ≤ i ≤ n } is obtained, satisfying S = s s s ...s 1 2 3 n .

Sentence Encoder: taking s = s t (1 ≤ t ≤ n ) as an example, after tokenization, we obtaine a sequence of L token ids D = [ d , d 1 2 , d 3 , ..., d L ] representing a sentence. This sequence is then passed through an embedding layer, resulting in word-level embedding vectors of E , as shown in Eq.1.

$$E = ( e _ { i } ) _ { L \times \text{hidden} \, \text{size} } = \text{Embed} ( D ) \quad \quad ( 1 )$$

These embeddings are subsequently input into selfattention based encoder blocks, yielding hidden features H , as shown in Eq. 2.

$$H = ( h _ { i } ) _ { L \times \text{hidden} \text{size} } = \text{EncoderBlocks} ( E ) \quad ( 2 )$$

To derive the sentence-level token, we fuse these L features into a single vector Ω t ∈ R hidden size . This sentence- level token is then fed into the decoder-only LLM, which generates a new sentence-level token Ω t +1 at each time step.

Feature Fusion Mechanism: after the encoder blocks generates H , we propose a method to fuse them into a single sentence-level token Ω t . This method involves accumulating the L vectors and normalizing them using Layer Normalization (Ba, Kiros, and Hinton 2016), as Eq. 3.

$$\Omega _ { t } = \text{LayerNorm} ( \sum _ { i = 1 } ^ { L } h _ { i } ) \quad \quad ( 3 ) \quad \ \ g _ { 1 } \\ \psi \quad. \quad. \quad \psi \quad. \quad \. \quad \.$$

Sentence Decoder: the Sentence Decoder contains a combination of masked self-attention and cross-attention blocks, where the cross-attention mechanism uses the individual sentence embedding vector Ω t +1 as key (K) and value (V).

In the prediction phase, given Ω t +1 , initialize the input token d 0 = &lt; bos &gt; , the decoder outputs d 1 , and then input [ d , d 0 1 ] and Ω t +1 into the decoder. Repeat this process until d l ′ +1 = &lt; eos &gt; , and terminate the iteration, as Eq. 4.

$$\varphi _ { + 1 } = < e o s >, \, \text{and terminate the iteration, as } E q. \, 4. \, \\ \begin{array} { c } \text{in} \colon d _ { 0 } = < b o s >, l ^ { \prime } = 0 \\ \text{do} \colon \\ \text{$D_{l^{\prime}=[d_{0},d_{1},d_{2},\dots,d_{l^{\prime}}$} ] \quad & \text{$\mathfrak R$} \\ \text{$P_{l^{\prime}=(p_{i})(l^{\prime+1})\timeshidden_size} \\ \text{$=DecoderBlocks(D_{l^{\prime},\Omega_{t+1})$} } ( d _ { l^{\prime}=argmax(p_{l^{\prime})} \\ \text{$d_{l^{\prime+1}=concat(D_{l^{\prime},d_{l^{\prime})} } } ( d _ { l^{\prime}=l^{\prime}+1$} \\ \text{until} \colon d_{l^{\prime}=<e o s >} \\ \text{ret} \colon D_{L^{\prime=l^{\prime}}$} \end{array} \, \text{$\mathfrak r$} \, \text{th} \, \text{pl} \, 2 ( V _ { j } ) }$$

After the iteration is completed, the detokenization process is used to convert the output D L ′ back into a string.

In the training phase, parallel training is adopted, based on masked self-attention mechanism, to ensure that only tokens before d l ′ can be seen when inferring d l ′ +1 . Given an input sequence of D train = [ d , d 0 1 , ..., d L ′ ] , model output logits of P ∈ R ( L ′ +1) × hidden size , and ground truth of D groud truth = [ d , d 1 2 , ..., d L ′ , &lt; eos &gt; ] , focal loss (Lin et al. 2017) is taken as the loss function, as shown in Eq. 5.

$$P & = \text{DecoderBlocks} ( D _ { \text{train} }, \Omega _ { t + 1 } ) \\ P ^ { \prime } & = \text{softmax} ( P )$$

$$\tilde { \lambda } \quad - \sigma \mu \mu \alpha _ { \lambda } ( \tilde { \lambda } ) \\ \text{Loss} & = \sum _ { i = 1 } ^ { L ^ { \prime } } - ( 1 - p _ { d _ { i } } ) ^ { \gamma } \log ( p _ { d _ { i } } ), \gamma = 2$$

## Sentence-level Large Language Models (SLLMs)

Currently, almost all decoder-only LLMs consist of the following components: an embedding layer EMB llm , N decoder-only blocks DB llm , and a fully connected layer FC llm for outputting logits. As shown in Eq. 6, given context tokens D context = [ d , d 0 1 , ..., d l ′ ] , the model generates the next token d l ′ +1 .

$$E _ { \text{context} } & = \text{EMB} _ { \text{llm} } ( D _ { \text{context} } ) \\ & \quad H _ { \text{llm} } & = \text{DB} _ { \text{llm} } ( E _ { \text{context} } ) \\ & \quad P _ { \text{llm} } & = ( p _ { \text{llm}, i } ) _ { ( l ^ { \prime } + 1 ) \times \text{hidden} _ { \text{size} } } \quad \quad ( 6 ) \\ & \quad = \text{FC} _ { \text{llm} } ( H _ { \text{llm} } ) \\ & \quad d _ { l ^ { \prime } + 1 } & = \arg \max ( p _ { \text{llm}, l ^ { \prime } } ) \\ \text{this section, we introduce a unified graffing method to}$$

In this section, we introduce a unified grafting method to graft SentienceVAE onto the beginning and end of any LLM. This method transforms the LLMs into SLLMs, enabling it to operate effectively in the sentence-level embedding space.

Discard Embedding Layer: in a SLLM, the N decoderonly blocks no longer receives word-level tokens directly. Instead, it receives sentence embedding vectors encoded by the sentence encoder. Consequently, the traditional embedding layer in the LLM architecture is removed. Therefore, the model follows Eq. 7.

$$E _ { \text{sllm} } & = [ \Omega _ { 1 }, \Omega _ { 2 }, \dots, \Omega _ { t } ] \\ H _ { \text{sllm} } & = ( h _ { \text{sllm}, i } ) _ { t \times \text{hidden} \, \text{size} } \quad ( 7 ) \\ & = \text{DB} _ { \text{llm} } ( E _ { \text{sllm} } ) \\ \dots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots$$

Termination judgment layer: in previous LLMs, the final fully connected layer FC llm typically converts an H llm ∈ R t × hidden size to a probability vector (logits) P llm ∈ R t × V , where V represents the size of the vocabulary. This allows the model to determine the next token output using sampling algorithms, e.g. , Greedy Search, Beam Search (Graves 2012), Random Sampling, Temperature Sampling (Hinton, Vinyals, and Dean 2015), Top-K Sampling (Fan, Lewis, and Dauphin 2018), and Nucleus Sampling (Holtzman et al. 2019). If the current token output is a special token like eos (end-of-sequence), the iteration terminates. Notably, in SLLMs, the output of DB llm is a sentence-level hidden state vector H sllm . Therefore, traditional token generation methods are not applicable. Instead, we use a new fully connected layer FC sllm called termination judgment layer that converts the H sllm into a 2-dimensional boolean vector B stop flag , as shown in Eq. 8. This vector helps determine whether the current sentence-level hidden state vector signifies the end of a sentence (stop flag) or needs further decoding by the sentence decoder. If the vector indicates an end flag, the iteration terminates. Otherwise, the sentence decoder processes the embedding to generate corresponding tokens, as Eq. 9.

$$B _ { \text{stop} \, \text{flag} } & = ( b _ { i } ) _ { t \times 2 } \\ & = \text{FC} _ { \text{slim} } ( H _ { \text{slim} } )$$

$$\Omega _ { t + 1 } = \begin{cases} < e o s > &, \arg \max ( b _ { t } ) = 1 \\ h _ { s \text{llm}, t } &, \arg \max ( b _ { t } ) = 0 \\ \end{cases} \quad ( 9 )$$

During the training phase, calculate the focal loss for B stop flag as part of the global loss.

Inferencing sentence by sentence: in the SLLM architecture, we use a tiny SentenceVAE model to encode multiple tokens within a sentence into a single sentence embedding vector. This enables the LLM to conduct inference on a sentence-by-sentence basis rather than the traditional tokenby-token method.

## Experiment

To validate our method, we initially trained individual SentienceVAEs using self-supervised methods, demonstrating the capability of compressing multiple tokens from a sentence into a single vector via an encoder and reconstructing the original sequence through a decoder. Subsequently, we integrated these encoders and decoders at the endpoints of open-source LLMs, thereby enhancing LLMs into SLLMs that operate within a sentence embedding space. This modification not only improves perplexity (PPL) and enhances inference speed, but also reduces memory consumption. Observations of the loss curve indicate that SLLMs continue to adhere to the Scaling Law (Kaplan et al. 2020).

## Experimental Setting

Our experiments utilized either a single 4-card RTX 4090 (24G) or a 4-card A100 (40G) (for SLLM-1.3B), employing data parallel distribution for training.

Base Models: we employed the 125M, 350M, and 1.3B models from the OPT series (Zhang et al. 2022) as our base LLMs, exploring the extension to larger models via the Scaling Law.

Dataset: the training dataset comprised the English subset (EN/WebText) of the Wanjuan-1.0 dataset (He et al. 2023), with SentenceVAE samples including approximately 153.6M sentences (1.7B tokens) and SLLM samples encompassing about 6.4M paragraphs (5.6B tokens). A validation set of 1,000 random sentences or paragraphs ensured no overlap with the training data.

Hyperparameters: for SentenceVAEs, we set the maximum tokens per sentence at 64, with a batch size of 128/card, a base learning rate of 1e-7/batch/card, and up to 300K iterations. SLLMs training mirrored these settings, with a maximum of 64 sentences per paragraph, a batch size of 1/card, a base learning rate of 1e-6/batch/card, and up to 1.6M iterations.

All experiments utilized the AdamW optimizer (Loshchilov and Hutter 2017) with AMP (Micikevicius et al. 2017) enabled, a weight decay coefficient of 0.01, and a maximum gradient L2 norm of 1 for clipping. The initial 5K iterations followed a linear learning rate schedule, transitioning to a cosine annealing schedule for subsequent iterations, alongside an Exponential Moving Average (EMA) strategy.

Metrics: PPL was employed as the evaluation metric, calculated for output logits P and ground truth D groud truth as per the defined formula Eq. 10.

$$\text{PPL} = \exp { ( \frac { 1 } { L ^ { \prime } } \sum _ { i = 1 } ^ { L ^ { \prime } } - \log ( p _ { d _ { i } } ) ) } \quad \quad ( 1 0 )$$

## Sentence-level Tokens

We trained SentienceVAEs using a self-supervised approach to assess if sentence embeddings could effectively represent and reconstruct word-level tokens. Models were trained with hidden sizes corresponding to the dimensions of the OPT125M, OPT-350M, and OPT-1.3B, with varying block layers. Performance was evaluated using cross-entropy loss and

PPL on the validation set, confirming our method. The experimental results are presented in Table 1.

Table 1: Metrics of SentenceVAEs on validation set.

| Model        |   Hidden Size |   Hidden Layers |   Loss ↓ |   PPL ↓ |
|--------------|---------------|-----------------|----------|---------|
| SVAE-768-H1  |           768 |               1 |   1.339  |   3.605 |
| SVAE-768-H2  |           768 |               2 |   1.019  |   2.588 |
| SVAE-768-H4  |           768 |               4 |   0.5598 |   1.649 |
| SVAE-1024-H1 |          1024 |               1 |   0.9266 |   2.406 |
| SVAE-1024-H2 |          1024 |               2 |   0.661  |   1.845 |
| SVAE-1024-H4 |          1024 |               4 |   0.3704 |   1.384 |
| SVAE-2048-H1 |          2048 |               1 |   0.5165 |   1.622 |
| SVAE-2048-H2 |          2048 |               2 |   0.2845 |   1.292 |
| SVAE-2048-H4 |          2048 |               4 |   0.127  |   1.115 |

The evaluation results confirm that SentenceVAEs function as intended,validating their theoretical foundations. Table 2 showcases a variety of test cases, including Samples 1, 2, 3, 5, 6 , which serve as conventional examples. To evaluate model robustness, several out-of-distribution samples, marked in blue, are also incorporated:

- · Sample 4, 7: data preprocessing entails segmenting sentences based on punctuation marks, such as "," and "." . Consequently, these samples are split into multiple inputs during both training and deployment. Inputting these samples without prior preprocessing constitutes invalid input for the model.
- · Sample 8: this sample is the pinyin transcription of a well-known Chinese saying and is not in English, hence it is considered invalid input.

Analysis of the model's output reveals the following:

- · In the conventional samples, the model accurately reconstructed the sentences, with the exception of Sample 6 . The error in Sample 6 may be attributed to limitations inherent in the sinusoidal position encoding mechanism (Vaswani et al. 2017).
- · Although Sample 4 contains the illegal input, the model has accurately restored it with only error of punctuation marks. Sample 7 still maintains the meaning of the sentence. In Sample 8 , as the hidden size of the model increases, the model also accurately restores the illegal input 'yao yao ling xian'. These phenomena indicate that the model is robust to illegal inputs.

Overall, the experimental results indicate that, a series of word-level tokens can be represented by a sentence-level token with strong robustness.

## Sentence-level LLMs (SLLMs)

Upon validating the practicality of sentence-level embeddings, we integrated the encoder and decoder components

Table 2: Test examples of SentenceVAEs. Text in blue indicates out-of-distribution samples, text in red highlights partial mismatches between output and input, and the △ denotes missing output.

| ID   | Input Sentence                                    | Tokens   | Output Sentence                                  | Output Sentence                                    | Output Sentence                                     |
|------|---------------------------------------------------|----------|--------------------------------------------------|----------------------------------------------------|-----------------------------------------------------|
| ID   | Input Sentence                                    | Tokens   | SVAE-768-H4                                      | SVAE-1024-H4                                       | SVAE-2048-H4                                        |
| 1    | Hello,                                            | 3        | Hello,                                           | Hello,                                             | Hello,                                              |
| 2    | What's your name?                                 | 6        | What's your name?                                | What's your name?                                  | What's your name?                                   |
| 3    | What's your problem?                              | 6        | What's your problem?                             | What's your problem?                               | What's your problem?                                |
| 4    | Hello, my dear friend                             | 6        | Hello △ my dear friend,                          | Hello △ my dear friend,                            | Hello △ my dear friend,                             |
| 5    | Today is Friday.                                  | 5        | Today is Friday.                                 | Today is Friday.                                   | Today is Friday.                                    |
| 6    | One two three four five six seven eight nine ten˜ | 12       | One two three four six nine ten eight nine night | One two three six four three seven eight nine ten˜ | One two three four five six eight seven nine˜ ten △ |
| 7    | Hahaha.. and you?                                 | 8        | Hahahaaha and you?                               | Hahahaaha and you?                                 | Hahahaaha and you?                                  |
| 8    | Yao yao ling xian!                                | 9        | Yaoaoaoao xian!                                  | yao yaoaoao xian!                                  | Yao yao ling xian!                                  |

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00655v5-figure-52d52c37-3199-44d0-95ff-29a70a8b08fd.jpg)

Figure 3: Scaling Law of (a) SLLMs and (b) SVAEs.

![image](https://ac.marcodsn.me/arxiv-markdown-images/2408.00655v5-figure-bce4590a-f57a-45cf-a41f-aa6c647e8aa3.jpg)

from SentenceVAE with the OPT series models. This integration is detailed in Table 3.

Table 3: The correspondence relationship between SLLMs, base LLMs, and SentenceVAEs

Due to memory constraints during data-parallel distributed training, we were unable to evaluate the SLLM1.3B-H4 model. Comparative performance metrics for the OPT and SLLM models are presented in Table 4.

| Model                                  | Base Model   | Grafted SentenceVAE                    |
|----------------------------------------|--------------|----------------------------------------|
| SLLM-125M-H1 SLLM-125M-H2 SLLM-125M-H4 | OPT-125M     | SVAE-768-H1 SVAE-768-H2 SVAE-768-H4    |
| SLLM-350M-H1 SLLM-350M-H2 SLLM-350M-H4 | OPT-350M     | SVAE-1024-H1 SVAE-1024-H2 SVAE-1024-H4 |
| SLLM-1.3B-H1 SLLM-1.3B-H2              |              | SVAE-2048-H1 SVAE-2048-H2              |
|                                        | OPT-1.3B     |                                        |

Faster Inference: the throughput of SLLMs, measured using the PyTorch framework (Imambi, Prakash, and Kanagachidambaresan 2021), was assessed without the inclusion of optimization techniques such as PagedAttention (Kwon et al. 2023) or acceleration frameworks like TensorRT-LLM or LMDeploy (Contributors 2023). The baseline for this comparison was the original OPT model's throughput. Experimental findings indicate that SLLMs achieve an average inference speed that is 2 to 3 times faster than traditional LLMs. Notably, as the model size increases, the relative overhead of SentenceVAE decreases, thereby magnifying the speed advantage.

Table 4: Benchmark test results of OPTs and SLLMs.

| Model        | Total Params   | Average PPL   | Average PPL   | Average PPL   | Mean output throughput (toks/s)   | Mean output throughput (toks/s)   | Mean output throughput (toks/s)   | Mean GPU memory (KB/token)   | Mean GPU memory (KB/token)   | Mean GPU memory (KB/token)   |
|--------------|----------------|---------------|---------------|---------------|-----------------------------------|-----------------------------------|-----------------------------------|------------------------------|------------------------------|------------------------------|
|              |                | OPT ↓         | SLLM ↓        | ∆ ↓           | OPT ↑                             | SLLM ↑                            | ∆ ↑                               | OPT ↓                        | SLLM ↓                       | ∆ ↓                          |
| SLLM-125M-H1 | 214M           | 26.75         | 31.68         | +18.4%        | 214.57                            | 652.78                            | +204.2%                           | 73.15                        | 12.03                        | -83.6%                       |
| SLLM-125M-H2 | 226M           | 26.75         | 44.60         | +66.7%        | 214.57                            | 539.80                            | +151.6%                           | 73.15                        | 7.08                         | -90.3%                       |
| SLLM-125M-H4 | 250M           | 26.75         | 14.32         | -46.5%        | 214.57                            | 332.12                            | +54.8%                            | 73.15                        | 10.00                        | -86.3%                       |
| SLLM-350M-H1 | 429M           | 25.18         | 24.84         | -1.4%         | 144.33                            | 481.39                            | +233.5%                           | 197.59                       | 29.98                        | -84.8%                       |
| SLLM-350M-H2 | 450M           | 25.18         | 14.81         | -41.2%        | 144.33                            | 442.23                            | +206.4%                           | 197.59                       | 26.78                        | -86.4%                       |
| SLLM-350M-H4 | 492M           | 25.18         | 10.17         | -59.6%        | 144.33                            | 315.61                            | +118.7%                           | 197.59                       | 17.73                        | -91.0%                       |
| SLLM-1.3B-H1 | 1.61B          | 15.95         | 8.76          | -45.1%        | 119.07                            | 479.71                            | +302.9%                           | 400.01                       | 57.07                        | -85.7%                       |
| SLLM-1.3B-H2 | 1.69B          | 15.95         | 3.84          | -75.9%        | 119.07                            | 553.95                            | +365.2%                           | 400.01                       | 55.14                        | -86.2%                       |

Higher Accuracy: the PPL scores for SLLMs were superior to those of the baseline OPT models. This enhancement is attributed to the SLLM framework's ability to process language at a more granular sentence level, thereby boosting overall performance. Moreover, the computation of attention within the sentence embedding space enables SLLMs to handle shorter relative contexts for equivalent text lengths, further enhancing model efficacy.

ordering issues identified in Sample 6 . Although our current models are trained exclusively on English-language corpora, extending support to multiple languages could be a beneficial direction. Despite its nascent stage, the SLLM framework exhibits substantial potential for enhancements and broader applicability.

Longer Context: The maximum context length a model can handle is typically constrained by GPU memory availability. The SLLM framework addresses this by compressing multiple original tokens into a single token, reducing memory usage for contexts of equivalent length. This compression enables an extended context capacity within the same hardware limitations.

In summary, SLLMs can work in setence-level embedding space with faster inference speed, more accurate PPL, and longer context.

## Scaling Law of SLLMs

During the training of SLLMs, an analysis of the loss curve indicates compliance with the Scaling Law, as depicted in Figure 3. This result indicates that SLLMs also adhere to the Scaling Law, suggesting that this theory can be extended to larger models.

## Conclusion &amp; Future Trends

This section encapsulates the contributions of our research and delineates several promising avenues for exploration.

## Scaling up SLLMs with Enhanced Architectures

In our study, we employed the well-established Transformer architecture (Vaswani et al. 2017), implemented using the PyTorch framework (Imambi, Prakash, and Kanagachidambaresan 2021), to expedite the validation of our hypotheses. Constraints related to computational resources and time necessitated that our evaluations were confined to models with parameter sizes ranging from 125M to 1.3B. Nevertheless, by corroborating the Scaling Law, we extrapolated the feasibility of our methodologies to larger-scale models. Future iterations of the SLLM framework could integrate advanced architectural enhancements, such as Rotational Position Encoding (RoPE) (Su et al. 2024), to rectify sequence

## SLLMs in Hybrid Edge-Cloud Inference

The SLLM framework embodies a hybrid architecture that amalgamates small and large models. By pinpointing an optimal balance, the smaller model (SentenceVAE) and the larger model (LLM) can be efficiently allocated across edge and cloud environments, optimizing computational loads and improving user interactions.

## SLLMs and Embodied Intelligence

Currently, embodied intelligence that leverages the LLM Agent paradigm faces challenges in direct hardware interactions, relying instead on intermediary mechanisms to translate high-level LLM directives into conventional real-time control logic. A critical bottleneck is the generation rate of 'tokens' at the edge. In contrast, the SLLM framework's enhanced ability to process and produce more 'tokens' under identical computational and temporal constraints presents opportunities for direct interfacing of large embodied intelligence models with underlying hardware systems.

## SLLMs in Multimodal Large Models

In the context of multimodal large models, the 'frames' in video and 'trunks' in audio data can be analogized to 'tokens' in text-based models. The SLLM method could thus be adapted to augment the processing rates of 'frames' in these modalities, potentially elevating user experiences and achieving performance that matches or surpasses current standards.

## Acknowledgments

This research was supported by the China National Key R&amp;D Program (2022YFC2808003) and the Natural Science Basic Research Program of Shaanxi (2024JC-YBMS-468).

## References

Ba, J. L.; Kiros, J. R.; and Hinton, G. E. 2016. Layer Normalization. arXiv preprint arXiv:1607.06450 .

Badrinarayanan, V.; Kendall, A.; and Cipolla, R. 2017. Segnet: A deep convolutional encoder-decoder architecture for image segmentation. IEEE transactions on pattern analysis and machine intelligence , 39(12): 2481-2495.

Cai, Z.; Cao, M.; Chen, H.; Chen, K.; Chen, K.; Chen, X.; Chen, X.; Chen, Z.; Chen, Z.; Chu, P.; Dong, X.; Duan, H.; Fan, Q.; Fei, Z.; Gao, Y .; Ge, J.; Gu, C.; Gu, Y .; Gui, T.; Guo, A.; Guo, Q.; He, C.; Hu, Y.; Huang, T.; Jiang, T.; Jiao, P.; Jin, Z.; Lei, Z.; Li, J.; Li, J.; Li, L.; Li, S.; Li, W.; Li, Y .; Liu, H.; Liu, J.; Hong, J.; Liu, K.; Liu, K.; Liu, X.; Lv, C.; Lv, H.; Lv, K.; Ma, L.; Ma, R.; Ma, Z.; Ning, W.; Ouyang, L.; Qiu, J.; Qu, Y.; Shang, F.; Shao, Y.; Song, D.; Song, Z.; Sui, Z.; Sun, P.; Sun, Y.; Tang, H.; Wang, B.; Wang, G.; Wang, J.; Wang, J.; Wang, R.; Wang, Y.; Wang, Z.; Wei, X.; Weng, Q.; Wu, F.; Xiong, Y.; Xu, C.; Xu, R.; Yan, H.; Yan, Y.; Yang, X.; Ye, H.; Ying, H.; Yu, J.; Yu, J.; Zang, Y .; Zhang, C.; Zhang, L.; Zhang, P.; Zhang, P.; Zhang, R.; Zhang, S.; Zhang, S.; Zhang, W.; Zhang, W.; Zhang, X.; Zhang, X.; Zhao, H.; Zhao, Q.; Zhao, X.; Zhou, F.; Zhou, Z.; Zhuo, J.; Zou, Y.; Qiu, X.; Qiao, Y.; and Lin, D. 2024. InternLM2 Technical Report. arXiv:2403.17297.

Chen, Y.; Sun, Z.; Li, C.; and Li, X. 2023. Computational ghost imaging in turbulent water based on self-supervised information extraction network. Optics &amp; Laser Technology , 167: 109735.

Cho, K.; Van Merri¨ enboer, B.; Bahdanau, D.; and Bengio, Y. 2014. On the properties of neural machine translation: Encoder-decoder approaches. arXiv preprint arXiv:1409.1259 .

Contributors, L. 2023. LMDeploy: A Toolkit for Compressing, Deploying, and Serving LLM. https://github.com/ InternLM/lmdeploy.

Devlin, J.; Chang, M.-W.; Lee, K.; and Toutanova, K. 2018. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805 .

Fan, A.; Lewis, M.; and Dauphin, Y. 2018. Hierarchical Neural Story Generation. arXiv preprint arXiv:1805.04833 . Gloeckle, F.; Idrissi, B. Y.; Rozi` ere, B.; Lopez-Paz, D.; and Synnaeve, G. 2024. Better &amp; Faster Large Language Models via Multi-token Prediction. arXiv preprint arXiv:2404.19737 .

Graves, A. 2012. Sequence Transduction with Recurrent Neural Networks. arXiv preprint arXiv:1211.3711 .

He, C.; Jin, Z.; Xu, C.; Qiu, J.; Wang, B.; Li, W.; Yan, H.; Wang, J.; and Lin, D. 2023. WanJuan: A Comprehensive Multimodal Dataset for Advancing English and Chinese Large Models. arXiv:2308.10755.

Hinton, G.; Vinyals, O.; and Dean, J. 2015. Distilling the Knowledge in a Neural Network. arXiv preprint arXiv:1503.02531 .

Holtzman, A.; Buys, J.; Du, L.; Forbes, M.; and Choi, Y. 2019. The Curious Case of Neural Text Degeneration. arXiv preprint arXiv:1904.09751 .

Imambi, S.; Prakash, K. B.; and Kanagachidambaresan, G. 2021. PyTorch. Programming with TensorFlow: solution for edge computing applications , 87-104.

Islam, R.; and Moushi, O. M. 2024. GPT-4o: The Cutting-Edge Advancement in Multimodal LLM. Authorea Preprints .

Kaplan, J.; McCandlish, S.; Henighan, T.; Brown, T. B.; Chess, B.; Child, R.; Gray, S.; Radford, A.; Wu, J.; and Amodei, D. 2020. Scaling Laws for Neural Language Models. arXiv preprint arXiv:2001.08361 .

Kingma, D. P.; and Welling, M. 2013. Auto-encoding variational bayes. arXiv preprint arXiv:1312.6114 .

Kwon, W.; Li, Z.; Zhuang, S.; Sheng, Y.; Zheng, L.; Yu, C. H.; Gonzalez, J.; Zhang, H.; and Stoica, I. 2023. Efficient Memory Management for Large Language Model Serving with PagedAttention. In Proceedings of the 29th Symposium on Operating Systems Principles , 611-626.

Lazaridou, A.; Gribovskaya, E.; Stokowiec, W.; and Grigorev, N. 2022. Internet-augmented language models through few-shot prompting for open-domain question answering. arXiv preprint arXiv:2203.05115 .

- Le Cun, Y. 1987. Mod` eles connexionnistes de l'apprentissage . Ph.D. thesis, Universit´ e Pierre et Marie Curie. Th` ese de doctorat dirig´e e par Milgram, Maurice Sciences appliqu´ ees Paris 6 1987.
- Li, N.; Liu, Y.; Wu, Y.; Liu, S.; Zhao, S.; and Liu, M. 2020. Robutrans: A robust transformer-based text-to-speech model. In Proceedings of the AAAI conference on artificial intelligence , volume 34, 8228-8235.
- Li, X.; Chen, Y.; Tian, T.; and Sun, Z. 2024a. Part-based image-loop network for single-pixel imaging. Optics &amp; Laser Technology , 168: 109917.
- Li, X.; Yao, Y.; Jiang, X.; Fang, X.; Wang, C.; Liu, X.; Wang, Z.; Zhao, Y.; Wang, X.; Huang, Y.; Song, S.; Li, Y.; Zhang, Z.; Zhao, B.; Sun, A.; Wang, Y.; He, Z.; Wang, Z.; Li, X.; and Huang, T. 2024b. Tele-FLM Technical Report. arXiv:2404.16645.

Lin, T.-Y.; Goyal, P.; Girshick, R.; He, K.; and Doll´ ar, P. 2017. Focal Loss for Dense Object Detection. In Proceedings of the IEEE international conference on computer vision , 2980-2988.

Loshchilov, I.; and Hutter, F. 2017. Decoupled Weight Decay Regularization. arXiv preprint arXiv:1711.05101 .

Makin, J. G.; Moses, D. A.; and Chang, E. F. 2020. Machine translation of cortical activity to text with an encoderdecoder framework. Nature neuroscience , 23(4): 575-582.

Micikevicius, P.; Narang, S.; Alben, J.; Diamos, G.; Elsen, E.; Garcia, D.; Ginsburg, B.; Houston, M.; Kuchaiev, O.; Venkatesh, G.; et al. 2017. Mixed Precision Training. arXiv preprint arXiv:1710.03740 .

- Raffel, C.; Shazeer, N.; Roberts, A.; Lee, K.; Narang, S.; Matena, M.; Zhou, Y.; Li, W.; and Liu, P. J. 2020. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of machine learning research , 21(140): 1-67.

Singhal, K.; Tu, T.; Gottweis, J.; Sayres, R.; Wulczyn, E.; Hou, L.; Clark, K.; Pfohl, S.; Cole-Lewis, H.; Neal, D.; et al. 2023. Towards expert-level medical question answering with large language models. arXiv preprint arXiv:2305.09617 .

Su, J.; Ahmed, M.; Lu, Y.; Pan, S.; Bo, W.; and Liu, Y. 2024. RoFormer: Enhanced Transformer with Rotary Position Embedding. Neurocomputing , 568: 127063.

Sutskever, I.; Vinyals, O.; and Le, Q. V. 2014. Sequence to sequence learning with neural networks. Advances in neural information processing systems , 27.

Touvron, H.; Lavril, T.; Izacard, G.; Martinet, X.; Lachaux, M.-A.; Lacroix, T.; Rozi` ere, B.; Goyal, N.; Hambro, E.; Azhar, F.; et al. 2023a. LLaMA: Open and Efficient Foundation Language Models. arXiv preprint arXiv:2302.13971 .

Touvron, H.; Martin, L.; Stone, K.; Albert, P.; Almahairi, A.; Babaei, Y.; Bashlykov, N.; Batra, S.; Bhargava, P.; Bhosale, S.; et al. 2023b. Llama 2: Open Foundation and Fine-Tuned Chat Models. arXiv preprint arXiv:2307.09288 .

Vaswani, A.; Shazeer, N.; Parmar, N.; Uszkoreit, J.; Jones, L.; Gomez, A. N.; Kaiser, Ł.; and Polosukhin, I. 2017. Attention is All you Need. Advances in neural information processing systems , 30.

Wang, L.; Lyu, C.; Ji, T.; Zhang, Z.; Yu, D.; Shi, S.; and Tu, Z. 2023. Document-Level Machine Translation with Large Language Models. In Bouamor, H.; Pino, J.; and Bali, K., eds., Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing , 1664616661. Singapore: Association for Computational Linguistics.

Wang, Z.; Liu, X.; Liu, S.; Yao, Y.; Huang, Y.; He, Z.; Li, X.; Li, Y.; Che, Z.; Zhang, Z.; Wang, Y.; Wang, X.; Pu, L.; Xu, H.; Fang, R.; Zhao, Y.; Zhang, J.; Huang, X.; Lu, Z.; Peng, J.; Zheng, W.; Wang, S.; Yang, B.; he, X.; Jiang, Z.; Xie, Q.; Zhang, Y.; Li, Z.; Shi, L.; Fu, W.; Zhang, Y.; Huang, Z.; Xiong, S.; Zhang, Y.; Wang, C.; and Song, S. 2024. TeleChat Technical Report. arXiv:2401.03804.

Zhang, B.; Haddow, B.; and Birch, A. 2023. Prompting Large Language Model for Machine Translation: A Case Study. In Krause, A.; Brunskill, E.; Cho, K.; Engelhardt, B.; Sabato, S.; and Scarlett, J., eds., Proceedings of the 40th International Conference on Machine Learning , volume 202 of Proceedings of Machine Learning Research , 41092-41110. PMLR.

Zhang, S.; Roller, S.; Goyal, N.; Artetxe, M.; Chen, M.; Chen, S.; Dewan, C.; Diab, M.; Li, X.; Lin, X. V.; et al. 2022. OPT: Open Pre-trained Transformer Language Models. arXiv preprint arXiv:2205.01068 .
Hongjun An Yifan Chen Zhe Sun Xuelong Li
SentenceVAE: Enable Next-sentence Prediction for Large Language Models with Faster Speed, Higher Accuracy and Longer Context
Current large language models (LLMs) primarily utilize next-token prediction
method for inference, which significantly impedes their processing speed. In
this paper, we introduce a novel inference methodology termed next-sentence
prediction, aiming at enhancing the inference efficiency of LLMs. We present
Sentence Variational Autoencoder (SentenceVAE), which includes a Sentence
Encoder to compress multiple tokens in a sentence into a single token, and a
Sentence Decoder to reconstruct it. By integrating SentenceVAE into the input
and output layers of LLMs, we develop Sentence-level LLMs (SLLMs) that employ a
sentence-by-sentence inference method. In addition, the SentenceVAE module of
SLLMs can maintain the integrity of the original semantic content by segmenting
the context into sentences, thereby improving accuracy while boosting inference
speed. Moreover, compared to previous LLMs, SLLMs process fewer tokens over
equivalent context length, significantly reducing memory demands for
self-attention computation and facilitating the handling of longer context.
Extensive experiments on Wanjuan dataset have revealed that the proposed method
can accelerate inference speed by 204~365%, reduce perplexity (PPL) to 46~75%
of its original metric, and decrease memory overhead by 86~91% for the
equivalent context length, compared to previous token-by-token methods.