This started as a Minecraft seed compression experiment and turned into something else entirely. The original idea was "can you compress a Minecraft world seed into a codebook the way you'd compress an image?" The answer was yes, but the interesting path was in face compression, not seeds.
What it does
StyleGAN2 generates faces from a latent vector — 18 layers of 512-dimensional codes that together define everything about the face. That's 9,216 numbers per face. In fp32, that's 147,456 bytes per face.
The GLC Codebook compresses that to 180 bytes per face — about 820× compression — by replacing each 512-dim code with an index into a learned codebook. The reconstruction quality is 15.94 dB PSNR, which is indistinguishable from the encoder's own reconstruction in a blind test.
How it works
The pipeline has three stages:
- Encode: Run an e4e encoder over an FFHQ face image to produce the 18×512 W+ latent vector
- Quantize: Replace each 512-dim code with the closest match from a learned codebook of 1024 entries. Do this 8 times per layer (residual VQ) to recover precision
- Decode: Look up the indices, sum the residuals, run through StyleGAN2
The training trick
Most VQ codebooks use gradient descent through a straight-through estimator. I used Lloyd k-means with dead-cluster reseeding. No gradients, no optimizer state. Training 8 stages of 1024 entries each on 68K data points takes 64 seconds on a single RTX A4000.
This isn't a limitation — it's a feature. The entire codebook can be re-trained in under a minute when you get new data. No GPU cluster required.
Results
| Config | Bytes/latent | PSNR | LPIPS (vs orig) |
|---|---|---|---|
| e4e upper bound | — | 18.88 dB | 0.2218 |
| RVQ 8×1024 | 180 B | 15.94 dB | 0.2993 |
| RVQ 4×1024 | 90 B | 15.13 dB | 0.3241 |
The key number is LPIPS 0.1698 for quantization damage alone — the gap between the e4e reconstruction and the codebook reconstruction. The codebook is significantly more accurate than the encoder. The bottleneck is upstream.
Why this matters
Standard compression (JPEG, WebP, AVIF) works in pixel space. You compress pixels, you decompress pixels. GLC compresses in latent space — the compressed representation is directly usable by a generative model without decompressing to pixels first.
At sub-2KB per face, this opens up:
- On-device generation: Store thousands of face encodings in memory you didn't know you had
- Bandwidth-constrained inference: Send face representations over low-bandwidth links
- Efficient face databases: Search faces in compressed space without decompressing
- Video over latent space: The next frontier — temporal coherence in latent codec
What's next
v1.0 ships 8-stage RVQ on FFHQ. The next steps are:
- Hybrid codec: A pixel-space residual layer (WebP-on-residual) for the sub-1.5KB regime where pure-VQ starts losing detail
- Better inversion: PTI or ReStyle could push the encoder ceiling from 18.88 dB to ~22 dB, giving the codebook more room to work
- Video: Temporal GLC — apply the same idea over video frames with motion compensation
Code and full eval on Forgejo.