lucidrains / vector-quantize-pytorch

Vector (and Scalar) Quantization, in Pytorch
MIT License
2.42k stars 196 forks source link

Difference between FSQ and LFQ #152

Open JasonShen-SH opened 1 month ago

JasonShen-SH commented 1 month ago

Hi,

I was wondering about the difference between FSQ (finite scalar quantization) and LFQ (look-up free quantization) for vector quantization.

As for a single vector among the encoder output, whatever the architecture, if we consider the quantizer to only map to -1 and 1. Then what's the difference ? Within LFQ, it still call the quantized vector to be a "codebook vector" within the "codebook". Well, in essence, that "codebook" is somewhat a concept manually made, it is no more than combinations of different quantization possibilities at each dimension, as it's not learned at all.

Then what's exactly made within FSQ, as the paper said: If we map each entry zi to L values (....., followed by rounding to integers), we obtain a quantized zˆ, where zˆ is one of Lˆd unique possible vectors (d is vector dimension, L is quantization levels, L being 2 is -1 and 1). I believe this Lˆd possible vectors are the codebook itself anyway.

Hope someone could teach & discuss about this, many thanks!

leolin65 commented 4 weeks ago

how about https://github.com/zhaoyue-zephyrus/bsq-vit/blob/main/transcoder/models/quantizer/bsq.py