[RFC] Backend-pluggable low-precision training for Dense Linear and AutoEP grouped GEMM (Ascend HiFloat8)

オープン
#8,777 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
6/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
活発
技術スタック
python, pytorch

調査の方向性

This is an RFC for design review, not a contained change. Start with the configuration tutorial at docs/_tutorials/hifloat8_training.md and the resume check tests/unit/runtime/hifloat8_resume_validation.py, then benchmarks/profile_hifloat8.py. Done means maintainers agree on the accelerator/provider boundary and the review questions in the issue are resolved.

索引モデルが issue の本文から書いたものです。

説明

Summary

Add optional TorchAO training support for Dense Linear and AutoEP grouped experts, starting with Ascend HiFloat8. The implementation is in draft PR #8784. Both module types use one public torchao.quantization.quantize_ call. DeepSpeed owns module selection and training/distributed execution; AO owns the numerical policy and low-precision GEMM implementations.

The current configuration uses hifloat8.backend="torchao". On NPU, the installed Ascend extension exposes its implementation through torchao.hifloat8. DeepSpeed consumes that public namespace; it does not import torchao_npu in the training integration. This still requires the paired NPU extension: installing upstream TorchAO alone does not provide this HiFloat8 path.

Motivation

Our Q4 work focuses on MoE training, in particular low-precision expert GEMMs. After token routing, the gate/up/down projections become groups of matrix multiplications over expert weights. The AO NPU extension provides HiFloat8 quantization and grouped GEMM forward/backward kernels for these operations: 8-bit operands reduce GEMM payload size and can use the device's native low-precision compute, while model parameters and training boundaries remain BF16.

We want DeepSpeed to integrate with TorchAO as a shared low-precision component, using torchao imports rather than an NPU-specific package API. Hardware packages should supply their policies and kernels through that component, with DeepSpeed retaining its existing accelerator abstraction and training lifecycle. Ascend HiFloat8 is the first implementation here; support for other hardware and formats is a direction for this interface, not a claim that those paths have been implemented or validated.

The main practical constraint is conversion overhead. Faster GEMMs do not guarantee faster training when quantization, layout copies, routing and communication remain. The work therefore covers both the integration boundary and the actual Dense/grouped execution paths.

Architecture

Owner Responsibilities
DeepSpeed engine Select modules, check training compatibility, apply conversion after AutoEP replacement/device placement and before optimizer setup, manage optimizer/checkpoint lifecycle
DeepSpeed AutoEP Expert sharding, routing, padding, activation, token dispatch/combine and DP/EP communication
Accelerator Resolve optional capabilities through get_hifloat8_provider() and the separate high-precision get_grouped_mm() hook
TorchAO and its NPU extension Parse HiFloat8Config, probe requested native kernels, register Linear/grouped handlers, implement HiFloat8 Dense/grouped quantization and autograd
TorchNPU/CANN Execute native quantization and GEMM kernels

Shared initialization is on the left; Dense and MoE execution are the two parallel paths. DeepSpeed performs AutoEP replacement and device placement before selection and preflight checks. Routing and communication stay in AutoEP; low precision applies at the Linear and expert GEMM call sites.

%%{init: {"theme": "base", "htmlLabels": false, "fontFamily": "Arial, sans-serif", "themeVariables": {"fontSize": "16px", "fontFamily": "Arial, sans-serif", "lineColor": "#64748b"}, "flowchart": {"htmlLabels": false, "nodeSpacing": 24, "rankSpacing": 28, "padding": 12}}}%%
flowchart LR
    A["DeepSpeed<br/>select + preflight"] --> Q["quantize_<br/>shared AO policy"]
    Q --> D["Dense / AO handler<br/>HiFloat8Linear<br/>hifloat8_linear"]
    Q --> M["AO grouped handler<br/>grouped_mm hook<br/>hifloat8_grouped_mm"]
    D --> K["TorchNPU / CANN<br/>HiFloat8 GEMMs"]
    M --> K

    classDef framework fill:#f1f5f9,stroke:#64748b,color:#172337
    classDef ao fill:#e8f3fb,stroke:#4b7da6,color:#17344d
    classDef native fill:#edf5ed,stroke:#648568,color:#25452a
    class A framework
    class Q,D,M ao
    class K native

