Skip to content

feat(pcie_dma): add INT8 and MXFP8 wire modes#72

Merged
lukealonso merged 4 commits into
masterfrom
codex/sparkinfer-pcie-mxfp8-current-20260722
Jul 23, 2026
Merged

feat(pcie_dma): add INT8 and MXFP8 wire modes#72
lukealonso merged 4 commits into
masterfrom
codex/sparkinfer-pcie-mxfp8-current-20260722

Conversation

@voipmonitor

@voipmonitor voipmonitor commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds two opt-in compressed wire codecs to PCIeDmaAllReduce, each available on the existing all-gather, ring, and all-to-all topologies:

  • i8, i8_ring, i8_a2a: signed block INT8 with one FP32 scale per 128 values
  • mx, mx_ring, mx_a2a: standard MXFP8 with E4M3 payload values and one E8M0 scale per 32 values

All compressed layouts use 132 bytes per 128 values instead of 256 bytes for BF16, reducing wire bytes by 48.4%. Existing BF16 and E4M3 modes are unchanged.

This is an independently maintained combined alternative to #69. It is based directly on current SparkInfer master and includes the requested mx_ring implementation without modifying the other contributor's PR.

Modes

Mode Reduce-scatter All-gather
i8 BF16 ring block INT8 ring
i8_ring block INT8 ring, requantized per hop block INT8 ring
i8_a2a block INT8 scatter with FP32 accumulation block INT8 broadcast
mx BF16 ring MXFP8 ring
mx_ring MXFP8 ring, requantized per hop MXFP8 ring
mx_a2a MXFP8 scatter with FP32 accumulation MXFP8 broadcast

Every mode materializes the owner shard from the same canonical payload forwarded to peers. This preserves the all-reduce requirement that every rank receives bit-identical replicated activations.

Unknown non-empty mode strings raise ValueError; a typo such as mx_rnig can no longer silently select E4M3 ag. Unit tests cover every accepted INT8 and MXFP8 alias, including whitespace and case normalization.

Implementation

  • Adds BF16-to-INT8 quantization, INT8-to-BF16 materialization, FP32 multi-source accumulation, and fused dequantize-add-requantize kernels.
  • Adds standard E4M3/E8M0 MXFP8 equivalents with one scale byte per 32 values.
  • Reuses the existing ring and A2A scheduling, IPC staging, CUDA graph, and rank-consistency contracts.
  • Extends eager, graph-replay, GPU-oracle, and four-rank bit-identity tests to all new modes.
  • Documents topology, wire layout, eligibility, and configuration.

Validation

Completed on 2026-07-22 against current SparkInfer master (1a88b389) and the GLM-5.2 v20 stack:

  • parser and dependency-free codec tests: 62/62 pass
  • Ruff and git diff --check: pass
  • all nine compressed modes: four-GPU eager and CUDA graph replay pass
  • all nine compressed modes: output bit-identical across four ranks
  • MXFP8 GPU payload, E8M0 scales, and dequantized output match the CPU oracle exactly
  • A2A isolation rerun after an unrelated parallel-test TCP port collision: 3/3 pass

GLM-5.2 TP4/DCP4/MTP0 prefill

Wire mode 50k tok/s 64k tok/s
E4M3 ag 3,931 3,802
INT8 i8_ring 4,167 4,105
MXFP8 mx_ring 4,208 4,145

The approximately 1% difference between INT8 and MXFP8 is small enough to treat as run/pair variance. Both ring codecs materially outperform the E4M3 AG topology in this prefill profile while using the same wire bytes.

Paired teacher-forced prompt-logprob drift

An 8,191-position comparison against uncompressed BF16 transport on the same model and prompt produced:

Wire mode Mean logprob delta MAE RMSE Top-1 agreement
INT8 i8_ring -0.009045 0.14034 0.29428 91.283%
MXFP8 mx_ring -0.010088 0.14712 0.30709 90.929%

This is selected-token teacher-forced drift, not full-vocabulary KLD. INT8 was slightly better on this workload; codec selection remains an explicit model-specific choice.

The current long-context needle profile stops being a valid codec discriminator above 200k because its BF16 transport baseline also fails. This PR therefore makes no unsupported long-context retrieval claim.

Configuration

Set SPARKINFER_PCIE_DMA_FP8 or pass the same string as the fp8= constructor argument:

SPARKINFER_PCIE_DMA_FP8=mx_ring python -m your_server

