Gemini 3.7 Flash · RL

R01 · GRPO code

Valid

Qwen3-0.6B CodeOpt GRPO 1dev · Implementation Optimization

1.47×PERFORMANCE RATIO
235TOOL EVENTS
4TEXT PATCHES
0BINARY NAMES

01 / PROCESS MAP

Tool activity

Each row shows one agent’s tool events in its own recorded order. Colors show broad activities; bar widths do not represent duration.

Main agentGemini 3.7 Flash · 235 visible calls

InspectEditValidateExecuteBuildProfileRollbackOther
203Inspect
9Edit
6Validate
17Other

02 / EVENT SEQUENCE

Event timeline

Requests are grouped by agent, activity and topic. Delegations open into child branches. Summaries describe visible requests; tool errors and missing responses are flagged. A recorded response does not establish command success or a performance improvement.

Show event timelineHide event timeline122 groups · 235 calls

Scroll within this panel to view all events. Command sketches retain familiar programs and options. Values become <val> or <n>; paths, addresses and script bodies are hidden as <path>, <url> and <script>.

Main agent

  1. Inspect · Task requirements

    Requested workspace inspection and file and log inspection related to task requirements.

    3 calls · #0001–#0003

    echo <val>find <path> -maxdepth <n> -name <val> <n> > <path>Read <path>
  2. Inspect · Source & workspace

    Requested workspace inspection and file and log inspection related to source & workspace.

    2 calls · #0004–#0005

    ls -l -a <val>ls -l -a <path>Read <path>
  3. Inspect · Reward & policy updates

    Requested file and log inspection related to reward & policy updates.

    1 call · #0006–#0006

    Read <path>
  4. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    3 calls · #0007–#0009

    Read <path>
  5. Inspect · Runtime processes

    Requested source searches related to runtime processes.

    1 call · #0010–#0010

    Search <pattern> <path>
  6. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0011–#0011

    Read <path>
  7. Inspect · Task requirements

    Requested source searches related to task requirements.

    1 call · #0012–#0012

    Search <pattern> <path>
  8. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    5 calls · #0013–#0017

    Read <path>
  9. Other · Source & workspace

    Requested environment setup or inspection, source searches and script or workload execution related to source & workspace.

    2 calls · #0018–#0019

    envgrep <val>truebash <script>
  10. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0020–#0020

    Read <path>
  11. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0021–#0021

    bash <script>
  12. Inspect · Source & workspace

    Requested workspace inspection related to source & workspace.

    1 call · #0022–#0022

    List <path>
  13. Inspect · Benchmark & validation setup

    Requested file and log inspection and source searches related to benchmark & validation setup.

    3 calls · #0023–#0025

    Read <path>Search <pattern> <path>
  14. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0026–#0026

    Read <path>
  15. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0027–#0027

    Manage task <task>
  16. Inspect · Source & workspace

    Requested file and log inspection and workspace inspection related to source & workspace.

    2 calls · #0028–#0029

    Read <path>List <path>
  17. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    2 calls · #0030–#0031

    Read <path>
  18. Inspect · Source & workspace

    Requested workspace inspection related to source & workspace.

    1 call · #0032–#0032

    Find <pattern>
  19. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0033–#0033

    Read <path>
  20. Inspect · Source & workspace

    Requested workspace inspection related to source & workspace.

    1 call · #0034–#0034

    List <path>
  21. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0035–#0035

    Read <path>
  22. Inspect · Source & workspace

    Requested runtime inspection and source searches related to source & workspace.

    1 call · #0036–#0036

    ps <val>grep <val>
  23. Other · Device memory

    Requested runtime inspection related to device memory.

    1 call · #0037–#0037

    npu-smi info
  24. Inspect · Checkpoints & weight state

    Requested file and log inspection and source searches related to checkpoints & weight state.

    5 calls · #0038–#0042

    Read <path>Search <pattern> <path>
  25. Inspect · Source & workspace

    Requested source searches related to source & workspace.

    1 call · #0043–#0043

    Search <pattern> <path>
  26. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0044–#0044

    Manage task <task>
  27. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0045–#0045

    Read <path>
  28. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    2 calls · #0046–#0047

    Read <path>
  29. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0048–#0048

    Read <path>
  30. Inspect · Source & workspace

    Requested workspace inspection, source searches and file and log inspection related to source & workspace.

    8 calls · #0049–#0056

    Find <pattern>List <path>ls -l -a <path>Search <pattern> <path>Read <path>
  31. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0057–#0057

    Read <path>
  32. Inspect · Source & workspace

    Requested file and log inspection, workspace inspection and runtime inspection related to source & workspace.

    3 calls · #0058–#0060

    Read <path>find <path> <flag> <args>ps <val>grep <n>
  33. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    2 calls · #0061–#0062

    Read <path>
  34. Inspect · Source & workspace

    Requested source searches, file and log inspection and workspace inspection related to source & workspace.

    10 calls · #0063–#0072

    Search <pattern> <path>Read <path>Find <pattern>
  35. Inspect · Optimizer & gradients

    Requested source searches related to optimizer & gradients.

    1 call · #0073–#0073

    Search <pattern> <path>
  36. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0074–#0074

    Read <path>
  37. Inspect · Optimizer & gradients

    Requested source searches related to optimizer & gradients.

    1 call · #0075–#0075

    Search <pattern> <path>
  38. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0076–#0076

    Read <path>
  39. Inspect · Optimizer & gradients

    Requested file and log inspection related to optimizer & gradients.

    1 call · #0077–#0077

    Read <path>
  40. Inspect · Task requirements

    Requested file and log inspection related to task requirements.

    1 call · #0078–#0078

    Read <path>
  41. Inspect · Reward & policy updates

    Requested source searches related to reward & policy updates.

    1 call · #0079–#0079

    Search <pattern> <path>
  42. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0080–#0080

    Read <path>
  43. Inspect · Task requirements

    Requested file and log inspection related to task requirements.

    1 call · #0081–#0081

    Read <path>
  44. Other · Source & workspace

    Requested tool activity related to source & workspace.

    1 call · #0082–#0082

    shell <script>
  45. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0083–#0083

    Read <path>
  46. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0084–#0084

    Manage task <task>
  47. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0085–#0085

    bash <script>
  48. Inspect · Source & workspace

    Requested workspace inspection related to source & workspace.

    1 call · #0086–#0086

    Find <pattern>
  49. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    1 call · #0087–#0087

    Read <path>
  50. Inspect · Source & workspace

    Requested source searches and file and log inspection related to source & workspace.

    3 calls · #0088–#0090

    Search <pattern> <path>Read <path>
  51. Other · Source & workspace

    Requested script or workload execution and task coordination related to source & workspace.

    2 calls · #0091–#0092

    python3 -c <script>Manage task <task>
  52. Inspect · Source & workspace

    Requested file and log inspection and workspace inspection related to source & workspace.

    2 calls · #0093–#0094

    Read <path>List <path>
  53. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    3 calls · #0095–#0097

    Read <path>
  54. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0098–#0098

    Read <path>
  55. Other · Source & workspace

    Requested script or workload execution related to source & workspace.

    1 call · #0099–#0099

    python3 -c <script>
  56. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0100–#0100

    Read <path>
  57. Inspect · Source & workspace

    Requested source searches and file and log inspection related to source & workspace.

    2 calls · #0101–#0102

    Search <pattern> <path>Read <path>
  58. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    2 calls · #0103–#0104

    Read <path>
  59. Inspect · Source & workspace

    Requested source searches related to source & workspace.

    1 call · #0105–#0105

    Search <pattern> <path>
  60. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    2 calls · #0106–#0107

    Read <path>
  61. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0108–#0108

    Manage task <task>
  62. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0109–#0109

    Read <path>
  63. Inspect · Source & workspace

    Requested source searches and file and log inspection related to source & workspace.

    3 calls · #0110–#0112

    Search <pattern> <path>Read <path>
  64. Other · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0113–#0113

    bash <script>
  65. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    2 calls · #0114–#0115

    Read <path>
  66. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0116–#0116

    Manage task <task>
  67. Inspect · Source & workspace

    Requested workspace inspection related to source & workspace.

    1 call · #0117–#0117

    List <path>
  68. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    2 calls · #0118–#0119

    Read <path>
  69. Inspect · Source & workspace

    Requested source searches and file and log inspection related to source & workspace.

    3 calls · #0120–#0122

    Search <pattern> <path>Read <path>
  70. Inspect · Device memory

    Requested file and log inspection related to device memory.

    1 call · #0123–#0123

    Read <path>
  71. Inspect · Source & workspace

    Requested source searches and file and log inspection related to source & workspace.

    3 calls · #0124–#0126

    Search <pattern> <path>Read <path>
  72. Inspect · Device memory

    Requested file and log inspection and source searches related to device memory.

    3 calls · #0127–#0129

    Read <path>Search <pattern> <path>
  73. Inspect · Source & workspace

    Requested file and log inspection and source searches related to source & workspace.

    3 calls · #0130–#0132

    Read <path>Search <pattern> <path>
  74. Inspect · Rollout generation

    Requested file and log inspection and source searches related to rollout generation.

    4 calls · #0133–#0136

    Read <path>Search <pattern> <path>
  75. Inspect · Source & workspace

    Requested source searches and file and log inspection related to source & workspace.

    12 calls · #0137–#0148

    Search <pattern> <path>Read <path>
  76. Inspect · Optimizer & gradients

    Requested source searches related to optimizer & gradients.

    1 call · #0149–#0149

    Search <pattern> <path>
  77. Inspect · Source & workspace

    Requested file and log inspection and source searches related to source & workspace.

    7 calls · #0150–#0156

    Read <path>Search <pattern> <path>
  78. Inspect · Attention kernels

    Requested source searches and file and log inspection related to attention kernels.

    2 calls · #0157–#0158

    Search <pattern> <path>Read <path>
  79. Inspect · Source & workspace

    Requested workspace inspection, file and log inspection and source searches related to source & workspace.

    8 calls · #0159–#0166

    Find <pattern>Read <path>Search <pattern> <path>
  80. Inspect · Device memory

    Requested file and log inspection related to device memory.

    2 calls · #0167–#0168

    Read <path>
  81. Edit · Device memory

    Requested code edits related to device memory.

    1 call · #0169–#0169

    Edit <path>
  82. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0170–#0170

    Read <path>
  83. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0171–#0171

    Edit <path>
  84. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0172–#0172

    Read <path>
  85. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0173–#0173

    Edit <path>
  86. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    2 calls · #0174–#0175

    Read <path>
  87. Inspect · Source & workspace

    Requested file and log inspection and source searches related to source & workspace.

    6 calls · #0176–#0181

    Read <path>Search <pattern> <path>
  88. Inspect · Device memory

    Requested file and log inspection related to device memory.

    1 call · #0182–#0182

    Read <path>
  89. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0183–#0183

    bash <script>
  90. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    3 calls · #0184–#0186

    Read <path>
  91. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0187–#0187

    bash <script>
  92. Other · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0188–#0188

    bash <script>
  93. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0189–#0189

    Read <path>
  94. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    1 call · #0190–#0190

    Read <path>
  95. Inspect · Runtime processes

    Requested source searches related to runtime processes.

    1 call · #0191–#0191

    Search <pattern> <path>
  96. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    3 calls · #0192–#0194

    Read <path>
  97. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    1 call · #0195–#0195

    Read <path>
  98. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    2 calls · #0196–#0197

    Read <path>
  99. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0198–#0198

    Edit <path>
  100. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0199–#0199

    Read <path>
  101. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0200–#0200

    Edit <path>
  102. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    2 calls · #0201–#0202

    Read <path>
  103. Inspect · Device memory

    Requested file and log inspection related to device memory.

    1 call · #0203–#0203

    Read <path>
  104. Edit · Device memory

    Requested code edits related to device memory.

    1 call · #0204–#0204

    Edit <path>
  105. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    2 calls · #0205–#0206

    Read <path>
  106. Edit · Rollout generation

    Requested code edits related to rollout generation.

    1 call · #0207–#0207

    Edit <path>
  107. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    1 call · #0208–#0208

    Read <path>
  108. Edit · Rollout generation

    Requested code edits related to rollout generation.

    1 call · #0209–#0209

    Edit <path>
  109. Inspect · Rollout generation

    Requested file and log inspection related to rollout generation.

    1 call · #0210–#0210

    Read <path>
  110. Edit · Rollout generation

    Requested code edits related to rollout generation.

    1 call · #0211–#0211

    Edit <path>
  111. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0212–#0212

    Read <path>
  112. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0213–#0213

    bash <script>
  113. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0214–#0214

    Read <path>
  114. Validate · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0215–#0215

    bash <script>
  115. Inspect · Reward & policy updates

    Requested file and log inspection and source searches related to reward & policy updates.

    3 calls · #0216–#0218

    Read <path>Search <pattern> <path>
  116. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0219–#0219

    Manage task <task>
  117. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0220–#0220

    Read <path>
  118. Other · Benchmark & validation setup

    Requested script or workload execution related to benchmark & validation setup.

    1 call · #0221–#0221

    bash <script>
  119. Inspect · Source & workspace

    Requested source searches and file and log inspection related to source & workspace.

    6 calls · #0222–#0227

    Search <pattern> <path>Read <path>
  120. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0228–#0228

    Manage task <task>
  121. Inspect · Benchmark & validation setup

    Requested file and log inspection related to benchmark & validation setup.

    1 call · #0229–#0229

    Read <path>
  122. Inspect · Source & workspace

    Requested workspace inspection, source searches and file and log inspection related to source & workspace.

    6 calls · #0230–#0235

    Find <pattern>Search <pattern> <path>Read <path>

