A queue-based dictionary is a large, dynamic memory bank of encoded representations maintained as a first-in-first-out (FIFO) queue, serving as a consistent source of negative samples in contrastive learning frameworks. By decoupling the dictionary size from the mini-batch size, it enables access to a vast and stable set of negatives without requiring prohibitively large GPU memory.
Glossary
Queue-Based Dictionary

What is Queue-Based Dictionary?
A dynamic memory bank that decouples dictionary size from mini-batch size, enabling robust unsupervised feature learning with a vast set of negative samples.
Popularized by the MoCo (Momentum Contrast) architecture, the queue is progressively updated by enqueuing the latest mini-batch encodings and dequeuing the oldest. A momentum encoder—updated via exponential moving average—produces the queued keys, ensuring temporal consistency and preventing rapid representation drift that would degrade the contrastive learning signal.
Key Features of Queue-Based Dictionaries
The queue-based dictionary is the architectural innovation that decouples dictionary size from mini-batch size, enabling contrastive learning frameworks to access a vast and consistent set of negative samples without prohibitive memory costs.
FIFO Queue Structure
The dictionary is maintained as a First-In-First-Out (FIFO) queue of encoded representations. New mini-batch encodings are enqueued while the oldest representations are dequeued, ensuring the dictionary reflects a sliding window over recent training iterations. This dynamic replacement strategy maintains a large and consistent set of negative keys without storing the entire dataset in memory.
Decoupling from Batch Size
Traditional contrastive methods like SimCLR require large batch sizes (e.g., 4096–8192) to provide sufficient negative samples, demanding massive GPU memory. The queue-based dictionary completely decouples the number of negative samples from the mini-batch size. A dictionary of 65,536 keys can be maintained while using a batch size of only 256, making unsupervised pre-training feasible on commodity hardware.
Momentum Encoder for Consistency
Keys in the dictionary are produced by a momentum encoder—a slowly evolving copy of the query encoder updated via exponential moving average:
- Update rule: θ_k ← mθ_k + (1-m)θ_q, where m is typically 0.999
- Benefit: Prevents rapid key fluctuation, ensuring that dictionary representations remain temporally consistent across training steps
- Result: The query can compare against a stable, slowly drifting set of negatives rather than a chaotic, rapidly changing one
Progressive Key Replacement
Each training iteration enqueues the current mini-batch encoded by the momentum encoder and dequeues the oldest batch. This creates a progressive curriculum where:
- The oldest, most outdated representations are discarded first
- The dictionary always contains the most recent 65,536+ encoded samples
- The model is constantly challenged against increasingly difficult negatives as training progresses and representations improve
Memory-Efficient Negative Sampling
By storing only the low-dimensional encoded vectors (typically 128-d) rather than raw images or intermediate feature maps, the dictionary achieves extreme memory efficiency:
- 65,536 keys × 128 dimensions × 4 bytes ≈ 33.5 MB of GPU memory
- Enables hundreds of thousands of negatives without gradient computation through them
- The keys are treated as constant tensors during loss calculation, eliminating the need to store activations for backpropagation
MoCo Integration Pattern
The queue-based dictionary is the defining feature of the MoCo (Momentum Contrast) framework. The architecture follows a lookup-encode-enqueue cycle:
- Lookup: Sample a large set of negative keys from the dictionary
- Encode: Process the current query batch through the query encoder
- Contrast: Compute InfoNCE loss against both positive keys and dictionary negatives
- Enqueue: Add the new momentum-encoded batch to the dictionary
- Dequeue: Remove the oldest batch to maintain fixed dictionary size
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Explore the architectural details and operational mechanics of the queue-based dictionary, a critical component in modern contrastive learning frameworks that decouples dictionary size from mini-batch size.
A queue-based dictionary is a dynamic, large-scale memory bank of encoded data representations maintained as a First-In-First-Out (FIFO) queue. It functions as a continuously updated repository of negative sample keys for contrastive learning. As new mini-batches are processed by a momentum encoder, their output representations are enqueued into the dictionary, while the oldest representations are simultaneously dequeued. This mechanism decouples the dictionary size from the mini-batch size, allowing the model to access a vast and consistent set of negative samples—often numbering in the tens of thousands—without incurring the prohibitive GPU memory costs of a massive batch. The queue ensures that the keys are progressively replaced, maintaining a semantically diverse and up-to-date set of negatives that evolves smoothly over the course of training.
Related Terms
The queue-based dictionary is a central mechanism in modern contrastive learning. Explore the key concepts that interact with this dynamic memory bank to enable robust self-supervised pre-training.
Momentum Contrast (MoCo)
The foundational framework that popularized the queue-based dictionary. MoCo decouples dictionary size from mini-batch size by maintaining a FIFO queue of encoded representations. A momentum encoder—updated via an exponential moving average—produces consistent keys, ensuring the dictionary evolves smoothly over time.
Momentum Encoder
A slowly evolving copy of the primary query network, updated via exponential moving average (EMA). This prevents the keys in the queue from becoming outdated too quickly. The momentum update rule is θ_k ← mθ_k + (1-m)θ_q, where m is typically a large coefficient like 0.999.
Negative Pair Sampling
The strategy of selecting dissimilar data points to serve as repulsive anchors in the InfoNCE loss. The queue acts as a large, consistent source of negative samples. Effective sampling—including hard negative mining—is critical for learning discriminative features.
InfoNCE Loss
A noise-contrastive estimation objective that frames representation learning as a classification problem. It maximizes mutual information between a query and its positive key while minimizing it for all negative keys in the queue. The queue provides the large set of negatives required for this categorical cross-entropy calculation.
Representation Collapse
A critical failure mode where the encoder outputs a constant vector for all inputs. The queue-based dictionary helps prevent collapse by maintaining a diverse, decoherent set of negative samples. Without a large and varied queue, the model can find a trivial solution to the contrastive objective.
BYOL (Bootstrap Your Own Latent)
A non-contrastive method that does not use negative pairs. While it avoids a queue, understanding BYOL highlights the queue's specific role. BYOL prevents collapse using a stop-gradient operation and a momentum encoder, whereas queue-based methods rely on the repulsive force of a large negative dictionary.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us