Dense. AO's registered handler converts selected nn.Linear modules in place. HiFloat8Linear calls hifloat8_linear; its autograd implementation quantizes the operands and computes forward, input gradients and weight gradients. Converted modules keep their Parameter objects, hooks, names, mode and state-dict keys.

MoE grouped. DeepSpeed keeps its GroupedExperts container. Engine selects AO's HiFloat8GroupedConfig; AO's registered handler binds hifloat8_grouped_mm through the module's existing grouped_mm slot. The handler accepts this explicit hook contract and imports no DeepSpeed class. Gate/up/down calls keep native [E,N,K] parameters with trans_b=True; activation, routing/padding and communication remain in DeepSpeed. Cumulative offsets include empty experts; FWD/dX use group_type=0, and dW uses group_type=2.

HiFloat8GroupedConfig and HiFloat8LinearConfig are colocated with their common numerical base in AO's config.py. There is no nested config=policy wrapper. Each module kind reuses an immutable recipe parsed from the same numerical settings; distinct config types select distinct registered handlers. Engine builds one ModuleFqnToConfig map and calls quantize_ once. See the engine, AO handler/config implementation and expert execution.

The NPU resolver lives in accelerator/npu/hifloat8.py and lazily returns the public AO module after dependency/API checks. Ordinary BF16/FP16 grouped GEMM is separate: get_grouped_mm() resolves deepspeed/ops/npu/grouped_mm.py, which uses TorchNPU without requiring AO. Accelerator code contains capability lookup; operator implementations live under ops or in AO.

Numerical and storage contract

One numerical schema in HiFloat8Config controls Dense and grouped GEMMs. The typed recipes inherit its fields and validation; they have equal numerical settings rather than shared object identity across different config types. AO parses defaults and overrides through HiFloat8Config.from_dict(); DeepSpeed does not duplicate numerical validation. The default input/weight/gradient scale denominators are 15/15/224, with per-tensor scaling.

compute_dtype selects BF16/FP16 staging before quantization and GEMM result types. GEMM operands are still HiFloat8-tagged payloads; accumulation precision is kernel-owned. Converted module outputs match the caller's dtype, and parameters/gradients retain their high-precision types. Checkpoints retain the original high-precision weight names; reconstruct the same policy when resuming.

The grouped path quantizes contiguous expert storage and transposes the 8-bit payload view, avoiding a BF16 weight-layout materialization. With trans_b=True, dW is produced directly in parameter storage layout. Dense reuses saved payloads/scales for backward. Grouped weights are still quantized in forward and again for dX; persistent caching is not implemented.

Quick start

Use the paired source revisions listed below with torchao>=0.18,<0.19, compatible Torch/TorchNPU and CANN, and the Ascend extension installed with automatic activation enabled. No explicit import torchao_npu or manual model conversion is needed.

For an existing Qwen3.5 text-only training script, save this as ds_hifloat8.json:

{
  "train_micro_batch_size_per_gpu": 1,
  "gradient_accumulation_steps": 1,
  "bf16": {"enabled": true},
  "zero_optimization": {"stage": 2},
  "optimizer": {
    "type": "AdamW",
    "params": {"lr": 0.00001, "weight_decay": 0.0}
  },
  "expert_parallel": {
    "enabled": true,
    "autoep_size": 4,
    "preset_model": "qwen3_5_moe"
  },
  "hifloat8": {
    "enabled": true,
    "backend": "torchao",
    "module_name_patterns": ["*.experts", "*.shared_experts.*_proj"],
    "min_numel": 65536
  }
}

Pass it to the normal DeepSpeed initialization in that script:

import deepspeed

# model is the loaded model; the script owns data and trainable-parameter selection.
engine, optimizer, _, _ = deepspeed.initialize(
    model=model,
    model_parameters=model.parameters(),
    config="ds_hifloat8.json",
)

Launch four ranks in the configured NPU environment, for example DS_ACCELERATOR=npu torchrun --nproc_per_node=4 train.py, where train.py is the script above with the usual model, data and training loop. Device visibility and HCCL setup depend on the machine. This example enables low precision; it does not reproduce the historical partial-parameter benchmark by itself.