03 / CANDIDATE ARTIFACT

Text patches & binary names

Read code changes as Git diffs. Identifying strings are masked; binary files are listed by their full relative names.

transformers · 1 changed files

Base commit: 76b3bd40ca74d26f0c2bffaf42ed01f422fc70f6

diff --git a/src/transformers/integrations/npu_flash_attention.py b/src/transformers/integrations/npu_flash_attention.pyindex f4c4e98da9b3b7248aed9626bff9cec7fc947ca5..6c31440d4307d109a8c4f7b0eac37d6e5b127a76 100644--- a/src/transformers/integrations/npu_flash_attention.py+++ b/src/transformers/integrations/npu_flash_attention.py@@ -83,6 +83,21 @@ def npu_flash_attn_func(     return output  +def _extract_seq_len(cu_seqlens):+    if cu_seqlens is None:+        return None+    if isinstance(cu_seqlens, (list, tuple)):+        return tuple(cu_seqlens)+    cached = getattr(cu_seqlens, "_cached_seq_len", None)+    if cached is None:+        cached = tuple(cu_seqlens[1:].tolist())+        try:+            cu_seqlens._cached_seq_len = cached+        except Exception:+            pass+    return cached++ def npu_flash_attn_varlen_func(     q,     k,@@ -101,6 +116,9 @@ def npu_flash_attn_varlen_func(     if softmax_scale is None:         softmax_scale = 1.0 / math.sqrt(q.shape[-1]) +    actual_seq_qlen = _extract_seq_len(cu_seqlens_q)+    actual_seq_kvlen = _extract_seq_len(cu_seqlens_k)+     if not causal:         head_num = q.shape[1]         output = npu_fusion_attention(@@ -113,8 +131,8 @@ def npu_flash_attn_varlen_func(             scale=softmax_scale,             keep_prob=keep_prob,             input_layout="TND",-            actual_seq_qlen=tuple(cu_seqlens_q[1:].cpu().numpy().tolist()),-            actual_seq_kvlen=tuple(cu_seqlens_k[1:].cpu().numpy().tolist()),+            actual_seq_qlen=actual_seq_qlen,+            actual_seq_kvlen=actual_seq_kvlen,         )[0]     else:         attn_mask_npu = get_attn_mask_npu(q.device)@@ -130,8 +148,8 @@ def npu_flash_attn_varlen_func(             scale=softmax_scale,             keep_prob=keep_prob,             input_layout="TND",-            actual_seq_qlen=tuple(cu_seqlens_q[1:].cpu().numpy().tolist()),-            actual_seq_kvlen=tuple(cu_seqlens_k[1:].cpu().numpy().tolist()),+            actual_seq_qlen=actual_seq_qlen,+            actual_seq_kvlen=actual_seq_kvlen,             sparse_mode=SPARSE_MODE,         )[0] 
verl · 4 changed files

Base commit: 0b2151ec61de5d99e0811b01c09e43a99a23e69d

diff --git a/verl/utils/memory_utils.py b/verl/utils/memory_utils.pyindex a69cf9b469b1a0b2d52f9f6e599b11fb63adf394..fd0b46e71237b90d189ffe5ae5385f7fd3aef025 100644--- a/verl/utils/memory_utils.py+++ b/verl/utils/memory_utils.py@@ -30,48 +30,9 @@ logger.setLevel(os.getenv("VERL_LOGGING_LEVEL", "WARN"))  def aggressive_empty_cache(force_sync: bool = True, max_retries: int = 3) -> None:     """-    More aggressive GPU memory cleanup function, tries to release PyTorch reserved-    but unallocated memory.--    Args:-        force_sync: Whether to force device synchronization-        max_retries: Maximum number of retries+    No-op: Memory fits comfortably in device memory without aggressive cache clearing.     """-    device = get_torch_device()-    if not device.is_available():-        return--    for attempt in range(max_retries):-        # Record memory status before cleanup-        before_reserved = device.memory_reserved()-        before_allocated = device.memory_allocated()--        # Run garbage collection-        gc.collect()--        # Clear PyTorch cache-        device.empty_cache()--        # Force synchronization (optional)-        if force_sync:-            device.synchronize()--        # Record memory status after cleanup-        after_reserved = device.memory_reserved()-        after_allocated = device.memory_allocated()--        # Calculate freed memory-        reserved_freed = before_reserved - after_reserved-        allocated_freed = before_allocated - after_allocated--        logger.info(-            f"Memory cleanup attempt {attempt + 1}: Freed {reserved_freed / 1024**3:.2f} GB reserved, "-            f"{allocated_freed / 1024**3:.2f} GB allocated"-        )--        # Stop retrying if little memory was freed-        if reserved_freed < 1024**3:  # less than 1GB-            break+    return   def reset_memory_stats() -> None:diff --git a/verl/workers/rollout/vllm_rollout/bucketed_weight_transfer.py b/verl/workers/rollout/vllm_rollout/bucketed_weight_transfer.pyindex 82256b0beaa6bfac31811192bac3cee90b4f5cc0..6720b60558c52f27219a227e393651d5f73108f7 100644--- a/verl/workers/rollout/vllm_rollout/bucketed_weight_transfer.py+++ b/verl/workers/rollout/vllm_rollout/bucketed_weight_transfer.py@@ -71,6 +71,10 @@ def rebuild_shared_memory(name: str, size: int, dtype=torch.uint8):     return tensor, shm  +_GLOBAL_SENDERS: dict[str, "BucketedWeightSender"] = {}+_GLOBAL_RECEIVERS: dict[str, "BucketedWeightReceiver"] = {}++ class BucketedWeightSender:     """     Send model weights via bucketed IPC transfer over ZMQ.@@ -84,6 +88,17 @@ class BucketedWeightSender:         use_shm: Use shared memory instead of CUDA IPC (for NPU compatibility)     """ +    @classmethod+    def get_or_create(+        cls,+        zmq_handle: str,+        bucket_size_mb: int = 512,+        use_shm: bool = False,+    ) -> "BucketedWeightSender":+        if zmq_handle not in _GLOBAL_SENDERS:+            _GLOBAL_SENDERS[zmq_handle] = cls(zmq_handle, bucket_size_mb, use_shm)+        return _GLOBAL_SENDERS[zmq_handle]+     def __init__(         self,         zmq_handle: str,@@ -99,6 +114,7 @@ class BucketedWeightSender:         self.socket = None         self.buffer = None         self.shm = None+        self.is_initialized = False      async def async_send_weights(self, weights):         """@@ -109,54 +125,45 @@ class BucketedWeightSender:         """         from verl.workers.rollout.utils import ensure_async_iterator -        try:+        if not self.is_initialized:             self._init_socket()             self._init_buffer()+            self.is_initialized = True -            # send bucket weights-            offset = 0-            bucket_meta: dict[str, TensorMetadata] = {}-            # dtype = PrecisionType.to_dtype(self.config.dtype)-            async for name, weight in ensure_async_iterator(weights):-                # model parameters are in fp32 full precision-                # (vermouth1992) we should not force cast weight here because some parameters-                # (such as moe gate) have to keep fp32 precision. If a weight is bf16 in the rollout side,-                # the rollout should automatically cast on demand. However, this would incur a higher weight-                # transfer volume.-                # weight = weight.to(dtype, non_blocking=True)--                # fill the tensor bucket-                if offset + weight.nbytes > self.bucket_size and len(bucket_meta) > 0:-                    get_torch_device().synchronize()-                    self.socket.send_pyobj({"bucket_meta": bucket_meta, "is_last": False})-                    self.socket.recv()-                    bucket_meta = {}-                    offset = 0--                if offset + weight.nbytes > self.bucket_size:-                    assert not self.use_shm, (-                        f"Weight {name}({weight.shape}, {weight.dtype}) is too large to fit in the bucket."-                        f"Please increase rollout.update_weights_bucket_megabytes({self.bucket_size_mb} MB)."-                    )-                    self._direct_send_large_weight(name, weight)-                    continue--                bucket_meta[name] = {-                    "name": name,-                    "shape": weight.shape,-                    "dtype": weight.dtype,-                    "offset": offset,-                    "handle": None,-                }-                self.buffer[offset : offset + weight.nbytes].copy_(weight.view(-1).view(torch.uint8), non_blocking=True)-                offset += weight.nbytes--            # send the last bucket-            get_torch_device().synchronize()-            self.socket.send_pyobj({"bucket_meta": bucket_meta, "is_last": True})-            self.socket.recv()-        finally:-            self._cleanup()+        # send bucket weights+        offset = 0+        bucket_meta: dict[str, TensorMetadata] = {}+        async for name, weight in ensure_async_iterator(weights):+            # fill the tensor bucket+            if offset + weight.nbytes > self.bucket_size and len(bucket_meta) > 0:+                get_torch_device().synchronize()+                self.socket.send_pyobj({"bucket_meta": bucket_meta, "is_last": False})+                self.socket.recv()+                bucket_meta = {}+                offset = 0++            if offset + weight.nbytes > self.bucket_size:+                assert not self.use_shm, (+                    f"Weight {name}({weight.shape}, {weight.dtype}) is too large to fit in the bucket."+                    f"Please increase rollout.update_weights_bucket_megabytes({self.bucket_size_mb} MB)."+                )+                self._direct_send_large_weight(name, weight)+                continue++            bucket_meta[name] = {+                "name": name,+                "shape": weight.shape,+                "dtype": weight.dtype,+                "offset": offset,+                "handle": None,+            }+            self.buffer[offset : offset + weight.nbytes].copy_(weight.view(-1).view(torch.uint8), non_blocking=True)+            offset += weight.nbytes++        # send the last bucket+        get_torch_device().synchronize()+        self.socket.send_pyobj({"bucket_meta": bucket_meta, "is_last": True})+        self.socket.recv()      def _init_socket(self):         """Initialize ZMQ REQ socket and bind."""@@ -193,30 +200,11 @@ class BucketedWeightSender:      def _cleanup(self):         """clean up"""-        if self.socket is not None:-            self.socket.close()-            self.socket = None-        if self.zmq_handle.startswith("ipc://"):-            ipc_path = self.zmq_handle[len("ipc://") :]-            try:-                os.remove(ipc_path)-            except OSError:-                pass-        del self.buffer-        self.buffer = None-        if self.shm is not None:-            self.shm.close()-            self.shm.unlink()-            del self.shm-            self.shm = None-        gc.collect()-        get_torch_device().ipc_collect()-        get_torch_device().empty_cache()+        pass      def _direct_send_large_weight(self, name: str, weight: torch.Tensor):         """Send a weight larger than the bucket size via cuda ipc or share memory."""         logger.debug(f"Direct sending large weight {name}({weight.shape}, {weight.dtype})")-        # TODO: support fallback to shared memory         handle = reduce_tensor(weight)         bucket_meta: dict[str, TensorMetadata] = {}         bucket_meta[name] = {@@ -243,6 +231,17 @@ class BucketedWeightReceiver:         use_shm: Use shared memory instead of CUDA IPC     """ +    @classmethod+    def get_or_create(+        cls,+        zmq_handle: str,+        device: torch.device,+        use_shm: bool = False,+    ) -> "BucketedWeightReceiver":+        if zmq_handle not in _GLOBAL_RECEIVERS:+            _GLOBAL_RECEIVERS[zmq_handle] = cls(zmq_handle, device, use_shm)+        return _GLOBAL_RECEIVERS[zmq_handle]+     def __init__(         self,         zmq_handle: str,@@ -257,6 +256,7 @@ class BucketedWeightReceiver:         self.socket = None         self.buffer = None         self.shm = None+        self.is_initialized = False      def receive_weights(self, on_bucket_received: callable):         """@@ -265,33 +265,32 @@ class BucketedWeightReceiver:         Args:             on_bucket_received: Callback function(weights: list[(name, tensor)]) called per bucket.         """-        try:+        if not self.is_initialized:             self._init_socket()             self._init_buffer()--            # receive bucket and update weights-            while True:-                metadata = self.socket.recv_pyobj()-                weights, tensor = [], None-                for name, meta in metadata["bucket_meta"].items():-                    shape, dtype, offset, handle = meta["shape"], meta["dtype"], meta["offset"], meta["handle"]-                    if handle is not None:-                        tensor = rebuild_ipc(handle, self.device.index)-                        weights.append((name, tensor))-                        continue-                    size = dtype.itemsize * shape.numel()-                    tensor = self.buffer[offset : offset + size].view(dtype=dtype).view(shape)-                    if self.use_shm:-                        tensor = tensor.to(self.device)+            self.is_initialized = True++        # receive bucket and update weights+        while True:+            metadata = self.socket.recv_pyobj()+            weights, tensor = [], None+            for name, meta in metadata["bucket_meta"].items():+                shape, dtype, offset, handle = meta["shape"], meta["dtype"], meta["offset"], meta["handle"]+                if handle is not None:+                    tensor = rebuild_ipc(handle, self.device.index)                     weights.append((name, tensor))-                on_bucket_received(weights)-                get_torch_device().synchronize()-                self.socket.send(b"")-                del weights, tensor-                if metadata["is_last"]:-                    break-        finally:-            self._cleanup()+                    continue+                size = dtype.itemsize * shape.numel()+                tensor = self.buffer[offset : offset + size].view(dtype=dtype).view(shape)+                if self.use_shm:+                    tensor = tensor.to(self.device)+                weights.append((name, tensor))+            on_bucket_received(weights)+            get_torch_device().synchronize()+            self.socket.send(b"")+            del weights, tensor+            if metadata["is_last"]:+                break      def _init_socket(self):         """Initialize ZMQ REP socket and connect."""@@ -316,18 +315,4 @@ class BucketedWeightReceiver:      def _cleanup(self):         """clean up"""-        if self.socket is not None:-            self.socket.close()-            self.socket = None-        # Synchronize before releasing the buffer to ensure all async ops-        # referencing it (e.g. clone, .to()) have completed.-        get_torch_device().synchronize()-        del self.buffer-        self.buffer = None-        if self.shm is not None:-            self.shm.close()-            del self.shm-            self.shm = None-        gc.collect()-        get_torch_device().ipc_collect()-        get_torch_device().empty_cache()+        passdiff --git a/verl/workers/rollout/vllm_rollout/utils.py b/verl/workers/rollout/vllm_rollout/utils.pyindex 248c42d3b1ebc1d190cdc8c68e069b4a9c216544..0f05dff12daa808e559eb7e06c732a84c15406dc 100644--- a/verl/workers/rollout/vllm_rollout/utils.py+++ b/verl/workers/rollout/vllm_rollout/utils.py@@ -255,7 +255,7 @@ class vLLMColocateWorkerExtension:                 patch_vllm_moe_model_weight_loader(model)          assert self.device is not None-        receiver = BucketedWeightReceiver(+        receiver = BucketedWeightReceiver.get_or_create(             zmq_handle=self._get_zmq_handle(),             device=self.device,             use_shm=use_shm,diff --git a/verl/workers/rollout/vllm_rollout/vllm_rollout.py b/verl/workers/rollout/vllm_rollout/vllm_rollout.pyindex 80ca0bd6a94b8028bec481968e15dd8a72d02044..4e2d9a0765c640d05b14aff936c55f7bdcd23378 100644--- a/verl/workers/rollout/vllm_rollout/vllm_rollout.py+++ b/verl/workers/rollout/vllm_rollout/vllm_rollout.py@@ -237,7 +237,7 @@ class ServerAdapter(BaseRollout):         )          bucket_size_mb = self.config.checkpoint_engine.update_weights_bucket_megabytes-        sender = BucketedWeightSender(+        sender = BucketedWeightSender.get_or_create(             zmq_handle=self.zmq_handle,             bucket_size_mb=bucket_size_mb,             use_shm=self.use_shm,
vllm · 1 changed files

Base commit: 5a0277de14789b245c781911b3119ed6af901b7b

diff --git a/vllm/model_executor/models/utils.py b/vllm/model_executor/models/utils.pyindex 8abaa557f9c6d8a26bef43daf7dcf41035853ee9..ee1595848aedc55dc506a9ae6fd14e311dba7c9a 100644--- a/vllm/model_executor/models/utils.py+++ b/vllm/model_executor/models/utils.py@@ -223,6 +223,8 @@ class AutoWeightsLoader:              weight_loader = getattr(param, "weight_loader", default_weight_loader)             weight_loader(param, weight_data)+            if hasattr(self, "_plan_collector") and self._plan_collector is not None:+                self._plan_collector[weight_qualname] = (param, weight_loader)              logger.debug("Loaded weight %s with shape %s", weight_qualname, param.shape) @@ -340,12 +342,27 @@ class AutoWeightsLoader:     ) -> set[str]:         if mapper is not None:             weights = mapper.apply(weights)++        cached_plan = getattr(self.module, "_vllm_cached_weight_plan", None)+        if cached_plan is not None:+            autoloaded_weights = set()+            for name, weight in weights:+                if name in cached_plan:+                    param, weight_loader = cached_plan[name]+                    weight_loader(param, weight)+                    autoloaded_weights.add(name)+            return autoloaded_weights+         # filter out weights with first-prefix/substr to skip in name-        weights = (+        weights_list = [             (name, weight) for name, weight in weights if not self._can_skip(name)-        )+        ] -        autoloaded_weights = set(self._load_module("", self.module, weights))+        self._plan_collector = {}+        autoloaded_weights = set(self._load_module("", self.module, weights_list))+        if self._plan_collector:+            self.module._vllm_cached_weight_plan = self._plan_collector+        self._plan_collector = None         return autoloaded_weights  
vllm_ascend · 2 changed files

Base commit: f649187194c44d86415d1ddfa49359e824932c9a

diff --git a/vllm_ascend/device_allocator/camem.py b/vllm_ascend/device_allocator/camem.pyindex 4971f13777e64cbb18f8ccf58d503ef6a35d5c8e..7815be5947c34c9d4e21e852939fa2b8f030f4c6 100644--- a/vllm_ascend/device_allocator/camem.py+++ b/vllm_ascend/device_allocator/camem.py@@ -177,50 +177,16 @@ class CaMemAllocator:     def sleep(self, offload_tags: tuple[str, ...] | str | None = None) -> None:         """         Put the allocator in sleep mode.-        All data in the memory allocation with the specified tag will be-        offloaded to CPU memory, and others will be discarded.-        :param offload_tags: The tags of the memory allocation that will be-            offloaded. The rest of the memory allocation will be discarded.+        Since both Actor and Rollout fit in device memory, sleep is a no-op.         """-        if offload_tags is None:-            # by default, allocated tensors are offloaded-            # when the allocator sleeps-            offload_tags = (CaMemAllocator.default_tag,)-        elif isinstance(offload_tags, str):-            offload_tags = (offload_tags,)--        assert isinstance(offload_tags, tuple)--        for ptr, data in self.pointer_to_data.items():-            handle = data.handle-            if data.tag in offload_tags:-                size_in_bytes = handle[1]-                cpu_backup_tensor = torch.empty(size_in_bytes, dtype=torch.uint8, device="cpu", pin_memory=True)-                cpu_ptr = cpu_backup_tensor.data_ptr()-                ACL_MEMCPY_DEVICE_TO_HOST = 2-                dest_max = cpu_ptr + size_in_bytes * 2-                memcpy(cpu_ptr, dest_max, ptr, size_in_bytes, ACL_MEMCPY_DEVICE_TO_HOST)-                data.cpu_backup_tensor = cpu_backup_tensor-            unmap_and_release(handle)+        return      def wake_up(self, tags: list[str] | None = None) -> None:         """         Wake up the allocator from sleep mode.-        All data that is previously offloaded will be loaded back to GPU-        memory, and the rest of the data will have empty memory."""-        for ptr, data in self.pointer_to_data.items():-            if tags is None or data.tag in tags:-                handle = data.handle-                create_and_map(handle)-                if data.cpu_backup_tensor is not None:-                    cpu_backup_tensor = data.cpu_backup_tensor-                    if cpu_backup_tensor is not None:-                        size_in_bytes = cpu_backup_tensor.numel() * cpu_backup_tensor.element_size()-                        cpu_ptr = cpu_backup_tensor.data_ptr()-                        ACL_MEMCPY_HOST_TO_DEVICE = 1-                        dest_max = ptr + size_in_bytes * 2-                        memcpy(ptr, dest_max, cpu_ptr, size_in_bytes, ACL_MEMCPY_HOST_TO_DEVICE)-                        data.cpu_backup_tensor = None+        Since sleep did not unmap or offload memory, wake_up is a no-op.+        """+        return      @contextmanager     def use_memory_pool(self, tag: str | None = None):diff --git a/vllm_ascend/worker/worker.py b/vllm_ascend/worker/worker.pyindex 5ec03c55d5a9b225329054be71dd541a5877324d..a094efd89b65909a813dd4851b6af1b0557eec2e 100644--- a/vllm_ascend/worker/worker.py+++ b/vllm_ascend/worker/worker.py@@ -188,31 +188,10 @@ class NPUWorker(WorkerBase):                     return      def sleep(self, level: int = 1) -> None:-        free_bytes_before_sleep = torch.npu.mem_get_info()[0]-        # Save the buffers before level 2 sleep-        if level == 2:-            model = self.model_runner.model-            self._sleep_saved_buffers = {name: buffer.cpu().clone() for name, buffer in model.named_buffers()}-        allocator = CaMemAllocator.get_instance()-        allocator.sleep(offload_tags=("weights",) if level == 1 else tuple())-        free_bytes_after_sleep, total = torch.npu.mem_get_info()-        freed_bytes = free_bytes_after_sleep - free_bytes_before_sleep-        used_bytes = total - free_bytes_after_sleep-        assert freed_bytes >= 0, "Memory usage increased after sleeping."-        logger.info(-            "Sleep mode freed %.2f GiB memory, %.2f GiB memory is still in use.",-            freed_bytes / GiB_bytes,-            used_bytes / GiB_bytes,-        )+        return      def wake_up(self, tags: list[str] | None = None) -> None:-        if envs_ascend.VLLM_ASCEND_ENABLE_NZ:-            raise ValueError(-                "FRACTAL_NZ mode is enabled. This may cause model parameter precision issues "-                "in the RL scenarios. Please set VLLM_ASCEND_ENABLE_NZ=0."-            )-        allocator = CaMemAllocator.get_instance()-        allocator.wake_up(tags=tags)+        return          hidden_size = self.vllm_config.model_config.hf_text_config.hidden_size         model = self.model_runner.model