---
title: 'LogQ Algorithm: Distinct Methods Overview'
url: https://www.emergentmind.com/topics/logq-algorithm
type: topic
---

# LogQ Algorithm: Distinct Methods Overview

Searching arXiv for recent papers using “LogQ” across domains.
{}
The expression “LogQ algorithm” does not denote a single standardized method in the contemporary arXiv literature. It is used for several technically distinct constructions that share a logarithmic, log-corrected, or logarithmic-resource interpretation: a sampled-softmax bias correction for large-scale retrieval, a logarithmic-qubit variational encoding for QUBO and its later quantum-inspired reformulation, and closely related logarithmic quantization schemes such as LogQuant and Log\(_b\)Quant for LLM inference [2507.09331] [2604.12925] [2503.19950] [2607.01127]. This suggests that the term is polysemous rather than canonical.

## 1. Terminological scope

In one major usage, “logQ” refers to a correction applied to sampled softmax when negatives are drawn from a proposal distribution \(Q\), especially the in-batch distribution in two-tower retrieval systems. In another, “LogQ” denotes a variational method for QUBO that uses only \(N=\lceil \log_2 n\rceil\) qubits through amplitude encoding, and later a fully classical reformulation of the same phase-based construction. Closely related names, notably LogQuant and Log\(_b\)Quant, are used for logarithmic quantization of KV cache and model weights rather than for the retrieval or QUBO procedures themselves [2507.09331] [2507.08489] [2604.12925] [2503.19950] [2607.01127].

| Usage | Core object | Representative papers |
|---|---|---|
| logQ correction | Sampled softmax with in-batch negatives | [2507.09331] |
| LogQ for QUBO | Amplitude-encoded variational optimization | [2507.08489], [2604.12925] |
| LogQuant | 2-bit KV-cache compression | [2503.19950] |
| Log\(_b\)Quant | Logarithmic weight quantization | [2607.01127] |

A recurring misconception is that these works describe variants of one algorithm. They do not. The shared label arises from different uses of “log”: \(\log Q(d)\) correction in retrieval, logarithmic qubit scaling in QUBO, and logarithmic codebooks in quantization. A careful reading of notation is therefore necessary before importing results across domains.

## 2. logQ correction in large-scale retrieval

In retrieval systems, the LogQ algorithm is the “widely used industry fix” for the bias induced by sampled softmax with in-batch negatives. The setting is the standard two-tower model
\[
f_\theta(u,d)=\langle g_\theta(u),\,h_\theta(d)\rangle,
\]
trained to make the positive item score larger than scores of all other catalog items. Full softmax over the item set \(\mathcal D\) is the ideal objective, but it is infeasible when \(|\mathcal D|\) is in the millions, so training uses sampled softmax and, in practice, in-batch negatives. Because in-batch negatives follow the empirical item frequency in the training stream, popular items appear more often as negatives and are over-penalized [2507.09331].

The classical logQ correction addresses this mismatch by importance sampling. If negatives are sampled from \(Q(d)\), then
\[
\frac{P_\theta(d\mid u)}{Q(d)} \propto e^{f_\theta(u,d)-\log Q(d)},
\]
which motivates corrected logits
\[
f'_\theta(u,d)=f_\theta(u,d)-\log Q(d).
\]
The standard logQ-corrected loss is
\[
\mathcal{L}_{\text{logQ}(u,p)}
=
-\log
\frac{e^{f_\theta(u,p)-\log Q(p)}}
{e^{f_\theta(u,p)-\log Q(p)}+\sum_{i=1}^{n} e^{f_\theta(u,d_i)-\log Q(d_i)}}.
\]
The paper also notes a widely implemented variant that omits the positive correction in the denominator. In both forms, the operational idea is the same: subtract \(\log Q(d)\) so that oversampled negatives receive reduced influence. The derivation matches the full-softmax gradient asymptotically as the number of negatives \(n\to\infty\) [2507.09331].

Within this literature, “logQ” therefore does not mean logarithmic resource scaling or logarithmic quantization. It means a proposal-distribution correction inside sampled-softmax training.

