pytorch - ✅(Solved) Fix torch.distributed.checkpoint.save() return value is missing `storage_meta` [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#177887Fetched 2026-04-08 01:03:06
View on GitHub
Comments
1
Participants
2
Timeline
42
Reactions
0
Author
Participants
Timeline (top)
mentioned ×14subscribed ×14referenced ×7labeled ×3

Error Message

writer.checkpoint_id: /tmp/tmpmo7cr95j meta.storage_meta: None Traceback (most recent call last): File "/storage/home/jgehring/projs/amaia2/test_storage_meta_regression.py", line 23, in <module> assert meta.storage_meta is not None ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError

Root Cause

In 2.10, the metadata returned by torch.distributed.checkpoint.save() contains None for storage_meta. Presumably, the reason is that FileSystemWriter.finish() switched to using dataclass.replace() when modifying the metadata object it is passed; however, the call site (_save_state_dict()) seems to expect finish() to perform an in-place modification of metadata. Repro script:

Fix Action

Fix / Workaround

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 128 On-line CPU(s) list: 0-127 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Platinum 8462Y+ CPU family: 6 Model: 143 Thread(s) per core: 2 Core(s) per socket: 32 Socket(s): 2 Stepping: 8 CPU max MHz: 4100.0000 CPU min MHz: 800.0000 BogoMIPS: 5600.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect user_shstk avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hfi vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr ibt amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 3 MiB (64 instances) L1i cache: 2 MiB (64 instances) L2 cache: 128 MiB (64 instances) L3 cache: 120 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126 NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

PR fix notes

PR #178001: [dcp][oss] Fix Metadata.storage_meta regression from dataclasses.replace() (#178001)

Description (problem / solution / changelog)

Summary:

_FileSystemWriter.finish() used dataclasses.replace(metadata, version=CURRENT_DCP_VERSION) which creates a new Metadata object and rebinds the local variable. Since finish() returns None, the caller (_save_state_dict) still holds the original object, which never gets storage_meta, storage_data, or version updated. The on-disk metadata is correct (the new copy is pickled), but the in-memory Metadata returned by dcp.save() has None for these fields.

Fix by mutating the passed-in metadata in-place (metadata.version = CURRENT_DCP_VERSION) instead of creating a new copy. Metadata is not a frozen dataclass, so in-place mutation is safe and consistent with the subsequent storage_data and storage_meta assignments.

Fixes https://github.com/pytorch/pytorch/issues/177887

Test Plan:

import tempfile
import torch
import torch.distributed.checkpoint as dcp
from torch.distributed.checkpoint._fsspec_filesystem import FsspecWriter

state_dict = {"weight": torch.randn(4, 4)}

with tempfile.TemporaryDirectory() as tmpdir:
    writer = FsspecWriter(tmpdir)
    meta = dcp.save(state_dict, storage_writer=writer, no_dist=True)
    assert meta.storage_meta is not None
    assert meta.storage_data is not None
    assert meta.version is not None
    print(f"storage_meta: {meta.storage_meta}")
    print(f"version: {meta.version}")

Before the fix, meta.storage_meta is None. After the fix, it contains the expected StorageMeta with checkpoint_id and save_id.

Differential Revision: D97535692

Changed files

  • torch/distributed/checkpoint/filesystem.py (modified, +1/-1)

Code Example

import tempfile

import torch
import torch.distributed.checkpoint as dcp
from torch.distributed.checkpoint._fsspec_filesystem import FsspecWriter

state_dict = {"weight": torch.randn(4, 4)}

with tempfile.TemporaryDirectory() as tmpdir:
    writer = FsspecWriter(tmpdir)
    meta = dcp.save(state_dict, storage_writer=writer, no_dist=True)

    print(f"writer.checkpoint_id: {writer.checkpoint_id}")
    print(f"meta.storage_meta:    {meta.storage_meta}")

    assert meta.storage_meta is not None

---

writer.checkpoint_id: /tmp/tmp3kdjvi21
meta.storage_meta:    StorageMeta(checkpoint_id='/tmp/tmp3kdjvi21', save_id='837f6559-c8d2-48b8-91e0-8a70c05303e2', load_id=None, modules=[])

---

writer.checkpoint_id: /tmp/tmpmo7cr95j
meta.storage_meta:    None
Traceback (most recent call last):
  File "/storage/home/jgehring/projs/amaia2/test_storage_meta_regression.py", line 23, in <module>
    assert meta.storage_meta is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

In 2.10, the metadata returned by torch.distributed.checkpoint.save() contains None for storage_meta. Presumably, the reason is that FileSystemWriter.finish() switched to using dataclass.replace() when modifying the metadata object it is passed; however, the call site (_save_state_dict()) seems to expect finish() to perform an in-place modification of metadata. Repro script:

import tempfile

import torch
import torch.distributed.checkpoint as dcp
from torch.distributed.checkpoint._fsspec_filesystem import FsspecWriter

state_dict = {"weight": torch.randn(4, 4)}

with tempfile.TemporaryDirectory() as tmpdir:
    writer = FsspecWriter(tmpdir)
    meta = dcp.save(state_dict, storage_writer=writer, no_dist=True)

    print(f"writer.checkpoint_id: {writer.checkpoint_id}")
    print(f"meta.storage_meta:    {meta.storage_meta}")

    assert meta.storage_meta is not None

Output with 2.8:

writer.checkpoint_id: /tmp/tmp3kdjvi21
meta.storage_meta:    StorageMeta(checkpoint_id='/tmp/tmp3kdjvi21', save_id='837f6559-c8d2-48b8-91e0-8a70c05303e2', load_id=None, modules=[])

Output with 2.10:

writer.checkpoint_id: /tmp/tmpmo7cr95j
meta.storage_meta:    None
Traceback (most recent call last):
  File "/storage/home/jgehring/projs/amaia2/test_storage_meta_regression.py", line 23, in <module>
    assert meta.storage_meta is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

Versions

Collecting environment information... PyTorch version: 2.10.0+cu128 Is debug build: False CUDA used to build PyTorch: 12.8 ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64) GCC version: (conda-forge gcc 13.4.0-18) 13.4.0 Clang version: Could not collect CMake version: version 3.28.2 Libc version: glibc-2.35

Python version: 3.11.15 | packaged by conda-forge | (main, Mar 5 2026, 16:45:40) [GCC 14.3.0] (64-bit runtime) Python platform: Linux-6.8.12-680-6063-coreweave-amd64-f81899c8-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: 12.9.86 CUDA_MODULE_LOADING set to: GPU models and configuration: GPU 0: NVIDIA H100 80GB HBM3 GPU 1: NVIDIA H100 80GB HBM3 GPU 2: NVIDIA H100 80GB HBM3 GPU 3: NVIDIA H100 80GB HBM3 GPU 4: NVIDIA H100 80GB HBM3 GPU 5: NVIDIA H100 80GB HBM3 GPU 6: NVIDIA H100 80GB HBM3 GPU 7: NVIDIA H100 80GB HBM3

Nvidia driver version: 580.95.05 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.9.8.0 /usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.8.0 /usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.8.0 /usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.8.0 /usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.8.0 /usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.8.0 /usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.8.0 /usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.8.0 Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True Caching allocator config: N/A

CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 128 On-line CPU(s) list: 0-127 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Platinum 8462Y+ CPU family: 6 Model: 143 Thread(s) per core: 2 Core(s) per socket: 32 Socket(s): 2 Stepping: 8 CPU max MHz: 4100.0000 CPU min MHz: 800.0000 BogoMIPS: 5600.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect user_shstk avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hfi vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr ibt amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 3 MiB (64 instances) L1i cache: 2 MiB (64 instances) L2 cache: 128 MiB (64 instances) L3 cache: 120 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114,116,118,120,122,124,126 NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] numpy==2.2.6 [pip3] nvidia-cublas-cu12==12.8.4.1 [pip3] nvidia-cuda-cupti-cu12==12.8.90 [pip3] nvidia-cuda-nvrtc-cu12==12.8.93 [pip3] nvidia-cuda-runtime-cu12==12.8.90 [pip3] nvidia-cudnn-cu12==9.10.2.21 [pip3] nvidia-cudnn-frontend==1.18.0 [pip3] nvidia-cufft-cu12==11.3.3.83 [pip3] nvidia-curand-cu12==10.3.9.90 [pip3] nvidia-cusolver-cu12==11.7.3.90 [pip3] nvidia-cusparse-cu12==12.5.8.93 [pip3] nvidia-cusparselt-cu12==0.7.1 [pip3] nvidia-nccl-cu12==2.27.5 [pip3] nvidia-nvjitlink-cu12==12.8.93 [pip3] nvidia-nvtx-cu12==12.8.90 [pip3] torch==2.10.0 [pip3] torch_c_dlpack_ext==0.1.5 [pip3] torchaudio==2.10.0 [pip3] torchdata==0.11.0 [pip3] torchvision==0.25.0 [pip3] triton==3.6.0 [conda] Could not collect

cc @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta @msaroufim @dcci @aditvenk @xmfan @LucasLLC @pradeepfn

extent analysis

Fix Plan

The issue arises from the FileSystemWriter.finish() method using dataclass.replace() instead of performing an in-place modification of the metadata object. To fix this, we need to modify the _save_state_dict() function to handle the new behavior of finish().

Here are the steps to fix the issue:

  • Modify the torch.distributed.checkpoint module to handle the new behavior of finish().
  • Update the _save_state_dict() function to correctly handle the metadata object returned by finish().

Code Changes

import torch
import torch.distributed.checkpoint as dcp
from torch.distributed.checkpoint._fsspec_filesystem import FsspecWriter

def _save_state_dict(state_dict, storage_writer, no_dist):
    # ... (rest of the function remains the same)
    metadata = storage_writer.finish()
    # Handle the new behavior of finish()
    if metadata is not None:
        storage_meta = metadata.storage_meta
    else:
        storage_meta = None
    # ... (rest of the function remains the same)

# Update the save function to use the new _save_state_dict function
def save(state_dict, storage_writer, no_dist):
    return _save_state_dict(state_dict, storage_writer, no_dist)

# Example usage:
state_dict = {"weight": torch.randn(4, 4)}

with tempfile.TemporaryDirectory() as tmpdir:
    writer = FsspecWriter(tmpdir)
    meta = save(state_dict, writer, no_dist=True)

    print(f"writer.checkpoint_id: {writer.checkpoint_id}")
    print(f"meta.storage_meta:    {meta.storage_meta}")

Verification

To verify that the fix worked, run the example usage code and check that meta.storage_meta is not None. The output should be similar to the output with PyTorch 2.8.

Extra Tips

  • Make sure to update the torch.distributed.checkpoint module to handle the new behavior of finish().
  • If you are using a custom storage_writer, ensure that it correctly handles the metadata object returned by finish().

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix torch.distributed.checkpoint.save() return value is missing `storage_meta` [1 pull requests, 1 comments, 2 participants]