How ugonfor/dgq works
Project Type and Purpose
• This is a research‐codebase and CLI tool for “Distribution‐Aware Group Quantization (DGQ)” of large text‐to‐image diffusion models (Stable Diffusion v1.4 & SDXL‐turbo).
• It integrates with Hugging Face’s diffusers library to perform:
• Weight‐only quantization (4/8 bits)
• Activation quantization (6/8 bits)
• Merging quantized weights+activations
• Running inference on the fully‐quantized model
• Users invoke shell scripts or Python entrypoints to orchestrate each phase.
File‐Structure Analysis
• Top-level:
• environment.yaml, setup.py, Makefile – environment & build
• scripts/*.sh – bash wrappers for each quantization/inference step
• src/*.py – Python modules: calibration, quantization, inference, utilities
• quant/*.py – core quantization routines (weight, activation, group routines)
• results/*.py – post‐processing (merge checkpoints)
• linklink/ – helpers for distributed execution & logging
• diffusers/ & diffusers_rewrite/ – submodule containing the HuggingFace library and a small rewrite for runtime calls
• Patterns:
• “scripts → src → quant → results” sequence for workflow
• Modular separation: quantization logic (quant/), orchestration (scripts/), I/O & merging (results/), external library (diffusers/)
README Insights
• Describes a four‐stage pipeline:
1. Weight quantization
2. Activation quantization
3. Merge the two quantized checkpoints
4. Inference with the merged checkpoint
• Lists external dependencies: PyTorch/CUDA, HuggingFace diffusers, conda environment
Diagramming Recommendations
• Actor (stick‐figure) for the User
• Rounded rectangles for Scripts & CLI entrypoints
• Rectangles for Python modules (quant, src, results)
• Orchestration (scripts & linklink) in blue
• Quantization logic (quant/) in green
• I/O & merge (results/) in orange
• Inference & model loading (src/ + diffusers_rewrite) in purple
• Storage in gray
User → Script → WeightQuant → Storage → ActQuant → Storage → Merge → Storage → Inference → Output
• Orchestration lane (scripts, linklink)
• Compute lane (quant, inference)
• Storage lane (checkpoints)