THUDM / THUDM/slime

[Question] Is it safe for non-source ranks to del long_lived_tensors immediately in UpdateWeightFromTensor ?

Open
#1,348 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I've been studying the colocated weight update mechanism in slime/backends/megatron_utils/update_weight/update_weight_from_tensor.py
and noticed a behavior that I'm struggling to understand regarding shared memory safety. In the update_weights loop, the code iterates over weight chunks and sends them to the colocated engine:

def update_weights(self) -> None:
    # ...
    for hf_named_tensors in self._hf_weight_iterator.get_hf_weight_chunks(megatron_local_weights):
        refs, long_lived_tensors = self._send_hf_params(hf_named_tensors)
        
        # Source rank waits for consumption (refs is not empty)
        # But non-source ranks have empty refs, so they return immediately?
        ray.get(refs)
        
        # Non-source ranks delete the tensors immediately here
        del long_lived_tensors 

    # The barrier is outside the loop
    dist.barrier(group=get_gloo_group())

--
As I understand it, Non-source ranks delete long_lived_tensors immediately without waiting for the consumer (Rollout Engine). Since dist.barrier is outside the loop, could this cause the underlying shared memory to be released before the Engine maps it, leading to a race condition? Or is there an implicit sync I missed?
Would love to hear some insights on how the lifecycle is managed here. Thanks!

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, following update_weights through _send_hf_params, ray.get(refs), long_lived_tensors cleanup, and the final get_gloo_group barrier. Trace the shared-memory ownership and consumer synchronization across source and non-source ranks. Done means establishing whether deletion can race with engine mapping and documenting or testing the required lifecycle guarantee.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.