Non-autoregressive VQ-VAE for text compression, with a focus on studying codebook collapse dynamics. Trained on TinyStories using a dataset-specific BPE tokenizer.
models/text_vqvae.py— model definition: transformer encoder ↠8E7A ’ VectorQuantizer → memory-trunk decodercommon/— shared utilities (paths, device detection, wandb tracking, text data loading)training/run_text_vqvae_experiment.py— main training entry pointtraining/text_vqvae/— sub-package: config, training loop, codebook init, reportingtraining/train_tokenizer.py— trains a byte-level BPE tokenizer on a text datasettraining/run_experiment_sequence.py— runs a JSON-configured sequence of experimentsvisualization/text_vqvae.py— PCA diagnostics and encoder/codebook distribution plotstests/— unit and integration testsconfigs/— example experiment sequence JSON configs
legacy/ contains the original learning-project code. Entry points are renamed:
python -m legacy.training.trainAE
python -m legacy.training.trainVAE
python -m legacy.training.trainVQVAE
python -m legacy.training.run_collapse_experimentsAll training entry points report configs and metrics to Weights & Biases. Put the API key
in the ignored root .env file (project/entity settings are optional):
WANDB_API_KEY=your_api_key
WANDB_PROJECT=ae-vqvae
# WANDB_ENTITY=your_team_or_username# list every flag with its effective dataclass default
python -m training.run_text_vqvae_experiment --help
# print resolved JSON to stdout without creating a run
python -m training.run_text_vqvae_experiment --print-config
python -m training.run_text_vqvae_experiment --collapse-preset anti --batch-size 64 --print-config
# run TinyStories compression with the trained 8K BPE tokenizer (default)
python -m training.run_text_vqvae_experiment --run-name my_run
# choose decoder type: cross_attention (original) or memory_trunk (current best)
python -m training.run_text_vqvae_experiment --decoder-type memory_trunk
# use kmeans codebook initialization instead of random
python -m training.run_text_vqvae_experiment --codebook-init kmeans
# train as a continuous AE for 1,000 optimizer steps, then fit K-means C0
# immediately before step 1,001 and continue as a VQ-VAE
python -m training.run_text_vqvae_experiment \
--codebook-init kmeans --ae-warmup-steps 1000
# stop AE warmup automatically when target-rate and 99%-variance latent
# dimensions plateau; max-steps is a required safety cap
python -m training.run_text_vqvae_experiment \
--codebook-init kmeans --ae-warmup-mode adaptive \
--ae-warmup-min-steps 1000 --ae-warmup-max-steps 5000
# change the slot-level PAD exclusion threshold (default: 0.5)
python -m training.run_text_vqvae_experiment --slot-pad-ratio-threshold 0.5
# enable all anti-collapse measures (EMA, dead-code reset, entropy loss, …)
python -m training.run_text_vqvae_experiment --collapse-preset anti
# quick offline smoke test from a local file
python -m training.run_text_vqvae_experiment \
--data-file path/to/text.txt --tokenizer byte \
--epochs 1 --max-train-samples 200 --batch-size 8
# run a configured sequence of experiments
python -m training.run_experiment_sequence --config configs/text_vqvae_experiments.example.json
python -m training.run_experiment_sequence --config configs/text_vqvae_experiments.example.json --dry-run# train an 8K byte-level BPE tokenizer on the full TinyStories train split
python -m training.train_tokenizer
# quick streaming smoke run
python -m training.train_tokenizer --streaming --max-samples 1000 --output-dir outputs/tokenizers/smokepython -m visualization.text_vqvae # initial PCA diagnostic (also run automatically at training start)uv run pytest tests/scripts/sync_outputs_from_mech.sh # skip weights and raw geometry
scripts/sync_outputs_from_mech.sh --include-pt # also pull all model/checkpoint weights
scripts/sync_outputs_from_mech.sh --best-only # pull best.pt only
scripts/sync_outputs_from_mech.sh --include-geometry # also pull raw geometry snapshots
scripts/sync_outputs_from_mech.sh --include-pt --include-geometry
scripts/sync_outputs_from_mech.sh --latest-only # sync only the newest run directoryBoth text-data training entries read HF_TOKEN from the process environment first,
then fall back to the ignored project-root .env file. The token is never written to
run configs, tokenizer artifacts, or repository files.
Managed via uv (pyproject.toml). Core: torch, torchvision, matplotlib, tokenizers, datasets, wandb, scikit-learn.