Skip to content

FSDP2 calibration with hf_ptq.py [2/2]#2013

Draft
sugunav14 wants to merge 33 commits into
mainfrom
svelury/parallel-export
Draft

FSDP2 calibration with hf_ptq.py [2/2]#2013
sugunav14 wants to merge 33 commits into
mainfrom
svelury/parallel-export

Conversation

@sugunav14

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: ?

Usage

# Add a code snippet demonstrating how to use this

Testing

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅ / ❌ / N/A
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: ✅ / ❌ / N/A
  • Did you write any new necessary tests?: ✅ / ❌ / N/A
  • Did you update Changelog?: ✅ / ❌ / N/A
  • Did you get Claude approval on this PR?: ✅ / ❌ / N/A

Additional Information

sugunav14 added 30 commits July 19, 2026 18:24
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
…r param

Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
sugunav14 and others added 3 commits July 23, 2026 23:42
Distribute quantized weight-packing across FSDP2 ranks: each rank packs its
own Shard(0) row-slice in place via a meta-skeleton FSDPParam rebuild
(_rebuild_fsdp_param_from_shard) instead of every rank packing the full model.
MoE fused experts are packed keep-fused and split into per-expert deployment
keys at write time; scale buffers are re-wrapped as Shard(0) DTensors with
explicit global shape/stride so unshard round-trips on uneven splits.

The FSDP2 export gather is mode-aware (MODELOPT_DISABLE_SHARD_LOCAL escape
hatch) with EXPORT_PHASE_TIMING markers for prep/pack/gather.

Supersedes the streaming Option A export path on this branch.

Validated on Qwen3-235B and NemotronH-120B: bit-exact vs the standard
device_map export at world=4 and world=8; packing 148.7s -> 88.4s (1.68x)
from 4 -> 8 ranks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Each FSDP2 rank writes its owned decoder-layer units concurrently instead of a
whole-model full_tensor gather + rank-0 save_pretrained. export_hf_checkpoint forks
to _parallel_write_hf_checkpoint (escape hatches MODELOPT_DISABLE_SHARD_LOCAL /
MODELOPT_DISABLE_PARALLEL_WRITE); _export_transformers_checkpoint gains a _pack_only
early-return so both paths share prep+pack. Per-unit gather (full_tensor) -> HF
split_torch_state_dict_into_shards writer -> gather_object index merge. Host memory
bounded to ~one chunk of world units; writes parallelize across ranks.

Validated: byte-exact vs single-writer reference on tiny Qwen3-MoE + NemotronH (w2)
and Qwen3-235B (w8, 146,361 keys); output HF-loadable (get_checkpoint_shard_files).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
Drop all os.environ-gated code from the shard-local + parallel-write path, leaving
the validated default behavior as the single path:
- EXPORT_PHASE_TIMING phase-timing markers (unified_export_hf)
- MODELOPT_DISABLE_SHARD_LOCAL escape hatch + its legacy get_model_state_dict
  full-pack gather branch (now dead) and _use_shard_local gate
- MODELOPT_DISABLE_PARALLEL_WRITE escape hatch on the export fork
- SHARD_LOCAL_DEBUG (_dbg) per-rank logging (core_utils)

FSDP2 distributed export now unconditionally uses shard-local pack + parallel write.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Suguna Velury <178320438+sugunav14@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4c288808-db00-4e39-b650-b2a9430d043d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch svelury/parallel-export

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

@sugunav14 sugunav14 changed the title Svelury/parallel export FSDP2 calibration with hf_ptq.py [2/2] Jul 24, 2026
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.

1 participant