For a Dense-only model, omit expert_parallel and replace the module patterns with the actual Linear names, such as ["*.mlp.*_proj"]. For MoE, patterns are evaluated after AutoEP replacement. Every pattern must match an eligible module; optional expected_module_count checks the total selected count. Trainable-parameter selection remains independent of low-precision selection.

Omitting hifloat8.config uses AO's shared defaults. Set hifloat8.enabled=false to return to ordinary high-precision execution. The legacy backend value "torchao_npu" is accepted as an alias for "torchao"; the temporary top-level low_precision section is rejected. The current configuration supersedes the earlier generic-provider proposal in this discussion.

2026-10-19 update: AO-owned grouped configuration and handler

Current sources: DeepSpeed 95dd780c, AO e0d59bd (MR31), Swift 3e9994baf.

AO now registers HiFloat8GroupedConfig alongside the Linear workflow. Both recipes use the common numerical base and inherited parsing/validation. DeepSpeed's grouped config/handler file is removed; Engine only selects configurations and invokes the public quantize_ entry point. The provider no longer requires the raw grouped function. No changes to upstream TorchAO's registry or default filter are needed: FQN selection chooses the modules, then configuration type chooses the handler. A plain grouped module was validated without importing DeepSpeed.

  • AO HiFloat8/namespace suites: 71 passed, 1 empty-Dense native-contract skip. DeepSpeed focused suites: 342 passed, 32 CUDA-only skips, including CPU reference cases.
  • A fresh process imports torch and public torchao APIs, converts a Linear and a plain grouped module together, and runs native forward/backward. There is no explicit torchao_npu import and no DeepSpeed module loaded. The grouped configuration derives from HiFloat8Config.
  • Actual AutoEP EP2/ZeRO-2: paired 30-step runs plus a reverse-order 100-step pair in each precision, BF16 and HiFloat8 separately. Inputs, losses, gradient norms and all 19 final tensors per rank are exact against the previous paired DS/AO sources. Two layers/four experts, hidden64/intermediate128, batch1/sequence16, seed42 and rank-dependent data seed123+rank, AdamW1e-3, same CPU affinity. This is a small actual AutoEP model, not a full Qwen convergence run.
  • NPU allocation peaks are identical before/after: 17,627,648 bytes initialization; 1,035,863,040 bytes training. Initial 30-step P50 changes were BF16 +14.57%, HiFloat8 +1.05%; the reverse-order 100-step changes were BF16 −0.50%, HiFloat8 +0.45%. Ordinary BF16 execution code is unchanged. The samples show timing sensitivity and do not establish a stable speedup or regression.
  • DP2/ZeRO-2/GAS2 checkpoint/resume retains exact subsequent losses, parameters and optimizer state. Typed Linear/grouped recipes have equal numerical fields; grouped modules reuse the same grouped recipe. Experts are replicated, so this is not AutoEP checkpoint proof.
  • Local CPU focused tests: 40 passed, 82 NPU-dependent skips. The first three reconstructed DeepSpeed commits were also tested independently: 199/6, 6/24 and 10/37 passed/skipped. Changed-file checks cover the full feature diff. Final trees match the validated source, with only a separately checked documentation wording correction after the initial native suites.

Existing histories were reorganized into four functional commits per repository with signed trailers and backups. The consolidated final trees retain the validated implementation; no new PR/MR was created.

Order DeepSpeed AO NPU
1 98caec79 fix(autoep): preserve Qwen3.5 routing and rank-local checkpoints 6b034fd fix: preserve NPU auto-activation during TorchAO discovery
2 9a87125d feat(npu): expose native grouped GEMM through accelerator capabilities ea917fd feat(ops): add differentiable native NPU grouped GEMM
3 b49b298f perf(autoep): generate large permutation indices on NPU a388ef3 feat(hifloat8): register Linear and grouped training workflows
4 95dd780c feat(hifloat8): integrate AO-owned quantize_ training handlers e0d59bd bench(hifloat8): separate timing, memory and kernel attribution

Reproduction: /data/dxq/hif8_a5_20260914/experiments/ao_grouped_handler_20261019_01, including the matched old/new DS+AO snapshots, run_all.sh, postchecks.sh, public-import probe and per-rank evidence. This validates the integration refactor on a small actual AutoEP model; the earlier full Qwen partial-training and historical performance records below retain their original scope and baselines.

