vector-quantize-pytorch
Route vector-quantize-pytorch tasks across PyTorch vector, residual, scalar, lookup-free, latent, SimVQ, and hierarchical quantizer workflows.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- vector-quantize-pytorch
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Route vector-quantize-pytorch tasks across PyTorch vector, residual, scalar, lookup-free, latent, SimVQ, and hierarchical quantizer workflows.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/package-overview.md5.1 KB
- 参考文档references/repo-provenance.md1.6 KB
- 参考文档references/repo-routing-metadata.json361 B
- 参考文档references/troubleshooting.md4.4 KB
- 脚本scripts/check_vector_quantize_env.py3.7 KB
03 SKILL.md 正文
vector-quantize-pytorch
Use this repo skill when a task asks how to use, configure, debug, or validate the vector-quantize-pytorch package for neural discrete representations, VQ-VAE tokenizers, residual quantizers, finite scalar quantizers, lookup-free quantizers, latent quantizers, SimVQ, or hierarchical image feature-map quantization.
Do not use this skill for generic PyTorch training, unrelated LLM weight quantization, bitsandbytes/QLoRA quantization, vector databases, or nearest-neighbor search libraries unless the task explicitly involves vector-quantize-pytorch APIs.
Install and import baseline
pip install vector-quantize-pytorch
python - <<'PY'
import torch
from vector_quantize_pytorch import VectorQuantize
vq = VectorQuantize(dim=8, codebook_size=16)
x = torch.randn(1, 4, 8)
quantized, indices, loss = vq(x)
print(quantized.shape, indices.shape, loss.shape)
PY
The package imports as vector_quantize_pytorch. Base runtime dependencies are PyTorch, einops/einx utilities, and torch-einops-utils; the public package has no console entry point. Optional examples may need training-only packages such as torchvision, tqdm, fire, or x-transformers, but those are not needed for ordinary API use.
Route by task
| Task signal | Read |
|---|---|
Single-stage learned codebooks, VectorQuantize, codebook size/dim, masks/lens, image or 3D feature maps, top-k/manual EMA, random projection quantizer, codebook health tricks |
vector-quantization |
ResidualVQ, GroupedResidualVQ, stacked residual codebooks, shared/stochastic codebooks, quantize dropout, beam search, DiVeQ, reconstruction from residual indices |
residual-quantizers |
FSQ, FSP, ResidualFSQ, GroupedResidualFSQ, finite scalar levels, scalar index encoding/decoding, projections, FSP perturbation/norm/activation choices |
scalar-quantizers |
LFQ, ResidualLFQ, GroupedResidualLFQ, LatentQuantize, BinaryMapper, EvoLFQ, binary latents, entropy/diversity losses, latent levels |
lookup-free-and-latent |
SimVQ, ResidualSimVQ, frozen/implicit codebooks, HierarchicalVQ, multi-scale image feature-map quantization |
sim-and-hierarchical |
Shared references and checks
- Package overview summarizes public API families, tensor layouts, return tuple conventions, and common selection rules.
- Troubleshooting covers install/import failures, PyTorch backend choices, optional example dependencies, tensor shape/layout errors, reconstruction gotchas, and when to run sub-skill smoke helpers.
- Repository provenance records the source snapshot used to create this skill; read it before deciding whether the skill is stale for another checkout.
- Router metadata is structured import metadata for the managed
repo-skills-routerif this skill is imported later. - Environment checker performs a safe CPU import and representative quantizer smoke check:
python scripts/check_vector_quantize_env.py --help
python scripts/check_vector_quantize_env.py
Common operating rules
- Choose the quantizer family first.
VectorQuantize/ResidualVQare learned-codebook workflows; FSQ/FSP avoid learned embeddings; LFQ/LatentQuantize use binary or per-latent code values; SimVQ/HierarchicalVQ cover implicit/frozen and multi-scale image cases. - Decide tensor layout before coding. Many APIs default to
(batch, sequence, dim); image/video APIs may requireaccept_image_fmap=True,accept_3d_fmap=True,channel_first=True, or a class-specific layout. - Treat return tuples as class-specific. Do not assume every quantizer returns
(quantized, indices, loss): FSQ returns two values, FSP returns four, random projection returns indices only, and hierarchical APIs may return a list/tuple of indices. - Use eval mode when generating indices for later reconstruction unless the workflow explicitly needs training-time stochastic sampling or dropout.
- Do not run original tutorial training loops as quick checks. Use the bundled smoke scripts first; full examples can require dataset downloads, optional packages, and training time.
- If a workflow spans families, read both sub-skills and keep ownership clear: for example, an audio tokenizer may combine residual routing with scalar or lookup-free details.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).