目录
Yann Collet

Code quantized safetensors tensors by their role (#1177)

Summary: Pull Request resolved: https://github.com/facebook/openzl/pull/1177

Quantized safetensors files (GPTQ, AWQ, compressed-tensors, MLX) store packed 4-bit values in int32 tensors next to their float16 or bfloat16 group scales. The parser only looked at dtypes, so packed values went through the 32-bit numeric graph, slow and no better than bytes, and scales went to the Transformer.

The parser now recognizes these tensors by name (qweight, weight_packed, scales, weight_scale…): packed values are coded as bytes, and scales use the scale selector of D125026993, now shared by both parsers. Compression gets 1.4x to 8x faster, and files slightly smaller:

File (5-layer samples) before after compression MB/s
AWQ Qwen3-14B x1.1258 x1.1332 (+0.66%) 80 → 363
GPTQ Gemma-3-27B x1.1794 x1.1878 (+0.71%) 83 → 628
MLX 4-bit Qwen3.8-27B x1.1257 x1.1314 (+0.51%) 79 → 623
MLX 4-bit Qwen3-30B-A3B (MoE) x1.1292 x1.1337 (+0.40%) 84 → 580
w4a16 Qwen3-8B x1.1389 x1.1412 (+0.20%) 79 → 336
GPTQ Qwen2.5-7B x1.2096 x1.2091 (-0.04%) 75 → 249

Decompression is also up to 35% faster, and whole small models (Qwen2.5-0.5B in GPTQ, AWQ and MLX) gain 0.08-0.31%. GGUF files and safetensors files without these tensors are unchanged. Names are a best-effort guess: a misnamed tensor only compresses less well, never lossily.

Reviewed By: mmandina

Differential Revision: D125489450

fbshipit-source-id: 76cdba4609742a9c854348050862094fd7eaf21a

2天前964次提交

OpenZL

OpenZL delivers high compression ratios while preserving high speed, a level of performance that is out of reach for generic compressors. Check out the blog post and whitepaper for a breakdown of how it works.

OpenZL takes a description of your data and builds from it a specialized compressor optimized for your specific format. Learn how it works →

OpenZL consists of a core library and tools to generate specialized compressors — all compatible with a single universal decompressor. It is designed for engineers that deal with large quantities of specialized datasets (like AI workloads for example) and require high speed for their processing pipelines.

See our docs for more information and our quickstart guide to get started with a guided tutorial.

Project Status

This project is under active development. The API, the compressed format, and the set of codecs and graphs included in OpenZL are all subject to (and will!) change as the project matures.

However, we intend to maintain some stability guarantees in the face of that evolution. In particular, payloads compressed with any release-tagged version of the library will remain decompressible by new releases of the library for at least the next several years. And new releases of the library will be able to generate frames compatible with at least the previous release.

(Commits on the dev branch offer no guarantees whatsoever. Use only release-tagged commits for any non-experimental deployments.)

Despite the big scary warnings above, we consider the core to have reached production-readiness, and OpenZL is used extensively in production at Meta.

Building OpenZL

Prerequisites

OpenZL requires a compiler that supports C11 and C++17. When building with cmake, cmake 3.20.2 or newer is required. There is ongoing work to relax these restrictions. As that happens, this section will be updated.

Build with make

The OpenZL library and essential tools can be built using make:

make

Build Options

The Makefile supports all standard build variables, such as CC, CFLAGS, CPPFLAGS, LDFLAGS, LDLIBS, etc.

It builds with multi-threading by default, auto-detecting the local number of cores, and can be overridden using standard -j# flag (ex: make -j8).

Build Types

Binary generation can be altered by explicitly requesting a build type:

Example:

make lib BUILD_TYPE=DEV

Build types are documented in make help, and their exact flags are detailed with make show-config.

Usual ones are:

  • BUILD_TYPE=DEV: debug build with asserts enabled and ASAN / UBSAN enabled
  • BUILD_TYPE=OPT: optimized build with asserts disabled (default)

Build with cmake

OpenZL can be built using cmake. Basic usage is as follows:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DOPENZL_BUILD_TESTS=ON ..
make -j
make -j test

Details on setting CMake variables is below.

Build Modes

By default, we ship several different predefined build modes which can be set with the OPENZL_BUILD_MODE variable:

  • none (default): CMake default build mode controlled by CMAKE_BUILD_TYPE
  • dev: debug build with asserts enabled and ASAN / UBSAN enabled
  • dev-nosan: debug build with asserts enabled
  • opt: optimized build with asserts disabled
  • opt-asan: optimized build with asserts disabled and ASAN / UBSAN enabled
  • dbgo: optimized build with asserts enabled
  • dbgo-asan: optimized build with asserts enabled and ASAN / UBSAN enabled

[!CAUTION] When switching between build modes, make sure to purge the CMake cache and re-configure the build. For instance, cmake --fresh -DOPENZL_BUILD_MODE=dev-nosan ..

For ASAN / UBSAN, ensure that libasan and libubsan are installed on the machine.

Editor Integration

OpenZL ships with settings to configure VSCode to work with the CMake build system. To enable it install two extensions:

  1. cmake-tools
  2. clangd (or any other C++ language server that works with compile_commands.json)

Important: For proper C++ language server support, you need to generate compile_commands.json:

The preferred method is to use the CMake Tools extension command “CMake: Configure“.

If it doesn’t work, or is too difficult to setup, you can use the manual setup:

mkdir -p cmakebuild
cmake -B cmakebuild -DOPENZL_BUILD_TESTS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
cp cmakebuild/compile_commands.json .

When to regenerate:

  • After cloning the repository (first-time setup)
  • When adding/removing source files
  • When modifying CMakeLists.txt

CMake Variables

  • CMAKE_C_COMPILER = Set the C compiler for OpenZL & dependency builds
  • CMAKE_CXX_COMPILER = Set the C++ compiler for OpenZL & dependency builds
  • CMAKE_C_FLAGS = C flags for OpenZL & dependency builds
  • CMAKE_CXX_FLAGS = C++ flags for OpenZL & dependency builds
  • OPENZL_BUILD_TESTS=ON = pull in testing deps and build the unit/integration tests
  • OPENZL_BUILD_BENCHMARKS=ON = pull in benchmarking deps and build the benchmark executable
  • OPENZL_BUILD_MODE = Sets the build mode for OpenZL and dependencies
  • OPENZL_SANITIZE_ADDRESS=ON = Enable ASAN & UBSAN for OpenZL (but not dependencies)
  • OPENZL_COMMON_COMPILE_OPTIONS = Shared C/C++ compiler options for OpenZL only
  • OPENZL_C_COMPILE_OPTIONS = C compiler options for OpenZL only
  • OPENZL_CXX_COMPILE_OPTIONS = C++ compiler options for OpenZL only
  • OPENZL_COMMON_COMPILE_DEFINITIONS = Shared C/C++ compiler definitions (-D) for OpenZL only
  • OPENZL_C_COMPILE_DEFINITIONS = C compiler definitions (-D) for OpenZL only
  • OPENZL_CXX_COMPILE_DEFINITIONS = C++ compiler definitions (-D) for OpenZL only
  • OPENZL_COMMON_FLAGS = extra compiler flags used in all targets

Windows Build

OpenZL uses modern C11 features that may not be fully supported by MSVC. For Windows builds, we recommend using clang-cl for the best compatibility.

Quick Start (Windows)

  1. Recommended: Use clang-cl for full C11 support

    cmake -S . -B build -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl
    cmake --build build --config Release
  2. Alternative: Use MinGW-w64 for GNU toolchain compatibility.

    cmake -S . -B build -G "MinGW Makefiles"
    cmake --build build --config Release
  3. Limited Support: MSVC may produce C2099 errors due to limited C11 support.

Compiler Detection

Run our detection script to check available compilers and get recommendations:

# PowerShell
./build-scripts/cmake/detect_windows_compiler.ps1

# Command Prompt
./build-scripts/cmake/detect_windows_compiler.bat

For detailed Windows build instructions, troubleshooting, and installation guides, see build-scripts/cmake/WINDOWS_BUILD.md.

License

OpenZL is BSD licensed, as found in the LICENSE file.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号