THUDM / THUDM/slime

[Bug] Colocate weight update fails with torch_memory_saver/offload because PyTorch CUDA IPC _share_cuda_ raises cudaErrorInvalidValue

Open
#2,188 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
8.5k
Forks
1.3k
Avg merge
5h 36m
Merged PRs (30d)
22

Description

Bug Description

I am running a Slime GRPO job with Megatron backend, SGLang rollout engines, --colocate, --offload-train, and torch_memory_saver preload enabled. The job consistently fails during the first colocated weight update, before any training step completes.

Although --update-weight-transport nccl is configured, colocated engines still go through UpdateWeightFromTensor, which serializes flattened CUDA tensors with MultiprocessingSerializer / PyTorch CUDA IPC. In this environment that path fails in storage._share_cuda_() with CUDA error: invalid argument.

Steps to Reproduce
  1. Run a single-node 8xH100 Slime GRPO job with:

    • Megatron backend
    • SGLang rollout engines
    • --colocate
    • --offload-train
    • --update-weight-mode full
    • --update-weight-transport nccl
    • --rollout-num-gpus 8
    • --rollout-num-gpus-per-engine 1
    • --tensor-model-parallel-size 4
    • --megatron-to-hf-mode bridge
  2. Enable torch_memory_saver preload:

    • LD_PRELOAD=<torch_memory_saver_hook_mode_preload_cu12.abi3.so>
    • TMS_INIT_ENABLE=1
    • TMS_INIT_ENABLE_CPU_BACKUP=1
  3. Start training.

  4. Observe that SGLang engines start successfully and Megatron loads the checkpoint, but the first actor_model.update_weights() fails inside UpdateWeightFromTensor.

Expected Behavior

Slime colocate should either:

  • successfully update colocated SGLang engines with CUDA IPC under torch_memory_saver, or
  • provide a supported non-disk fallback, such as local NCCL weight update for colocated engines.

In particular, if --update-weight-transport nccl is configured, it would be helpful to either use NCCL for colocated engines too or document that colocated engines still use PyTorch CUDA IPC.

Actual Behavior

The first colocated weight update fails in PyTorch CUDA IPC serialization:

ray.exceptions.RayTaskError(AcceleratorError): ray::MegatronTrainRayActor.update_weights()
  File ".../slime/backends/megatron_utils/update_weight/update_weight_from_tensor.py", line ...
    serialized = MultiprocessingSerializer.serialize(flattened_tensor_data, output_str=True)
  File ".../sglang/srt/utils/common.py", line 2335, in serialize
    ForkingPickler(buf).dump(obj)
  File ".../torch/multiprocessing/reductions.py", line 353, in reduce_tensor
    ) = storage._share_cuda_()
  File ".../torch/storage.py", line 1452, in _share_cuda_
    return self._untyped_storage._share_cuda_(*args, **kwargs)
torch.AcceleratorError: CUDA error: invalid argument

The failing tensor can be very small:

rank=6 dtype=dtype tms_interesting_region=False
cuda_context={'current_device': 6, 'local_rank': '6',
              'cuda_visible_devices': '0,1,2,3,4,5,6,7'}
tensor={'shape': (8192,), 'dtype': 'torch.uint8', 'device': 'cuda:6',
        'numel': 8192, 'nbytes': 8192, 'is_contiguous': True, ...}

I also ruled out current-device mismatch and simple storage reuse:

  • current_device == local_rank == tensor.device
  • cloned tensors with a different storage pointer still fail in _share_cuda_() in the full Slime actor after the actor enters the TMS/offload lifecycle
  • cloning and serializing from a fresh Python thread also fails in _share_cuda_()
Environment
  • slime version: 0.3.0, commit 4c058f65
  • Python version: 3.12.3
  • PyTorch version: 2.11.0+cu129
  • CUDA/ROCm version: CUDA 12.9
  • OS: Ubuntu 24.04.2 LTS
  • SGLang version: 0.5.13, commit 28b095c
  • Megatron-LM version: commit 1dcf0dafa
  • Ray version: 2.55.1
  • torch_memory_saver version: 0.0.9.post1
Logs
ray.exceptions.RayTaskError(AcceleratorError): ray::MegatronTrainRayActor.update_weights()
  File ".../slime/backends/megatron_utils/update_weight/update_weight_from_tensor.py", line ...
    serialized = MultiprocessingSerializer.serialize(flattened_tensor_data, output_str=True)
  File ".../sglang/srt/utils/common.py", line 2335, in serialize
    ForkingPickler(buf).dump(obj)
  File ".../torch/multiprocessing/reductions.py", line 353, in reduce_tensor
    ) = storage._share_cuda_()
  File ".../torch/storage.py", line 1452, in _share_cuda_
    return self._untyped_storage._share_cuda_(*args, **kwargs)
torch.AcceleratorError: CUDA error: invalid argument

CUDA IPC serialize failed for colocate weight bucket;
rank=6 dtype=dtype tms_interesting_region=False
cuda_context={'current_device': 6, 'local_rank': '6',
              'cuda_visible_devices': '0,1,2,3,4,5,6,7'}
tensor={'shape': (8192,), 'dtype': 'torch.uint8', 'device': 'cuda:6',
        'numel': 8192, 'nbytes': 8192, 'is_contiguous': True, ...}

CUDA IPC serialize retry failed for colocate weight bucket;
cloned_tensor={'shape': (8192,), 'dtype': 'torch.uint8', 'device': 'cuda:0',
               'data_ptr': 43298350592, 'storage_ptr': 43298350592}
thread_traceback=...
  File ".../torch/multiprocessing/reductions.py", line 353, in reduce_tensor
    ) = storage._share_cuda_()
torch.AcceleratorError: CUDA error: invalid argument
Additional Context

I checked nearby issues/PRs:

  • THUDM/slime#1731 fixes CUDA IPC cache lifetime/leak behavior, but this failure happens at the first _share_cuda_() call.
  • THUDM/slime#1786 is another TMS/offload CUDA error, but the stack is different.
  • THUDM/slime#2186 is about CUDA 13 selecting the wrong torch_memory_saver preload .so; my environment is CUDA 12.9, the preload library loads successfully, and the failure happens later during the first colocated weight update.
  • fzyzcjy/torch_memory_saver#36 reports a similar lower-level issue where CUDA IPC tensor serialization fails when torch_memory_saver is enabled.
Pre-submission Checklist
  • I have read the CONTRIBUTING.md and understand the collaboration scope.
  • I have read the documentation and my issue is not addressed there.
  • I have searched for existing issues and this is not a duplicate.
  • I have provided a minimal, reproducible example.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in slime/backends/megatron_utils/update_weight/update_weight_from_tensor.py and trace the colocated path from actor_model.update_weights() through MultiprocessingSerializer.serialize. Reproduce the first weight update with the listed colocate, offload-train, NCCL, and torch_memory_saver settings, then verify that colocated engines complete the update without the CUDA IPC error and that the configured transport behavior is supported or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
distributed-systems, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.