2026-10-16 update: grouped GEMM selection in the handler

October 16 source revisions: DeepSpeed 6b91ff09, AO 9c6dfb4, Swift 967b47fee.

The engine now constructs GroupedExpertsConfig(policy). The existing handler resolves the accelerator's public HiFloat8 provider and binds its grouped GEMM. Linear and experts still share one quantize_ call. Engine-wide preflight remains before any conversion; there is no new conversion wrapper, registry or configuration field. Ordinary BF16 grouped and AO's numerical kernels are unchanged. The paired AO/Swift commits clarify documentation only.

  • Four focused suites on Ascend950PR: 341 passed, 32 CUDA-only skips, including CPU reference cases. Covers the real public quantize_ entry point, policy-only grouped conversion, shared policy identity, unsupported capability failure before mutation, native forward/backward, empty/padded experts and BF16 residuals with FP16 working GEMMs.
  • Local CPU focused suites: 40 passed, 81 NPU-dependent skips. Changed-file pre-commit passed in DeepSpeed and Swift; documentation snippets and whitespace checks passed.
  • Real AutoEP EP2/ZeRO-2, two layers/four experts, hidden size 64/intermediate size 128, batch 1/sequence length 16, seed 42, rank-dependent inputs seeded 123+rank, AdamW at 1e-3: BF16 and HiFloat8 separately, 30 matched baseline/candidate steps. Both ranks have exact input hashes, loss/gradient-norm traces and all 19 final parameter tensors.
  • The same matched runs have identical NPU initialization/training allocation peaks: 17,627,648 / 1,035,863,040 bytes. Excluding five warmup steps, maximum-rank step P50 is BF16 20.3156 → 20.3308 ms (+0.075%), HiFloat8 24.3285 → 24.2211 ms (−0.441%). These are before/after-refactor comparisons within each precision on the small model, with identical CPU affinity; they do not establish a speedup or a BF16-versus-HiFloat8 training result.
  • DP2/ZeRO-2/GAS2: checkpoint at optimizer step 2, resume through step 4; subsequent losses, parameters and optimizer state are exact, and policy identity is retained on both ranks. Experts are replicated here; this does not establish AutoEP checkpoint recovery.
  • Tested source files were hashed before and after execution: 1,216 paths per DeepSpeed snapshot and 31 AO paths; the candidate matches the committed source. Used the original Conda/CANN/driver through read-only mounts on cards 0/7, avoiding the high-memory workloads on cards 5/6. All experiment jobs completed normally.

The EP2 evidence uses a small actual AutoEP model, not the full Qwen3.5 model. It validates this initialization change against DS e9e32025. Reproduction record: /data/dxq/hif8_a5_20260914/experiments/grouped_handler_20261016_01 (run_all.sh, source manifests, rank tables, exact configs, per-rank results and comparison.json).

2026-10-15 update: public TorchAO entry point and device separation

October 15 source revisions after the documentation sync: DeepSpeed e9e32025, AO 19e33b0, Swift 00c4aa2ed. These documentation-only commits retain the runtime code validated at DS 7b11cd53, AO 3a162ec and Swift 421625ef; the measurements below were not rerun for the documentation update.

  • Dense and GroupedExperts now use one public quantize_ call. AO owns the shared numerical policy; DeepSpeed retains a small adapter for its expert container.
  • The accelerator returns capabilities. The NPU resolver is accelerator/npu/hifloat8.py; ordinary BF16/FP16 grouped GEMM lives in deepspeed/ops/npu/grouped_mm.py. The October 8 placement of that high-precision operator in AO is historical.
  • Removed the intermediate provider class, conversion forwarding API and generic low_precision configuration. Engine code uses public TorchAO APIs without NPU imports.
  • Qwen3.5 text-wrapper compatibility and NPU permutation index generation use existing AutoEP extension points and introduce no extra HiFloat8 configuration.

Validation of the current layout on A5: 340 focused tests passed, with 32 CUDA-only skips; the suite also includes CPU reference cases. Local CPU checks passed 249 tests with 123 hardware/optional skips. Native BF16 GroupedExperts forward/backward also passed with both AO namespaces unavailable. DP2/ZeRO-2/GAS2 checkpoint/resume matched subsequent losses, parameters and optimizer state exactly; experts are replicated in that test.

