Skip to main content

Prequantization utilities (MXFP8 / bw128fp8_deepgemm / NVFP4) for Fireworks AI hot-load / incremental snapshot pipelines

Project description

fireworks-prequant

Prequantization utilities used by the Fireworks AI serving/training stack to produce already-quantized model checkpoints (MXFP8 / NVFP4) so that both the upload and the deployment-side download are smaller, and serving loads the packed weights directly instead of converting bf16 on the fly.

The quantization is byte-identical to the Fireworks runtime's on-the-fly --convert-to-precision (it uses the same kernels), so a prequantized checkpoint serves identically to the bf16 checkpoint + on-the-fly conversion.

Install

pip install fireworks-prequant          # torch + safetensors — enough for mxfp8_bw128

That plain install fully supports the mxfp8_bw128 (bw128fp8_deepgemm) format, which is pure torch. The other two formats each need one extra GPU kernel:

pip install fireworks-prequant[mxfp8]   # + flashinfer  (for fmt="mxfp8")
pip install fireworks-prequant[nvfp4]   # + triton      (for fmt="nvfp4")
pip install fireworks-prequant[all]     # + both        (every format)

torch and flashinfer are already present in the Fireworks trainer/learner image, so this is effectively just adding the pure-Python package there.

Quick start

In-memory (the hook the stage-sharded hot-load weight publisher calls on each PP-stage owner's gathered HF state):

from fireworks_prequant import quantize_state_dict

# hf_state: dict[str, torch.Tensor] of one PP stage (bf16 on CPU)
packed = quantize_state_dict(hf_state, fmt="mxfp8", device="cuda")
# expert weights -> {..}.weight (float8_e4m3fn) + {..}.weight_scale_inv (uint8 E8M0)
# non-expert tensors pass through unchanged

Offline (directory of safetensors shards):

from fireworks_prequant import quantize_checkpoint_dir

quantize_checkpoint_dir(
    "/path/to/bf16-checkpoint",
    "/path/to/mxfp8-checkpoint",
    fmt="mxfp8",
    num_workers=8,
)  # rebuilds the weight index + stamps quantization_config into config.json

Formats

fmt Target Serving precision Extra needed
mxfp8_bw128 128x128 block FP8, fp32 scales moe=bw128fp8_deepgemm none (pure torch)
mxfp8 1x32 block FP8, E8M0 scales moe=mxfp8 [mxfp8] (flashinfer)
nvfp4 packed FP4 + FP8 block scales FP4 [nvfp4] (triton)

mxfp8_bw128 emits the deepseek/DeepGEMM blockwise-fp8 layout ([128,128] fp8 e4m3 weights + [ceil(M/128), ceil(K/128)] fp32 block scales) — the same layout as a natively-fp8 [128,128] HF checkpoint — and is byte-identical to the runtime fireworks::fp8_blockwise_weight_quant conversion.

Only the routed MoE expert projections (model.layers.*.mlp.experts.*.{gate,up,down}_proj.weight, prefix-tolerant) are quantized; dense/attention/gate/shared-expert weights pass through in their original dtype — matching the runtime precision policy.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fireworks_prequant-0.2.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fireworks_prequant-0.2.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file fireworks_prequant-0.2.0.tar.gz.

File metadata

  • Download URL: fireworks_prequant-0.2.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for fireworks_prequant-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4180a8477080de7cfaeb99820fbb1b88f3a1f9ee5f04d269e39d15cafe44f2c3
MD5 9c8ee2bac13edcd549c2886170269a98
BLAKE2b-256 74993fcb24fa5fca79575bad63e451b3384ac4ffc1375b5db8503cad4e7bc249

See more details on using hashes here.

File details

Details for the file fireworks_prequant-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fireworks_prequant-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d7879cda45c4e3f11ee54fd11f1a020eb6ac8a9f6ef2ee9ca06b289f05b96f7
MD5 930527899826457cee730018768a5fb1
BLAKE2b-256 54dd3be8c64be948537abe9677de05756dfc4c5cbb742317d9db1178e43b8403

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page