[BUG] Byte-view parameter broadcasts fail for zero-dimensional parameters
Describe the bug
DeepSpeed reinterprets parameter storage as torch.uint8 before broadcasting so the original parameter bit pattern is preserved. For a valid zero-dimensional parameter such as nn.Parameter(torch.tensor(1.0)), PyTorch rejects a dtype-changing Tensor.view(dtype) on a 0-D tensor. Initialization raises before the broadcast runs:
RuntimeError: self.dim() cannot be 0 to view Float as Byte (different element sizes)To Reproduce
Run the following model on two distributed ranks. Initialize the scalar differently on each rank so the model broadcast is exercised:
import torch
import deepspeed
import deepspeed.comm as dist
from torch import nn
class ScalarModel(nn.Module):
def __init__(self):
super().__init__()
self.weight = nn.Parameter(torch.tensor(float(dist.get_rank() + 1)))
deepspeed.init_distributed()
engine, *_ = deepspeed.initialize(
model=ScalarModel(),
config={
"train_micro_batch_size_per_gpu": 1,
"zero_optimization": {"stage": 0},
},
)There is also a minimal PyTorch reproduction:
torch.tensor(1.0).view(torch.uint8)Reproduced on latest master
At commit d099bc61bb95bb71abaac3d3c1ba6911f15b2b95, a two-rank regression test failed for both ZeRO stage 0 and stage 3. Both cases reached DeepSpeedEngine._broadcast_model() and failed at p.data.view(torch.uint8) before initialization completed.
Expected behavior
Scalar parameters should be broadcast successfully as their original raw bytes, with every rank receiving the source rank's value and without changing the parameter's dtype or bit pattern.
Suggested fix direction
Centralize the raw-byte view in a helper that adds a dimension only for scalar tensors before reinterpreting the dtype, for example:
def view_as_uint8(tensor):
if tensor.ndim == 0:
tensor = tensor.unsqueeze(0)
return tensor.view(torch.uint8)unsqueeze preserves the original storage, so in-place collective writes still update the parameter. The helper should be used by all raw-byte parameter broadcast sites. A multi-rank regression should cover engine initialization and the ZeRO/GatheredParameters broadcast paths.
ds_report output
Relevant environment summary:
torch version .................... 2.13.0+cu130
torch cuda version ............... 13.0
deepSpeed info ................... 0.19.6+18af1625dasync_io is unavailable in this environment, but the scalar-broadcast reproducer does not require it.
System info
- OS: Linux
- GPU count and types: Two ranks on NVIDIA GeForce RTX 5090 D GPUs (8 GPUs visible)
- Interconnects: Single node
- Python version: 3.10.20
- PyTorch: 2.13.0+cu130
- CUDA runtime: 13.0
Launcher context
DeepSpeed's two-rank DistributedTest harness (single node).
Docker context
Not using a specific Docker image.
Additional context
This is distinct from #7686: that report concerns narrow() on a 0-D tensor in the ZenFlow Stage 3 path, whereas this issue is caused by dtype reinterpretation for parameter broadcasts.
Source: deepspeedai/DeepSpeed