Compressed transport requires BF16 input and a per-rank shard divisible by 128 elements. Other shapes retain the BF16 path.

Summary by CodeRabbit

  • New Features

    • Added compressed PCIe DMA wire modes using INT8 and MXFP8 formats.
    • Added support for AG, ring, and all-to-all communication variants.
    • Added configuration through SPARKINFER_PCIE_DMA_FP8 or the constructor’s fp8 option.
    • Documented mode selection, compatibility requirements, wire-size characteristics, and usage examples.
  • Bug Fixes

    • Improved compressed communication handling for alignment and topology-specific processing.
  • Tests

    • Added coverage for mode parsing, INT8/MXFP8 accuracy, layouts, round trips, and communication consistency.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

PCIe DMA compressed wire transport now supports INT8 and MXFP8 codecs across mode parsing, CUDA kernels, all-reduce routing, documentation, and GPU/CPU validation tests.

Changes

Compressed PCIe DMA wire codecs

Layer / File(s) Summary
Wire-mode configuration and mapping
sparkinfer/comm/pcie/pcie_dma.py, README.md
Adds INT8 and MXFP8 mode aliases, explicit codec/topology mappings, validation for unknown modes, and documentation for supported configurations and constraints.
INT8 and MXFP8 CUDA codecs
sparkinfer/comm/pcie/pcie_dma.cu
Adds quantization, dequantization, accumulation, dequant-add-quant kernels, host launchers, and PyBind exports for INT8 and MXFP8 payloads.
Compressed all-reduce execution
sparkinfer/comm/pcie/pcie_dma.py
Generalizes compressed eligibility, codec dispatch, reduce-scatter/all-gather forwarding, chunk alignment, synchronization, and final BF16 materialization.
Codec and topology validation
tests/comm/test_pcie_dma_*
Expands GPU mode coverage and adds CPU-reference tests for INT8, MXFP8 layouts, scale handling, roundtrips, aliases, topology consistency, and rank consistency.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant PCIeDmaAllReduce
  participant PyBindExtension
  participant CUDAKernels
  participant BF16Output
  Caller->>PCIeDmaAllReduce: all_reduce(mode)
  PCIeDmaAllReduce->>PyBindExtension: select codec launcher
  PyBindExtension->>CUDAKernels: quantize and reduce compressed shards
  CUDAKernels-->>PCIeDmaAllReduce: forward compressed payloads
  PCIeDmaAllReduce->>PyBindExtension: dequantize final shards
  PyBindExtension->>BF16Output: store BF16 results
Loading

Possibly related PRs

Suggested reviewers: lukealonso

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding INT8 and MXFP8 PCIe DMA wire modes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/sparkinfer-pcie-mxfp8-current-20260722

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@voipmonitor

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/comm/test_pcie_dma_int8_codec.py (1)

30-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Optional: add a bit-exact GPU-oracle test for the INT8 kernels. MXFP8 gets a direct dma_quant_mx/dma_dequant_store_mx vs CPU-reference check (test_pcie_dma_mxfp8_codec_matches_cpu_reference), but the INT8 GPU kernels (dma_quant_i8/dma_dequant_store_i8) are only validated indirectly through the tolerance-based four-GPU gate. A parallel GPU codec test would give the INT8 path the same bit-exactness guarantee.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/comm/test_pcie_dma_int8_codec.py` around lines 30 - 93, Add a dedicated
GPU codec test alongside test_int8_roundtrip_has_half_step_error_bound that runs
dma_quant_i8 and dma_dequant_store_i8 on representative INT8 input, then
compares payload, scales, and restored values bit-exactly with _quantize and
_dequantize. Reuse the existing GPU execution/setup conventions and include edge
cases such as zero and out-of-range values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sparkinfer/comm/pcie/pcie_dma.cu`:
- Around line 173-177: Gate the MXFP8 helper usage in mxfp8_scale_byte and
related E8M0 helpers on CUDA Toolkit 12.6 availability, using the repository’s
existing CUDA-version detection conventions. Ensure older toolkits do not
compile or select the __nv_cvt_float_to_e8m0 path, or explicitly
enforce/document CUDA 12.6 as the minimum if that is the established project
policy.

---