## 3. Refined logQ and the finite-sample bias problem

The 2025 revision of logQ argues that the standard derivation overlooks a crucial detail: the positive item is not Monte Carlo sampled from \(Q\); it is always present with probability \(1\). The paper rewrites the full-softmax gradient as
\[
\nabla_\theta \mathcal{L}_{\text{softmax}(u,p)}
=
(1-P_\theta(p\mid u))
\left(
-\nabla_\theta f_\theta(u,p)
+
\mathbb{E}_{d\sim P_\theta(\cdot\mid u,\,d\neq p)}
[\nabla_\theta f_\theta(u,d)]
\right),
\]
so the exact gradient is scaled by the model’s misclassification probability \(1-P_\theta(p\mid u)\). Standard logQ instead produces a factor \(1-v_{up}\), where \(v_{up}\) is computed from the sampled denominator that includes the positive. The paper’s claim is that standard logQ is asymptotically consistent but still biased for practical finite \(n\) because it effectively applies importance sampling to the positive “twice” [2507.09331].

The refined correction removes the positive from the denominator and introduces an explicit sample weight
\[
w_{up}=\mathrm{sg}(1-P_\theta(p\mid u)),
\]
with stop-gradient. The resulting loss is
\[
\mathcal{L}_{\text{ours}(u,p)}
=
-
w_{up}\,
\log
\frac{e^{f_\theta(u,p)}}
{\sum_{i=1}^{n} e^{f_\theta(u,d_i)-\log Q'(d_i)}},
\]
where \(d_i\sim Q'(d)\) and \(Q'\) excludes the positive. The weight has an interpretable semantics: it is the probability that the current model misclassifies the positive. This makes the correction a weighted log-softmax over negatives rather than a symmetric logit shift over both positive and negative terms [2507.09331].

Empirically, the refined correction is reported to improve both academic and industrial retrieval benchmarks. On MovieLens-1M and Steam, improved logQ with in-batch or mixed negatives typically performs as well or better than standard logQ. In a production music-retrieval system, the paper reports that consumption Recall@1000 rises from \(0.4308\) to \(0.4616\), and engagement Recall@1000 from \(0.4036\) to \(0.4345\), when moving from standard logQ to improved logQ. The same study emphasizes that high-\(k\) recall is the more relevant operating point for retrieval pipelines, even if performance at \(k=10\) can be similar or slightly lower [2507.09331].

A second misconception follows from the term’s industrial familiarity: standard logQ is often treated as if it fully debiased in-batch sampling. The 2025 analysis explicitly rejects that interpretation.

## 4. LogQ for QUBO: logarithmic qubit scaling and variational encoding

In quantum combinatorial optimization, LogQ refers to a different construction altogether. Here the target problem is spin-QUBO,
\[
s^*=\underset{s\in\{-1,1\}^{n}}{\arg\min}\;
-\frac{1}{2}\sum_{i,j=0}^{n-1} s_i Q_{ij} s_j,
\]
with symmetric \(Q\in\mathbb{R}^{n\times n}\). The distinctive claim of LogQ is that it represents the \(n\) binary variables on only
\[
N=\lceil \log_2 n\rceil
\]
qubits by amplitude encoding rather than computational-basis encoding. The variational state is written as
\[
|\Psi(\theta)\rangle
=
\frac{1}{n}\sum_{i=0}^{n-1} f(\theta_i)\,|i\rangle,
\qquad
f(\theta_i)=e^{-i\pi R(\theta_i)},
\]
and the optimized phases encode the discrete solution through
\[
R(\theta_i^*)=0 \text{ or } 1,
\qquad
s_i^*=
\begin{cases}
-1 & \text{if } R(\theta_i^*)=0,\\
+1 & \text{if } R(\theta_i^*)=1.
\end{cases}
\]
The cost function is
\[
C(\theta)=-2^{N-2}\,\langle \Psi(\theta)|\hat{L}|\Psi(\theta)\rangle,
\]
with \(\hat{L}\) obtained from a Pauli decomposition of \(Q\) [2604.12925].

The appeal of this formulation is resource scaling. The improved-LogQ study states that QAOA uses \(n\) qubits for an \(n\)-variable QUBO, whereas LogQ uses \(N=\lceil\log_2 n\rceil\), and that the number of CNOTs scales as \(\sim n\) for LogQ versus \(p|E|\le p(n^2-n)/2\) for MaxCut in QAOA. This is the basis for the claim that LogQ uses exponentially fewer qubits than QAOA, although it does not remove all bottlenecks because the observable still requires Pauli decomposition and measurement [2507.08489].

The main obstacle in the original quantum formulation was optimization. The original encoding function \(R^{(0)}\) was a step function,
\[
R^{(0)}(\theta_z)=
\begin{cases}
0 & \text{if } \theta_z\in[0,\pi[,\\
1 & \text{if } \theta_z\in[\pi,2\pi],
\end{cases}
\]
so \(R'(\theta_z)=0\) almost everywhere. The corresponding cost landscape is effectively flat for gradient-based methods, forcing the use of genetic algorithms or other global heuristics. The 2025 improvement replaces this with sigmoid-based parameterizations, first
\[
R^{(1)}_\lambda(\theta_z)=\frac{1}{1+e^{\lambda(\pi-\theta_z)}},
\]
and then the “distorted” form
\[
R^{(2)}_{\lambda,\kappa}(\theta_z)=
\mathrm{sgm}_\lambda(\pi-\theta_z)\,\mathrm{sgm}_{-\lambda}(\kappa\pi+2\pi-\theta_z)
+
\mathrm{sgm}_\lambda(\kappa\pi-\theta_z),
\]
which was designed so that \(R(\theta_z)\in[0,1]\), \(R'(\theta_z)=0\Rightarrow R(\theta_z)\in\{0,1\}\), large intervals retain non-small gradients, and small gradients occur only where the cost is close to an extremum. The optimization is then performed with a “gradient-inspired” method, specifically Cobyla, followed by a sharpening stage with \(\lambda=30\) to drive \(R(\theta_z^*)\) toward \(0\) or \(1\) [2507.08489].

On MaxCut instances, this change materially affects optimization quality. For \(n=50\), \(128\), and \(256\), the paper reports objective values of \(-238\), \(-1410\), and \(-5383\) for LogQ-grad, versus \(-219\), \(-1325\), and \(-5149\) for original LogQ with a genetic algorithm under comparable runtime budgets [2507.08489].

## 5. Classical reformulation: LogQ as a non-linear continuous relaxation

A later development removes the quantum device entirely while preserving the same phase-based encoding. The 2026 paper shows that LogQ can be reformulated as a fully classical heuristic. Instead of measuring
\[
-2^{N-2}\,\langle \Psi(\theta)|\hat{L}|\Psi(\theta)\rangle
\]
on a quantum computer, one directly minimizes
\[
-\frac{1}{2}\sum_{i,j=1}^{n} f^\dagger(\theta_i)\,Q_{ij}\,f(\theta_j),
\qquad
|f(\theta_i)|=1,
\]
with the same phase parametrization \(f(\theta_i)=e^{-i\pi R(\theta_i)}\). The key identity is
\[
\frac{1}{2}\sum_{i,j=1}^{n} f^\dagger(\theta_i)Q_{ij}f(\theta_j)
=
\sum_{i>j=1}^{n}
\cos\!\big(\pi(R(\theta_i)-R(\theta_j))\big)\,Q_{ij}
+
\text{ctnt},
\]
so, up to an additive constant, the relaxed objective becomes
\[
\widehat{F}(\theta)
=
-
\sum_{i>j=1}^{n}
Q_{ij}\,
\cos\!\big(\pi(R(\theta_i)-R(\theta_j))\big).
\]
The paper emphasizes that this is “no longer a linear relaxation”; it is a non-linear continuous relaxation on the complex unit circle [2604.12925].

The practical significance is negative as well as positive. On the positive side, Pauli decomposition, quantum state preparation, and measurement overhead disappear. On the negative side, the method remains nonconvex and heuristic, and the paper explicitly states that it provides no approximation guarantees or convergence theorems. The intended optimization class is “gradient-inspired” or perturbed-gradient methods, reusing the same design conditions on \(R(\cdot)\) that had been introduced for the improved quantum formulation [2604.12925].

This reformulation also clarifies a second misconception: logarithmic qubit scaling does not by itself make the original quantum LogQ computationally simple. The measurement bottleneck was serious enough that the same ansatz could motivate a purely classical algorithm.

## 6. Related logarithmic schemes and adjacent usages

Closely related names have proliferated in LLM systems, but they denote distinct algorithms. “LogQuant” is a training-free 2-bit KV-cache quantization method that keeps at most \(3W\) tokens in full precision using a log-distributed retention rule and stores the rest in INT2 through the Quanto backend. Its streaming update is based on a recurrent density-halving rule:
```text
Input: A: list of original-precision tokens
       a*: new token (original precision)
       W: window length

if len(A) < 3W:
    A ← concat(A, a*)
else:
    A ← concat(A[0:2W:2], A[2W:3W])
    A ← concat(A, a*)
return A
```
The method reports that it “enhances throughput by 25% and boosts batch size by 60% without increasing memory consumption,” and for Math and Code Completion it reports “40% to 200%” relative accuracy improvement at the same compression ratio over comparable techniques. These are logarithmic quantization ideas, but they are not the retrieval logQ correction and not the QUBO LogQ ansatz [2503.19950].

“Log\(_b\)Quant” is a different logarithmic quantizer for LLM weights. It defines
\[
\mathrm{Quant}(b,s,x)=
\begin{cases}
0 & x=0,\\
\mathrm{sign}(x)\,\left\lfloor \log_b(|x|)+s\right\rceil_{-q_{\max}}^{q_{\max}} & x\neq 0,
\end{cases}
\]
and
\[
\mathrm{Dequant}(b,s,q)=
\begin{cases}
0 & q=0,\\
\mathrm{sign}(q)\cdot b^{|q|-s} & q\neq 0.
\end{cases}
\]
Its tensor-wise base is chosen as
\[
b=\left(\frac{w_{\max}}{w_{\min}}\right)^{1/q_{\max}},
\]
with \(w_{\min}\) determined by an energy-based pruning rule. The reported outcome is superior 4-bit performance versus asymmetric linear quantization at tensor-wise granularity, together with “moderate speedup and high memory savings”; for example, the paper gives 62.6% memory savings for Llama-3.1-8B and 65.0% for Qwen3-14B [2607.01127].

Outside these better-defined usages, the label also appears informally. A 2021 engineering-design paper describes Logspace Sequential Quadratic Programming as “essentially what you refer to as a ‘LogQ algorithm’: SQP run in log-space with a specially constructed quadratic subproblem,” and reports a 40–70% reduction in number of iterations compared to SQP for the cases studied [2105.14441]. A different neighboring usage appears in maximum \(\log_q\)-likelihood estimation for Weibull parameters, where the objective is
\[
l_q(\boldsymbol{\theta};\boldsymbol{x})
=
\sum_{i=1}^{n}\log_q(f(x_i;\boldsymbol{\theta}))
=
\sum_{i=1}^{n}\frac{f^{1-q}(x_i;\boldsymbol{\theta})-1}{1-q},
\]
optimized by a genetic algorithm [2012.08294]. This broader pattern suggests that “LogQ algorithm” functions more as a descriptive label than as a uniquely identified method.

The term therefore has to be interpreted locally. In recommender systems, it denotes a log-proposal correction for sampled softmax. In quantum combinatorial optimization, it denotes a logarithmic-qubit phase-encoding scheme for QUBO, now also reinterpreted as a classical non-linear relaxation. In LLM systems, related names denote logarithmic quantizers for KV cache or weights. Treating these as interchangeable obscures the core methodological point of each line of work.

Source: https://www.emergentmind.com/topics/logq-algorithm