For actual AutoEP EP2/ZeRO-2, matched 30-step runs before/after the file relocation had identical inputs, loss/gradient-norm curves and final parameters in BF16 and HiFloat8 separately. A 100-step HiFloat8 pair with fixed CPU affinity also matched exactly and used the same peak allocation; P50 was 8.196 → 8.233 ms (+0.46%). These are refactor checks on a small model, not a BF16-versus-HiFloat8 performance comparison. The earlier Qwen3.5 EP4 integration passed its matched 30-step checks; it was not rerun for the byte-identical file relocation.

Compute measurements and memory

The retained experiments answer different questions. The following results are historical measurements reviewed on October 15, not a new benchmark of the latest PR.

Experiment and comparison Baseline → candidate Result
Sep 15, routed expert GEMM device-task time, BF16 → HiFloat8 46.759 → 25.513 ms 45.44% lower
Sep 15, shared-expert Dense GEMM device-task time, BF16 → HiFloat8 3.078 → 2.729 ms 11.34% lower
Oct 8, isolated trainable grouped operator FWD+backward, previous HiFloat8 → packed-layout HiFloat8 1.075 → 0.729 ms 32.20% lower
Same Oct 8 operator benchmark, peak NPU allocated memory 422.001 → 363.003 MiB 13.98% lower; 59.0 MiB saved
Sep 28–29, 500-step training, BF16 → HiFloat8, steady-state step P50 0.801581 → 0.849000 s 5.92% slower
Same 500-step training, maximum-rank peak NPU allocation 32.194 → 31.953 GiB 0.75% lower

Measurement scope:

  • Sep 15 native profile: one warmup step and two active steps, averaging device GEMM task sums over complete ranks 0–2; incomplete rank 3 is excluded. Quantization, layout, activation, communication and launch costs are outside these GEMM totals. Routed gains are mainly FWD/dX; routed dW was 0.14% slower. This used the older Torch/TorchNPU 2.9 helper path (DeepSpeed 89fe70ef, Swift c10a9736, TorchNPU 36ab0b99), so it is evidence for the native compute opportunity, not a measurement of the current AO integration.
  • Oct 8 operator benchmark: E=64, M=2048, K=2048, N=512, trainable weights, three interleaved pairs, 100 timed iterations after 10 warmups per run; median of run P50s. AO 9521053 → 256090d, Torch/TorchNPU 2.11. Memory is the benchmark's peak allocated memory, not an isolated quantized-payload count. This 14% memory reduction compares two HiFloat8 implementations, not HiFloat8 with BF16. The benchmark is available as benchmarks/profile_hifloat8.py; the packed candidate uses --trans-b.
  • 500-step training: Qwen3.5-35B-A3B, four Ascend950PR devices, EP4/ZeRO-2, batch 1/rank, accumulation 1, sequence length ≤256. All 40 layers execute; only layer 0/39 routed/shared expert parameters train (12 tensors/rank). Steady-state timing uses steps 11–500 and the slowest rank per step. DeepSpeed 8ab23b4d, AO runtime ac61a4f (published a62af9b, identical tree), Torch/TorchNPU 2.11. Across all 500 steps, loss Pearson correlation was 0.999507 and rank-0 gradient-norm correlation 0.997368. Inputs and initial trainable weights matched. There is one long run per precision; this is not full-parameter convergence evidence.

Why the end-to-end run is still slower. In that 500-step pair, the step-internal interval already contains about 47.25 ms of the 47.42 ms P50 gap; the mean between-step gap differs by only 0.045 ms on rank 0. The internal interval includes quantization, routing, communication, backward and optimizer work, not just GEMM.

The older paired profile shows where extra device work appears: HiFloat8 adds 104.59 ms of quantization tasks, and transpose tasks increase from 23.47 to 99.21 ms, while Dense plus grouped GEMMs save 21.60 ms. These are sums over two profiled steps, averaged across ranks, not wall-clock components. They identify quantization/layout overhead as optimization targets, but cannot quantitatively explain the 5.92% gap on a different software version. BF16 master weights, optimizer/gradient state and communication also remain, limiting whole-model memory savings. A new matched profile is needed to attribute the current branch's end-to-end cost.

Model and compatibility scope

Scope Status
Dense Linear and AutoEP GroupedExperts, BF16 parameters, BF16/FP16 working precision Native forward/backward and public quantize_ tests
ZeRO stages 0–2 Accepted; distributed lifecycle checks include DP2/ZeRO-2
Actual AutoEP EP2 Current-layout checks described above
Qwen3.5-35B-A3B text-only EP4/ZeRO-2 Earlier paired partial-parameter validation; no full-parameter convergence claim
Ordinary BF16/FP16 grouped training on NPU Independent of AO
Other Dense/MoE families Require model-level validation
HiFloat8 with ZeRO-3, PipelineModule, AutoTP, custom MPU, explicit DeepSpeed MoE or fused gate/up override Rejected
TorchAO quantized checkpoint ingestion, AutoEP checkpoint/resume, full-parameter convergence, LoRA, offload/compile, EP8, multi-node, CUDA low-precision validation Not established by this integration

Earlier experiment records

These records retain their original revision pairs and APIs. They document earlier experiments; use the October 15 architecture, quick start and source revisions above for the current implementation.

October 8–9 prototype results and configuration history

Initial A5 validation report

Environment: Ascend950PR, 128 GiB HBM/device; CANN 9.1.0; driver 25.7.rc1; Python 3.11.15; PyTorch 2.11.0 CPU wheel with TorchNPU 2.11.0; torchao 0.18.0; ms-swift 4.6.0.dev0. Exact fork revisions are linked below.

Functional/numerical gates:

  • AO: 32 passed; policy/conversion commit separately passed 31. Coverage: custom ranges/dtypes, BF16 references, weight-version guards, Parameter/mode preservation, saved-tensor hooks and repeated backward.
  • DeepSpeed NPU: 83 passed, 26 legacy-helper skips. CPU/import/selection: 47 passed, 109 device/dependency skips. Changed-file pre-commit passed.
  • DP2 / ZeRO-2 / accumulation 2: checkpoint at optimizer step 2, resume through step 4; subsequent losses, BF16 parameters and optimizer state were exact on both ranks. Experts are replicated in this lifecycle test; AutoEP checkpoint parity is a separate gate.
Operator measurements

Baseline and candidate both use the existing 15/15/224 HiFloat8 recipe. Three interleaved repetitions, 100 timed FWD+backward iterations after 10 warmups; median of run P50s. M=2048, K=2048, N=512, E=64; Dense weight [512,2048].

Path Baseline → candidate Latency change
Dense Linear 0.186 → 0.154 ms −17.3%
Grouped, DeepSpeed weight layout, trainable weights 1.360 → 1.061 ms −21.9%
Grouped, same layout, frozen weights with dX 0.868 → 0.557 ms −35.8%

Frozen-weight peak allocation decreased 121 MiB; other operator peaks were unchanged. Original weight preparation: approximately 292 µs transpose + 199 µs quantization, versus 57 µs FWD GEMM. The candidate removes the separate transpose kernel. Diagnostic kernel durations are distinct from wall time.

Model measurements

Qwen3.5-35B-A3B: EP2, ZeRO-2, BF16 communication, batch 1/rank, accumulation 1, sequence length ≤256, eager attention, no gradient checkpointing; seeds 42; AdamW, LR 1e-5, cosine schedule, no warmup/weight decay, clipping 1.

Train layers 0 and 39 routed/shared-expert parameters: 12 tensors/rank; all 40 MoE layers execute. Each run has 20 steps, excluding five warmups.

Three matched pairs of the final revision gave 725 → 684 ms end-to-end step P50 (−5.7%), using the median of run P50s and the slowest rank at each step. Individual changes: −5.54%, −6.01%, −5.74%. An earlier prototype pair measured −4.4%.

Both ranks matched inputs, losses, gradient norms and all 12 final BF16 tensors exactly. Peak allocation remained 51.21 GiB/rank. This short partial-parameter experiment, with other devices active, does not establish convergence or multi-node performance.

2026-10-08 update: sole AO ownership and packed dW

Implemented and pushed:

  • Native _NPUGroupedMatmul autograd moved from DeepSpeed to torchao_npu.ops.npu.grouped_mm (BF16/FP16).
  • HiFloat8 is now owned exclusively by AO. DeepSpeed defaults to backend="torchao_npu"; the old helper backend is rejected with a migration message. DeepSpeed keeps selection, routing/padding and distributed lifecycle checks.
  • trans_b=True accepts native [E,N,K] parameters and produces dW directly in that layout; empty-rank gradients also live in AO.

Validation: 70 AO and 87 DeepSpeed NPU tests passed. DP2/ZeRO-2/GAS2 checkpoint parity is exact. Qwen3.5 EP2 has two matched 30-step pairs; EP4 has one BF16 and three interleaved HiFloat8 50-step pairs. Every rank matches input/loss/gradient-norm traces and all 12 final trainable BF16 tensors exactly, using the same partial-training scope documented above.

Comparison against the previous prototype Result
Trainable grouped GEMM, same benchmark dimensions 1.075 → 0.729 ms; −32.2%, peak allocation −59 MiB
EP2 HiFloat8 Step P50 −1.6% across two pairs
EP4 BF16 Step P50 −0.33%; peak allocation −482 MiB/rank
EP4 HiFloat8 Step P50 +0.39% across three pairs; peak allocation −116.5 MiB/rank

The independent gradient-transpose kernel disappeared from the diagnostic trace. No additional model throughput improvement is established by the EP4 sample: most experts are frozen in this experiment, so the dW optimization affects a small part of the model. Weight quantization and routing synchronization remain.

AO implementation: 256090dee33a10ec277d60b0629b86b763b92c5d.
DeepSpeed implementation.
Baseline: AO 9521053, DeepSpeed 48af66b. Use benchmarks/profile_hifloat8.py --trans-b for the native-storage cases. The preceding initial-prototype numbers use a different revision pair and should be interpreted separately.

2026-10-09 update: minimal configuration and precision contract

Recommended BF16/ZeRO-2 configuration (AutoEP selection/topology is configured separately):

{
  "bf16": {"enabled": true},
  "zero_optimization": {"stage": 2},
  "hifloat8": {
    "enabled": true,
    "backend": "torchao_npu",
    "module_name_patterns": ["*.experts", "*.shared_experts.*_proj"],
    "min_numel": 65536
  }
}

AO provides the established 15/15/224 per-tensor recipe. Missing/null/empty config and the old full JSON remain compatible; optional overrides remain available. These values originated in the PyTorchA training recipe and influence scale/payloads. They are distinct from the native quantizer default. Grouped keyword defaults now derive from the common policy; no GEMM, routing or CUDA/BF16 implementation changed.

compute_dtype is retained: renaming it to output_dtype would omit its pre-quantization cast semantics. Native tests record and call the real operators, confirming HiFloat8-tagged inputs in all three FWD/dX/dW GEMMs for null/BF16/FP16 working precision. BF16 and HiFloat8 grouped paths already share shape/device/offset/layout validation; the existing small DeepSpeed adapter needs no additional abstraction.

Validation: 85 AO tests passed (one empty-Dense native-quantizer skip), 90 DeepSpeed NPU tests passed. BF16-reference numerical gates, empty/uneven experts, both weight layouts, BF16 default-vs-explicit exact output/gradient equality and populated AdamW-state identity passed. DP2/ZeRO-2/GAS2 checkpoint parity remains exact with replicated experts.

Qwen3.5 EP4/ZeRO-2: two interleaved 30-step pairs compare the prior source/full JSON against the new source/minimal JSON, using the same partial-training scope above. All ranks match inputs, losses, gradient norms and final trainable BF16 tensors exactly; native call counts and peak NPU allocation are unchanged (31.19 GiB/rank).

Step P50s: 722.6 → 779.4 ms (+7.85%) and 773.6 → 773.4 ms (−0.01%); median of run P50s is +3.79%. These measurements include identical validation hooks. No speedup or stable regression is established. A third sample was initially blocked by a busy device; its retry failed in a baseline HCCL barrier before DeepSpeed/AO initialization, so it is excluded. Three operator repetitions showed approximately −0.1% to −1.9% differences with unchanged allocation, also insufficient to attribute a new speed gain. Existing repeated grouped weight quantization remains.

Current revisions: AO repository, 397d0f24537923ce3ed904714117073ff4bee537 (runtime change 114acb2; subsequent documentation-only provenance correction); DeepSpeed 2623227b. Rollback: AO c7a82e2, DeepSpeed 0da46635.

Historical source revisions
  • DeepSpeed Draft PR #8784: source hazelduan/DeepSpeed:deepspeed_ao, tested revision 2623227bb9285555040845c2a339a027c3d25218. Initial prototype 48af66b183d0fe6d60129f1714ffbf15d4e0d7c3, baseline c4b9ee883a5492afce1039b060821fce81f470b9.
  • torchao_npu Draft MR !31: source hazeldxq/torchao_npu:deepspeed_ao, revision 397d0f24537923ce3ed904714117073ff4bee537 (tested runtime 114acb2; subsequent documentation-only correction). Earlier policy/conversion ab249d330173e8ae4c8a0f6842c987381e5ca1c7, optimization 95210535e4b63d68ac78374aa7e1d5bda4616206, baseline e51455174188d0327f04283df9de4742b214a973.
  • ms-swift branch comparison: source hazelduan/ms-swift:deepspeed_ao; tested revision 46b8711.
  • Model run data: 400 text examples; SHA-256 769882e1d8e43e249847f1aaa6eb72aa13f6eebdeb850975b9ecc61360922252. Model revision was a local snapshot; it was not independently pinned to a Hub revision.

Upstream proposal and remaining work

  1. Review the current split: optional accelerator capabilities, public TorchAO quantize_, AO-owned numerical policy, and a small DeepSpeed adapter for GroupedExperts.
  2. Reduce repeated grouped weight quantization and remaining layout costs. Any cache needs an explicit parameter-update/invalidation and memory contract.
  3. Extend beyond partial-parameter training: full-model precision/convergence, AutoEP checkpoint/resume, then offload/compile and multi-node validation. Quantized checkpoint ingestion into ZeRO-3 remains outside the implemented path.
  4. Add other hardware/formats through TorchAO as concrete implementations become available; retain device-specific numerical and performance gates.

Source and reproduction

  • DeepSpeed draft PR #8784, source hazelduan/DeepSpeed:deepspeed_ao: 95dd780ce4e2f534b484610f273d3ef21c505baf.
  • torchao_npu draft MR !31, source hazeldxq/torchao_npu:deepspeed_ao: e0d59bdfcc17721fb13e3cc4b6c949391d68aa7d.
  • ms-swift branch comparison, paired revision 3e9994baf135f939dffefc9ad4773bae35e2b5b9.
  • Current HiFloat8 tutorial and AutoEP configuration.
  • Current validation environment: Ascend950PR, 128 GiB HBM/device; CANN 9.1.0; driver 25.7.rc1; Python 3.11.15; PyTorch 2.11.0 CPU wheel with TorchNPU 2.11.0; TorchAO 0.18.0. Older performance experiments use the versions explicitly listed with each result.
  • Historical model data: 400 text examples, SHA-256 769882e1d8e43e249847f1aaa6eb72aa13f6eebdeb850975b9ecc61360922252. The model was a local snapshot, not independently pinned to a Hub revision.
Focused reproduction commands

Install the paired source revisions in a compatible NPU environment and source CANN. Use idle devices with the matching device visibility and HCCL configuration.

# AO: current operator measurement and native numerical tests.
python benchmarks/profile_hifloat8.py --iterations 100 --warmup 10 \
  --trans-b --profile --output /tmp/hif8-profile/results.json
python benchmarks/summarize_hifloat8_profile.py /tmp/hif8-profile \
  --output /tmp/hif8-profile/stages.json
python -m pytest test/test_hifloat8_linear_npu.py \
  test/test_hifloat8_grouped_npu.py test/test_hifloat8_config_npu.py -q

# DeepSpeed: two-rank lifecycle check with replicated experts.
DS_ACCELERATOR=npu torchrun --nproc_per_node=2 \
  tests/unit/runtime/hifloat8_resume_validation.py --output /tmp/hif8-resume

The benchmark records uninstrumented timing before its diagnostic profile. These commands exercise the current sources; reproducing a historical before/after number requires the corresponding revision pair and measurement settings above.

主要言語
Python
スター
43.3k
フォーク
5.1k
平均マージ
5日 10時間
マージ済み PR(30日)
85

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

deepspeedai/DeepSpeed のほかの issue

deepspeedai/DeepSpeed の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。