Nitpick comments:
In `@tests/comm/test_pcie_dma_int8_codec.py`:
- Around line 30-93: Add a dedicated GPU codec test alongside
test_int8_roundtrip_has_half_step_error_bound that runs dma_quant_i8 and
dma_dequant_store_i8 on representative INT8 input, then compares payload,
scales, and restored values bit-exactly with _quantize and _dequantize. Reuse
the existing GPU execution/setup conventions and include edge cases such as zero
and out-of-range values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 314a3ec4-1dc0-44a7-af5e-ba4005ea6b98

📥 Commits

Reviewing files that changed from the base of the PR and between 1a88b38 and 3fe6d00.

📒 Files selected for processing (8)
  • README.md
  • sparkinfer/comm/pcie/pcie_dma.cu
  • sparkinfer/comm/pcie/pcie_dma.py
  • tests/comm/test_pcie_dma_gpu.py
  • tests/comm/test_pcie_dma_int8_codec.py
  • tests/comm/test_pcie_dma_mode.py
  • tests/comm/test_pcie_dma_mxfp8_codec.py
  • tests/comm/test_pcie_dma_rank_consistency_gpu.py

Comment on lines +173 to +177
__device__ __forceinline__ unsigned char mxfp8_scale_byte(float amax) {
if (amax == 0.0f) return 127;
return __nv_cvt_float_to_e8m0(
amax / kFp8Max, __NV_SATFINITE, cudaRoundPosInf);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

__nv_cvt_float_to_e8m0 CUDA toolkit version introduced cuda_fp8.h

💡 Result:

The CUDA Math API function nv_cvt_float_to_e8m0 and the related E8M0 data type support were introduced in the cuda_fp8.h header in CUDA Toolkit 12.6 [1]. While the cuda_fp8.h header itself has been available in earlier versions of the CUDA Toolkit (e.g., since at least CUDA 11.8 for standard FP8 types like E4M3 and E5M2) [2][3][4], support for the E8M0 format—specifically used for scaling factors—was added in version 12.6 [1]. Third-party projects often implement conditional compilation guards (e.g., checking for CUDA 12.6+) to maintain compatibility with older toolkit versions when using this specific functionality [1].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== repository files =="
git ls-files | rg '(^|/)(cuda\.arch|requirements|pyproject|setup\.py|CMakeLists|cmake|.*cuda.*|.*torch.*ext.*|.*extension.*|README|.*\.cu$)' || true

echo
echo "== relevant references =="
rg -n "__nv_cvt_float_to_e8m0|cudaRoundPosInf|__NV_SATFINITE|cuda_fp8\.h|nv_cvt_float_to_e8m0|load_extension|torch\.utils\.cpp_extension|CMAKE_CUDA|CUDA_ARCH|CUDA_VERSION|cuda" -S --glob '!build/**' --glob '!dist/**' . | head -n 240

Repository: local-inference-lab/sparkinfer

Length of output: 28066


Gate E8M0 MXFP8 helpers on CUDA 12.6+ availability. __nv_cvt_float_to_e8m0 is only available starting in CUDA Toolkit 12.6, but this repository does not document or enforce a CUDA >=12.6 minimum. Since pcie_dma.cu includes this directly, builds with older toolkits can fail for the MXFP8 route. Guard these helpers and/or raise the minimum supported toolkit requirement.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sparkinfer/comm/pcie/pcie_dma.cu` around lines 173 - 177, Gate the MXFP8
helper usage in mxfp8_scale_byte and related E8M0 helpers on CUDA Toolkit 12.6
availability, using the repository’s existing CUDA-version detection
conventions. Ensure older toolkits do not compile or select the
__nv_cvt_float_to_e8m0 path, or explicitly enforce/document CUDA 12.6 as the
minimum if that is the established project policy.

@voipmonitor

Copy link
Copy Markdown
Contributor Author

Fresh manual review and validation completed at 3fe6d0090db4006380e077f4db8fe5f711af6cf5; no blocking code issue was found.

Validation performed:

  • parser and CPU codec/oracle tests: 62/62 passed;
  • four-GPU BF16 plus all nine compressed-mode eager/CUDA-graph cases: 11/11 passed;
  • i8, i8_ring, i8_a2a, mx, mx_ring, and mx_a2a: eager and graph-replay outputs were bit-identical across all four ranks;
  • changed Python files pass Ruff.

The release integration is kept separate from this PR: voipmonitor/b12x@5dc1bcebc26a41a1b8d8126122d5e2347ca3ef27 combines this exact head with test-only PR #71. No extra runtime patch was added to #72.

@lukealonso
lukealonso merged commit 1bfa2a9 into master Jul 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants