[Offloading] Cannot save disk-offloaded `Qwen/Qwen3-30B-A3B`
Author: kylesayrs
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 5.13.0.dev0
- Platform: Linux-5.14.0-611.41.1.el9_7.x86_64-x86_64-with-glibc2.34
- Python version: 3.12.12
- Huggingface_hub version: 1.18.0
- Safetensors version: 0.8.0
- Accelerate version: 1.15.0.dev0
- Accelerate config:    not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.12.0+cu130 (CUDA)
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: NVIDIA A100-SXM4-80GB

### Who can help?

@Cyrilvallez @SunMarc 

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [x] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

```python3
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen3-30B-A3B",
    device_map="auto",
    max_memory={},
    offload_folder="/mnt/nvme-data/engine/kylesayrs/offload_folder",
)
model.save_pretrained("save_path")
```

```
Some parameters are on the meta device because they were offloaded to the disk.
Writing model shards:   0%|                                                                      | 0/248 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/home/kylesayrs/llm-compressor/disk_save_repro.py", line 12, in <module>
    model.save_pretrained(SAVE_DIR)
  File "/home/kylesayrs/transformers/src/transformers/modeling_utils.py", line 3680, in save_pretrained
    safe_save_file(shard_state_dict, filename, metadata=metadata)
  File "/home/kylesayrs/llm-compressor/env/lib64/python3.12/site-packages/safetensors/torch.py", line 324, in save_file  
    _flatten_as_ptr(tensors, keep_references_alive), filename, metadata=metadata
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kylesayrs/llm-compressor/env/lib64/python3.12/site-packages/safetensors/torch.py", line 582, in _flatten_as_
ptr
    arr, tensor_ref = _to_ndarray(v)
                      ^^^^^^^^^^^^^^
  File "/home/kylesayrs/llm-compressor/env/lib64/python3.12/site-packages/safetensors/torch.py", line 479, in _to_ndarray
    tensor = tensor.to("cpu")
             ^^^^^^^^^^^^^^^^
NotImplementedError: Cannot copy out of meta tensor; no data!
```

### Expected behavior

Model should save properly. Issue does not occur when using https://github.com/huggingface/transformers/pull/46902

Comments:
I believe this may be related to https://github.com/huggingface/transformers/pull/47018#discussion_r3514034927

When I patch with the above suggestion, I run into this issue
```
Some parameters are on the meta device because they were offloaded to the disk.
/home/kylesayrs/transformers/src/transformers/modeling_utils.py:3566: UserWarning: Attempting to save a model with offloaded modules. Ensure that unallocated cpu memory exceeds the `shard_size` (50GB default)
  warnings.warn(
Writing model shards:   0%|                                                                       | 0/12 [00:02<?, ?it/s]
Traceback (most recent call last):
  File "/home/kylesayrs/transformers/src/transformers/modeling_utils.py", line 3667, in save_pretrained
    weight_map.update({k: os.path.basename(shard_file)} for k in shard_state_dict.keys())  # ty: ignore[unresolved-attribute]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: dictionary update sequence element #0 has length 1; 2 is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kylesayrs/llm-compressor/disk_save_repro.py", line 13, in <module>
    model.save_pretrained("tmp_save_path")
  File "/home/kylesayrs/transformers/src/transformers/modeling_utils.py", line 3669, in save_pretrained
    raise RuntimeError(
RuntimeError: We could not revert some weight conversions because of offlading, and several weights needed for a single conversion operation living in different shard files. Try reducing `max_shard_size` a bit, or worst case set `save_original_format=False`.
```

Hi @kylesayrs ! I took a look at the second traceback you posted. The ValueError during the save operation is caused by a syntax typo in modeling_utils.py at line 3667. The update() method is being passed a generator yielding dictionaries instead of a dictionary comprehension.

I can open a quick PR to fix this Python syntax issue so the team can get past this hurdle and properly debug the underlying offloading/meta-tensor issue. I will link the PR shortly

@ajayraj30002 Thanks for opening the PR! The one I opened also has the change needed to fix disk saving e2e, but I'm glad we both arrived at the same conclusion!

@kylesayrs  I'm happy to see the issue is fixed.  Thanks for the update!