{"id":35890127,"url":"https://github.com/LeanModels/DFloat11","last_synced_at":"2026-01-15T13:00:47.529Z","repository":{"id":288392828,"uuid":"966916741","full_name":"LeanModels/DFloat11","owner":"LeanModels","description":"DFloat11: Lossless LLM Compression for Efficient GPU Inference","archived":false,"fork":false,"pushed_at":"2025-11-24T09:46:56.000Z","size":68,"stargazers_count":564,"open_issues_count":21,"forks_count":33,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-11-27T22:14:29.081Z","etag":null,"topics":["compression","gpu","llm","lossless-compression-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LeanModels.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-15T16:39:29.000Z","updated_at":"2025-11-27T16:36:54.000Z","dependencies_parsed_at":"2025-05-23T21:19:06.745Z","dependency_job_id":"b50560c1-403c-4980-bd89-4607a8ab36c0","html_url":"https://github.com/LeanModels/DFloat11","commit_stats":null,"previous_names":["leanmodels/dfloat11"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LeanModels/DFloat11","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeanModels%2FDFloat11","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeanModels%2FDFloat11/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeanModels%2FDFloat11/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeanModels%2FDFloat11/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeanModels","download_url":"https://codeload.github.com/LeanModels/DFloat11/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeanModels%2FDFloat11/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28452327,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-15T12:51:34.178Z","status":"ssl_error","status_checked_at":"2026-01-15T12:50:49.284Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compression","gpu","llm","lossless-compression-algorithm"],"created_at":"2026-01-09T05:00:33.425Z","updated_at":"2026-01-15T13:00:47.482Z","avatar_url":"https://github.com/LeanModels.png","language":"Python","funding_links":[],"categories":["Research Articles 📄","Python"],"sub_categories":[],"readme":"# DFloat11: Lossless Compression of LLMs and Diffusion Models for Efficient GPU Inference\n\n[![PyPI version](https://img.shields.io/pypi/v/dfloat11.svg?color=blue)](https://pypi.org/project/dfloat11/)\n[![arXiv](https://img.shields.io/badge/arXiv-2504.11651-b31b1b.svg)](https://arxiv.org/abs/2504.11651)\n[![Hugging Face](https://img.shields.io/badge/Model-%F0%9F%A4%97-yellow.svg)](https://huggingface.co/DFloat11)\n\n**DFloat11** is a lossless compression framework that reduces the size of Large Language Models (LLMs) and diffusion models (e.g. FLUX.1, Qwen-Image, etc.) by approximately **30%** while preserving **bit-for-bit identical outputs** to the original model. It enables efficient GPU inference on resource-constrained hardware without sacrificing any accuracy.\n\n## 📰 News\n- [09/18/2025] Our research paper is accepted to NeurIPS 2025! Hope to see you at the San Diego Convention Center in December!\n- [08/24/2025] Compression code released!\n  * Reduce the size of any model by 30% with DFloat11 compression.\n  * Get started here: [examples/compress_flux1](https://github.com/LeanModels/DFloat11/tree/master/examples/compress_flux1).\n- [07/29/2025] Efficient CPU Offloading Now Supported!\n  * Our latest update enables highly memory-efficient inference by keeping only one transformer block in GPU memory at a time. For example, CPU offloading reduces peak GPU memory for inference of **FLUX.1-Krea-dev from 17.5 to 9.8 GB, Qwen3-8B from 12.4 to 2.3 GB, and HiDream-I1-Full from 26.4 to 9.6 GB**.\n  * An example of using CPU offloading with FLUX.1-Krea-dev-DF11 can be found [here](https://huggingface.co/DFloat11/FLUX.1-Krea-dev-DF11).\n  * To enable CPU offloading, simply set `cpu_offload=True` when calling `DFloat11Model.from_pretrained(...)`.\n- [05/23/2025] **Wan2.1** support is now live! [`DFloat11/Wan2.1-T2V-14B-Diffusers-DF11`](https://huggingface.co/DFloat11/Wan2.1-T2V-14B-Diffusers-DF11)\n  * Text-to-video generation with DFloat11 *Wan2.1 14B* using only 24GB VRAM!\n  * Get started here: [examples/wan2.1](https://github.com/LeanModels/DFloat11/tree/master/examples/wan2.1).\n- [05/06/2025] **DFloat11 now supports [`FLUX.1-dev`](https://huggingface.co/black-forest-labs/FLUX.1-dev)**\n  * 🖼️ Generate stunning text-to-image results on GPUs with **less than 24GB VRAM** --- no quality lost!\n  * 📂 Get started here: [examples/flux.1](https://github.com/LeanModels/DFloat11/tree/master/examples/flux.1).\n- [05/05/2025] The `dfloat11` pip package has been upgraded to `v0.2.0`! Run `pip install -U dfloat11[cuda12]` to upgrade to the latest version. We have made the following important changes:\n  * We added support for Qwen 3, Gemma 3, and Phi 4!\n  * The GPU decompression kernel is now 20-40% faster! We achieved it by improving thread occupancy and implementing tons of optimizations.\n  * The DFloat11 models are now stored in safetensors format for better safety and loading performance.\n  * When using a DFloat11 model, only the compressed model is downloaded, not the original model.\n\n## 📦 Installation\n\nRequires a CUDA-compatible GPU (with CUDA 12) and [PyTorch](https://pytorch.org/get-started/locally/) installed.\n\nTo install from PyPI:\n```bash\npip install -U dfloat11[cuda12]\n```\n\n[Optional] To compile the GPU kernel and install locally:\n```bash\nnvcc -O3 -ptx dfloat11/decode.cu -o dfloat11/decode.ptx\npip install .[cuda12]\n```\n\n## 🔍 How It Works\n\nDFloat11 compresses model weights using **Huffman coding** of BFloat16 exponent bits, combined with **hardware-aware algorithmic designs** that enable efficient on-the-fly decompression directly on the GPU. During inference, the weights remain compressed in GPU memory and are **decompressed just before matrix multiplications**, then **immediately discarded after use** to minimize memory footprint.\n\nKey benefits:\n\n* **No CPU decompression or host-device data transfer**: all operations are handled entirely on the GPU.\n* **Decompression overhead is constant** per forward pass and **independent of batch size**, making DFloat11 increasingly efficient at larger batch sizes.\n* DFloat11 is **much faster than CPU-offloading approaches**, enabling practical deployment in memory-constrained environments.\n* At batch size = 1, inference is approximately 2× slower than the original BF16 model, but the performance gap narrows significantly with larger batches.\n* The compression is **fully lossless**, guaranteeing that the model’s outputs are **bit-for-bit identical** to those of the original model.\n\n## 🚀 Quick Start\n\n1. Install the `dfloat11` pip package. See [Installation](#-installation).\n2. Run the following code in Python, which automatically downloads the DFloat11 `Qwen3-8B` model and generates a response.\n  ```python\n  import torch\n  from dfloat11 import DFloat11Model\n  from transformers import AutoTokenizer\n\n  model_id = \"DFloat11/Qwen3-8B-DF11\"\n\n  model = DFloat11Model.from_pretrained(model_id, device_map=\"auto\")\n\n  tokenizer = AutoTokenizer.from_pretrained(model_id)\n  tokenizer.pad_token = tokenizer.eos_token\n\n  prompt = \"Question: What is a binary tree and its applications? Answer:\"\n  inputs = tokenizer(prompt, return_tensors=\"pt\", padding=True).to(model.device)\n\n  with torch.no_grad():\n      output = model.generate(\n          **inputs,\n          max_new_tokens=256,\n          do_sample=True,\n      )\n\n  print(tokenizer.batch_decode(output, skip_special_tokens=True))\n  ```\n3. Replace the `model_id` in the script above with any pre-compressed model in the [Model Hub](#-model-hub).\n\n## 🏎️ Benchmarking Performance\n\nTo test the speed and memory consumption a DFloat11 LLM during inference:\n\n```bash\nCUDA_VISIBLE_DEVICES=0 python inference.py \\\n  --model_name_or_path DFloat11/Qwen3-8B-DF11 \\\n  --prompt \"Question: What is a binary tree and its applications? Answer:\" \\\n  --num_tokens 512 \\\n  --batch_size 1\n```\n\n\u003e 💡 **Tip**: If you specify multiple CUDA devices (e.g., `CUDA_VISIBLE_DEVICES=0,1`), the model will be automatically distributed across them using 🤗 Accelerate's `device_map=\"auto\"`.\n\n### Arguments\n\n- `--model_name_or_path`: HuggingFace name or local path of the DFloat11 model (e.g., `DFloat11/Qwen3-8B-DF11`). See the [Model Hub](#-model-hub) section for a list of available DFloat11 models.\n- `--bf16`: *(Optional)* Turn on this flag when passing a BFloat16 model to `--model_name_or_path`\n- `--prompt`: Input prompt string for text generation\n- `--num_tokens`: Number of new tokens to generate per sample\n- `--batch_size`: Number of prompts to process in parallel\n- `--seed`: *(Optional)* Random seed for reproducible results\n\n### Output\n\nThe script prints:\n- Generated responses\n- Total decoding latency\n- Tokens per second (throughput)\n- GPU memory usage (allocated and peak)\n\n## 📚 Model Hub\n\n| Model | DFloat11 Link |\n|-------|---------------|\n| Wan2.1 T2V 14B (see [examples/wan2.1](https://github.com/LeanModels/DFloat11/tree/master/examples/wan2.1)) | [DFloat11/Wan2.1-T2V-14B-Diffusers-DF11](https://huggingface.co/DFloat11/Wan2.1-T2V-14B-Diffusers-DF11) |\n| FLUX.1 dev (see [examples/flux.1](https://github.com/LeanModels/DFloat11/tree/master/examples/flux.1)) | [DFloat11/FLUX.1-dev-DF11](https://huggingface.co/DFloat11/FLUX.1-dev-DF11) |\n| Qwen 3 32B | [DFloat11/Qwen3-32B-DF11](https://huggingface.co/DFloat11/Qwen3-32B-DF11) |\n| Qwen 3 14B | [DFloat11/Qwen3-14B-DF11](https://huggingface.co/DFloat11/Qwen3-14B-DF11) |\n| Qwen 3 8B | [DFloat11/Qwen3-8B-DF11](https://huggingface.co/DFloat11/Qwen3-8B-DF11) |\n| Qwen 3 4B | [DFloat11/Qwen3-4B-DF11](https://huggingface.co/DFloat11/Qwen3-4B-DF11) |\n| Phi 4 Reasoning Plus | [DFloat11/Phi-4-reasoning-plus-DF11](https://huggingface.co/DFloat11/Phi-4-reasoning-plus-DF11) |\n| Gemma 3 27B Instruct | [DFloat11/gemma-3-27b-it-DF11](https://huggingface.co/DFloat11/gemma-3-27b-it-DF11) |\n| Gemma 3 12B Instruct | [DFloat11/gemma-3-12b-it-DF11](https://huggingface.co/DFloat11/gemma-3-12b-it-DF11) |\n| Gemma 3 4B Instruct  | [DFloat11/gemma-3-4b-it-DF11](https://huggingface.co/DFloat11/gemma-3-4b-it-DF11) |\n| Llama 3.1 8B Instruct | [DFloat11/Llama-3.1-8B-Instruct-DF11](https://huggingface.co/DFloat11/Llama-3.1-8B-Instruct-DF11) |\n| DeepSeek R1 Distill Qwen 32B | [DFloat11/DeepSeek-R1-Distill-Qwen-32B-DF11](https://huggingface.co/DFloat11/DeepSeek-R1-Distill-Qwen-32B-DF11) |\n| DeepSeek R1 Distill Qwen 14B | [DFloat11/DeepSeek-R1-Distill-Qwen-14B-DF11](https://huggingface.co/DFloat11/DeepSeek-R1-Distill-Qwen-14B-DF11) |\n| DeepSeek R1 Distill Qwen 7B  | [DFloat11/DeepSeek-R1-Distill-Qwen-7B-DF11](https://huggingface.co/DFloat11/DeepSeek-R1-Distill-Qwen-7B-DF11) |\n| DeepSeek R1 Distill Llama 8B | [DFloat11/DeepSeek-R1-Distill-Llama-8B-DF11](https://huggingface.co/DFloat11/DeepSeek-R1-Distill-Llama-8B-DF11) |\n| ... | [Discover more models on our HF page!](https://huggingface.co/DFloat11) |\n\n### How to Use a DFloat11 Model\n\n1. Download a model using the HuggingFace command line tool:\n  ```bash\n  huggingface-cli download \\\n    DFloat11/Llama-3.1-8B-Instruct-DF11 \\     # DFloat11 model name\n    --local-dir ./Llama-3.1-8B-Instruct-DF11  # local path to download the DFloat11 model\n  ```\n2. Run the following in Python to load the model and tokenizer:\n  ```python\n  from dfloat11 import DFloat11Model\n  from transformers import AutoTokenizer\n\n  model_path = \"./Llama-3.1-8B-Instruct-DF11\"\n  model = DFloat11Model.from_pretrained(model_path, device_map=\"auto\")\n  tokenizer = AutoTokenizer.from_pretrained(model_path)\n  ```\n\n## 🗜️ Compressing Models (BFloat16 → DFloat11)\n\nThe DFloat11 compression utility is exposed via the `compress_model` function.\n\nCheck [examples/compress_flux1](https://github.com/LeanModels/DFloat11/tree/master/examples/compress_flux1) for a detailed example on compressing the FLUX.1 model.\n\n## 🔗 Links\n\n👉 Explore pre-compressed DFloat11 models ready to use on HuggingFace: **[https://huggingface.co/DFloat11](https://huggingface.co/DFloat11)**\n\n📂 Official Code Repository: [https://github.com/LeanModels/DFloat11](https://github.com/LeanModels/DFloat11)\n\n## 🧠 Contributions\n\nThis work is brought to you by the team at Rice University and [xMAD.ai](https://xmad.ai/).\n\nThe GPU kernel was designed and implemented by [Tianyi Zhang](https://github.com/tonyzhang617).\n\n## 📚 Citation\n\nIf you found our work useful or interesting, please consider citing our paper:\n\n```bibtex\n@inproceedings{\n  zhang2025,\n  title={70\\% Size, 100\\% Accuracy: Lossless {LLM} Compression for Efficient {GPU} Inference via Dynamic-Length Float ({DF}loat11)},\n  author={Tianyi Zhang and Mohsen Hariri and Shaochen Zhong and Vipin Chaudhary and Yang Sui and Xia Hu and Anshumali Shrivastava},\n  booktitle={The Thirty-ninth Annual Conference on Neural Information Processing Systems},\n  year={2025},\n  url={https://openreview.net/forum?id=xdNAVP7TGy}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLeanModels%2FDFloat11","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLeanModels%2FDFloat11","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLeanModels%2FDFloat11/lists"}