Product-Quantized N-Grammer Layers for Faster Attention Inference

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Conventional neural networks face inefficiencies in runtime latency and computational overhead due to the scaling of parameters in embedding layers, limiting their performance in machine learning tasks.

Innovation Solution

The implementation of an N-grammer layer that applies sparse and efficient clustering and hashing operations to generate latent n-gram representations, which are then processed by an output neural network, reducing the dependence on the number of parameters and enhancing inference speed.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If conventional embedding layers are used to map network inputs to embedded representations, then the neural network can perform machine learning tasks, but the runtime latency increases and computational overhead scales proportionally to the number of parameters

Engineering Contradiction:
Improveinference speedVSAvoidruntime latency
Core Design Contradiction:
ProductivityVSLoss of time

Solution Approach 1:

The patent changes the parameters of the embedding layer by replacing conventional dense embedding layers with hash-based embedding layers. This parameter change transforms the computational complexity from scaling with the number of parameters to scaling with the vocabulary size and hash table operations, thereby reducing runtime latency and improving inference speed while maintaining task performance.

Inventive Principle:
Principle #35Parameter changes

2Reliability

If conventional embedding layers with many parameters are used, then the neural network can achieve good task performance, but the training and inference cost scales proportionally to the number of parameters

Engineering Contradiction:
Improvetask performanceVSAvoidcomputational resources
Core Design Contradiction:
ReliabilityVSUse of energy by moving object

Solution Approach 1:

The patent extracts the essential function of embedding layers (mapping inputs to representations) while removing the computationally expensive parameter-heavy implementation. By using hash-based embedding layers, the patent retains the functional capability needed for task performance while eliminating the proportional scaling of computational resources with parameters.

Inventive Principle:
Principle #2Taking out (Extraction)

3Ease of operation

If attention-based neural networks with conventional embedding layers are used, then the network can process sequence data, but the wall clock time for inference is doubled compared to the proposed N-grammer layer approach

Engineering Contradiction:
Improvesequence processing capabilityVSAvoidwall clock time
Core Design Contradiction:
Ease of operationVSLoss of time

Solution Approach 1:

The patent substitutes the mechanical system of conventional embedding layer computations with a hash-based computational system. This substitution replaces the parameter-proportional computational mechanics with hash table lookup mechanics, which operate in constant time regardless of the number of parameters, thereby halving the wall clock time for inference while preserving sequence processing capability.

Inventive Principle:
Principle #28Mechanics substitution (Replace mechanical system)

Data Source

PatentUS12423518B2Attention neural networks with N-grammer layers
Publication Date: 2025.09.23 GOOGLE LLC
  • US12423518B2 patent drawing
  • US12423518B2 patent drawing
  • US12423518B2 patent drawing

AI summary

Methods, systems, and apparatus, including computer programs encoded on a computer storage medium, for performing a machine learning task on a network input to generate a network output. In one aspect, one of the systems includes a neural network configured to perform the machine learning task, the neural network comprising an N-grammer layer and an output neural network, the N-grammer layer configured to: at each of one or more heads: receive a sequence of input embeddings; generate a discrete latent representation of the sequence of input embeddings by using a learned product quantization codebook; generate a plurality of n-gram indices from the discrete latent representation; and generate a latent n-gram representation of the sequence of input embeddings; and generate a sequence of output embeddings, and the output neural network configured to: receive the sequence of output embeddings; and process the sequence of output embeddings to generate the network output.