Gemini 3.7 Flash · Training

T03 · Packed DP2

Valid

Qwen3-4B CodeOpt packed DP2 training 2dev · Implementation Optimization

1.23×PERFORMANCE RATIO
202TOOL EVENTS
2TEXT 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 · 202 visible calls

InspectEditValidateExecuteBuildProfileRollbackOther
158Inspect
10Edit
6Validate
2Execute
26Other

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 timeline99 groups · 202 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 · Source & workspace

    Requested workspace inspection related to source & workspace.

    1 call · #0001–#0001

    echo <val>ls -l -a <val>
  2. Inspect · Task requirements

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

    3 calls · #0002–#0004

    Read <path>ls -l -a <path> <path> <path> <path>
  3. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    3 calls · #0005–#0007

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

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

    3 calls · #0008–#0010

    Read <path>
  5. Inspect · Task requirements

    Requested file and log inspection related to task requirements.

    1 call · #0011–#0011

    Read <path>
  6. Inspect · Checkpoints & weight state

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

    1 call · #0012–#0012

    Read <path>
  7. Inspect · Task requirements

    Requested file and log inspection related to task requirements.

    1 call · #0013–#0013

    Read <path>
  8. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0014–#0014

    Read <path>
  9. Other · Source & workspace

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

    2 calls · #0015–#0016

    envgrep <val>truebash <script>
  10. Inspect · Source & workspace

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

    9 calls · #0017–#0025

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

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

    1 call · #0026–#0026

    bash <script>
  12. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0027–#0027

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

    Requested file and log inspection related to source & workspace.

    2 calls · #0028–#0029

    Read <path>
  14. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0030–#0030

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

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

    2 calls · #0031–#0032

    Read <path>ls -l -a <val>
  16. Inspect · Benchmark & validation setup

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

    1 call · #0033–#0033

    Read <path>
  17. Inspect · Source & workspace

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

    1 call · #0034–#0034

    ps <val>grep <val>
  18. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0035–#0035

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

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

    1 call · #0036–#0036

    bash <script>
  20. Inspect · Attention kernels

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

    7 calls · #0037–#0043

    Search <pattern> <path>Read <path>
  21. Inspect · Benchmark & validation setup

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

    1 call · #0044–#0044

    Read <path>
  22. Inspect · Source & workspace

    Requested source searches related to source & workspace.

    1 call · #0045–#0045

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

    Requested task coordination related to source & workspace.

    1 call · #0046–#0046

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

    Requested file and log inspection related to source & workspace.

    1 call · #0047–#0047

    Read <path>
  25. Inspect · Attention kernels

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

    8 calls · #0048–#0055

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

    Requested file and log inspection related to source & workspace.

    2 calls · #0056–#0057

    Read <path>
  27. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    2 calls · #0058–#0059

    Read <path>
  28. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0060–#0060

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

    Requested workspace inspection related to source & workspace.

    1 call · #0061–#0061

    ls -l -t <val>
  30. Inspect · Benchmark & validation setup

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

    1 call · #0062–#0062

    tail -n <n> <path>
  31. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0063–#0063

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

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

    1 call · #0064–#0064

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

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

    1 call · #0065–#0065

    bash <script>
  34. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    3 calls · #0066–#0068

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

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

    1 call · #0069–#0069

    Read <path>
  36. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0070–#0070

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

    Requested workspace inspection related to source & workspace.

    1 call · #0071–#0071

    ls -l -t <val>
  38. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0072–#0072

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

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

    1 call · #0073–#0073

    Read <path>
  40. Inspect · Source & workspace

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

    8 calls · #0074–#0081

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

    Requested source searches related to optimizer & gradients.

    1 call · #0082–#0082

    Search <pattern> <path>
  42. Inspect · Parallelism & communication

    Requested file and log inspection related to parallelism & communication.

    1 call · #0083–#0083

    Read <path>
  43. Inspect · Source & workspace

    Requested source searches related to source & workspace.

    1 call · #0084–#0084

    Search <pattern> <path>
  44. Inspect · Attention kernels

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

    3 calls · #0085–#0087

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

    Requested file and log inspection related to source & workspace.

    2 calls · #0088–#0089

    Read <path>
  46. Inspect · Attention kernels

    Requested source searches related to attention kernels.

    1 call · #0090–#0090

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

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

    9 calls · #0091–#0099

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

    Requested file and log inspection related to attention kernels.

    1 call · #0100–#0100

    Read <path>
  49. Inspect · Source & workspace

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

    8 calls · #0101–#0108

    Search <pattern> <path>Read <path>
  50. Inspect · Benchmark & validation setup

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

    1 call · #0109–#0109

    tail -n <n> <path>
  51. Inspect · Source & workspace

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

    5 calls · #0110–#0114

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

    Requested file and log inspection related to attention kernels.

    3 calls · #0115–#0117

    Read <path>
  53. Inspect · Source & workspace

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

    4 calls · #0118–#0121

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

    Requested file and log inspection related to attention kernels.

    3 calls · #0122–#0124

    Read <path>
  55. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0125–#0125

    Read <path>
  56. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0126–#0126

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

    Requested workspace file updates related to benchmark & validation setup.

    1 call · #0127–#0127

    cp <path> <path>
  58. Execute · Benchmark & validation setup

    Requested workspace file updates related to benchmark & validation setup.

    1 call · #0128–#0128

    cp <path> <path> <n> > <path>true
  59. Inspect · Source & workspace

    Requested workspace inspection related to source & workspace.

    1 call · #0129–#0129

    ls -l -a <val>
  60. Execute · Benchmark & validation setup

    Requested workspace file updates related to benchmark & validation setup.

    1 call · #0130–#0130

    cp <path> <path>
  61. Other · Source & workspace

    Requested repository inspection related to source & workspace.

    1 call · #0131–#0131

    git -C <path> <val> --short
  62. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    3 calls · #0132–#0134

    Read <path>
  63. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0135–#0135

    Edit <path>
  64. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0136–#0136

    Read <path>
  65. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0137–#0137

    Edit <path>
  66. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    2 calls · #0138–#0139

    Read <path>
  67. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0140–#0140

    Edit <path>
  68. Inspect · Attention kernels

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

    3 calls · #0141–#0143

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

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

    3 calls · #0144–#0146

    python3 -c <script>Manage task <task>
  70. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    2 calls · #0147–#0148

    Read <path>
  71. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0149–#0149

    Edit <path>
  72. Inspect · Attention kernels

    Requested file and log inspection related to attention kernels.

    1 call · #0150–#0150

    Read <path>
  73. Edit · Attention kernels

    Requested code edits related to attention kernels.

    1 call · #0151–#0151

    Edit <path>
  74. Other · Source & workspace

    Requested repository inspection related to source & workspace.

    1 call · #0152–#0152

    git -C <path> <val>
  75. Validate · Benchmark & validation setup

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

    1 call · #0153–#0153

    bash <script>
  76. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0154–#0154

    Manage task <task>
  77. Other · Benchmark & validation setup

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

    1 call · #0155–#0155

    bash <script>
  78. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0156–#0156

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

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

    7 calls · #0157–#0163

    Search <pattern> <path>Read <path>
  80. Inspect · Parallelism & communication

    Requested file and log inspection related to parallelism & communication.

    3 calls · #0164–#0166

    Read <path>
  81. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    3 calls · #0167–#0169

    Read <path>
  82. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0170–#0170

    Edit <path>
  83. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0171–#0171

    Read <path>
  84. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0172–#0172

    Edit <path>
  85. Inspect · Source & workspace

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

    8 calls · #0173–#0180

    Read <path>Search <pattern> <path>
  86. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0181–#0181

    Edit <path>
  87. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0182–#0182

    Read <path>
  88. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0183–#0183

    Edit <path>
  89. Other · Source & workspace

    Requested repository inspection related to source & workspace.

    1 call · #0184–#0184

    git -C <path> <val>
  90. Validate · Benchmark & validation setup

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

    1 call · #0185–#0185

    bash <script>
  91. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0186–#0186

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

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

    2 calls · #0187–#0188

    Search <pattern> <path>Read <path>
  93. Inspect · Benchmark & validation setup

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

    2 calls · #0189–#0190

    Read <path>
  94. Inspect · Source & workspace

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

    5 calls · #0191–#0195

    Search <pattern> <path>Read <path>
  95. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0196–#0196

    Edit <path>
  96. Validate · Benchmark & validation setup

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

    1 call · #0197–#0197

    bash <script>
  97. Other · Source & workspace

    Requested task coordination related to source & workspace.

    1 call · #0198–#0198

    Manage task <task>
  98. Other · Benchmark & validation setup

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

    1 call · #0199–#0199

    bash <script>
  99. Other · Source & workspace

    Requested task coordination and repository inspection related to source & workspace.

    3 calls · #0200–#0202

    Manage task <task>git -C <path> <val>git -C <path> <val> --short

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.

mindspeed · 3 changed files

Base commit: df2ea7fad8e43016b0e2edbf7ce16026496df2ae

diff --git a/mindspeed/core/context_parallel/get_batch_utils.py b/mindspeed/core/context_parallel/get_batch_utils.pyindex 5d36ce73907f1ea4d2555c2d89030b8187ca4de1..70299d9b579b9b41e9346552f754ce56e487153d 100644--- a/mindspeed/core/context_parallel/get_batch_utils.py+++ b/mindspeed/core/context_parallel/get_batch_utils.py@@ -49,11 +49,13 @@ def get_ring_degree():   def _broadcast(item):-    if item is not None:+    if item is not None and mpu.get_tensor_model_parallel_world_size() > 1:         torch.distributed.broadcast(item, mpu.get_tensor_model_parallel_src_rank(), group=mpu.get_tensor_model_parallel_group())   def broadcast_dynamic(item):+    if mpu.get_tensor_model_parallel_world_size() == 1:+        return item.npu() if item is not None else None     if item is not None:         item = item.npu()         item_len = torch.tensor(item.numel(), device=torch.cuda.current_device())diff --git a/mindspeed/core/transformer/dot_product_attention.py b/mindspeed/core/transformer/dot_product_attention.pyindex f5106f46088df37151cc3be052d279c84d34f193..1eb038607443068533d3503a59739f2f8afc847e 100644--- a/mindspeed/core/transformer/dot_product_attention.py+++ b/mindspeed/core/transformer/dot_product_attention.py@@ -279,14 +279,28 @@ def dot_product_attention_forward(     else:         if packed_seq_params is not None: # TND             cp_size = mpu.get_context_parallel_world_size()-            actual_seq_qlen = packed_seq_params.cu_seqlens_q.tolist()-            actual_seq_kvlen = packed_seq_params.cu_seqlens_kv.tolist()-            query, key, value = [rearrange(x, 's b h d -> (b s) h d') for x in [query, key, value]]+            actual_seq_qlen = getattr(packed_seq_params, 'cu_seqlens_q_list', None)+            if actual_seq_qlen is None:+                actual_seq_qlen = packed_seq_params.cu_seqlens_q.tolist()+            actual_seq_kvlen = getattr(packed_seq_params, 'cu_seqlens_kv_list', None)+            if actual_seq_kvlen is None:+                actual_seq_kvlen = packed_seq_params.cu_seqlens_kv.tolist()+            if bsz == 1:+                query = query.reshape(seq_length, query.shape[2], query.shape[3])+                key = key.reshape(seq_length, key.shape[2], key.shape[3])+                value = value.reshape(seq_length, value.shape[2], value.shape[3])+            else:+                query, key, value = [rearrange(x, 's b h d -> (b s) h d') for x in [query, key, value]]             shape_order = 'TND'         else: # SBH             actual_seq_qlen = None             actual_seq_kvlen = None-            query, key, value = [rearrange(x, 's b h d -> s b (h d)') for x in [query, key, value]]+            if bsz == 1:+                query = query.reshape(seq_length, 1, -1)+                key = key.reshape(seq_length, 1, -1)+                value = value.reshape(seq_length, 1, -1)+            else:+                query, key, value = [rearrange(x, 's b h d -> s b (h d)') for x in [query, key, value]]             shape_order = 'SBH'         if args.use_fusion_attn_v2:             output = npu_fusion_attention(@@ -320,5 +334,8 @@ def dot_product_attention_forward(                 actual_seq_kvlen=actual_seq_kvlen                 )[0]         if packed_seq_params is not None:-            output = rearrange(output, '(b s) h d -> s b (h d)', s=seq_length, b=bsz)+            if bsz == 1:+                output = output.reshape(seq_length, bsz, -1)+            else:+                output = rearrange(output, '(b s) h d -> s b (h d)', s=seq_length, b=bsz)     return outputdiff --git a/mindspeed/core/transformer/flash_attention/reset_attention_mask/adaptor.py b/mindspeed/core/transformer/flash_attention/reset_attention_mask/adaptor.pyindex cf83901088842333b53425ad794c7da0c3b75ea7..f0e480bce4234ed9bae820e5f261c4e54cc7ceb4 100644--- a/mindspeed/core/transformer/flash_attention/reset_attention_mask/adaptor.py+++ b/mindspeed/core/transformer/flash_attention/reset_attention_mask/adaptor.py@@ -676,9 +676,21 @@ def apply_rotary_pos_emb_thd(         Tensor: Shape [t, h, d]. The input tensor after applying RoPE.     """ -    position_ids = cu_seqlens.position_ids-    block_size, bsz = position_ids.shape-    freqs = freqs[position_ids.view(-1)].reshape(block_size, bsz, 1, -1)+    if args.reset_position_ids:+        cached_freqs = getattr(cu_seqlens, '_cached_rope_freqs', None)+        if cached_freqs is not None:+            freqs = cached_freqs+        else:+            position_ids = cu_seqlens.position_ids+            block_size, bsz = position_ids.shape+            freqs = freqs[position_ids.view(-1)].reshape(block_size, bsz, 1, -1)+            if hasattr(cu_seqlens, 'position_ids'):+                cu_seqlens._cached_rope_freqs = freqs+    else:+        # when args.reset_position_ids is False, use chunk is faster.+        cp_size = parallel_state.get_context_parallel_world_size()+        cp_rank = parallel_state.get_context_parallel_rank()+        freqs = freqs.chunk(cp_size, dim=0)[cp_rank]      return apply_rotary_pos_emb_bshd(t, freqs, rotary_interleaved, multi_latent_attention, mscale) 
mindspeed_llm · 6 changed files

Base commit: 72c49a6260c73669678b8f39b1ba41a4789bb555

diff --git a/megatron/training/utils.py b/megatron/training/utils.pyindex 61a69e140a74acc3caaf982470d0d5266a1d3394..968b13d78294df8bcf4aa0ebdf3dce794a4a9c78 100644--- a/megatron/training/utils.py+++ b/megatron/training/utils.py@@ -212,13 +212,12 @@ def calc_params_l2_norm(model, force_create_fp32_copy=False):  def average_losses_across_data_parallel_group(losses):     """Reduce a tensor of losses across all GPUs."""-    averaged_losses = torch.cat(-        [loss.clone().detach().view(1) for loss in losses])-    torch.distributed.all_reduce(averaged_losses,-                                 group=mpu.get_data_parallel_group())-    averaged_losses = averaged_losses / \-        torch.distributed.get_world_size(group=mpu.get_data_parallel_group())-+    averaged_losses = torch.stack(losses)+    dp_group = mpu.get_data_parallel_group()+    dp_world_size = torch.distributed.get_world_size(group=dp_group)+    if dp_world_size > 1:+        torch.distributed.all_reduce(averaged_losses, group=dp_group)+        averaged_losses = averaged_losses / dp_world_size     return averaged_losses  @@ -230,6 +229,8 @@ def reduce_max_stat_across_model_parallel_group(stat: float) -> float:      We use an all_reduce max since the values have already been summed across optimizer ranks where possible     """+    if mpu.get_tensor_model_parallel_world_size() == 1 and mpu.get_pipeline_model_parallel_world_size() == 1:+        return stat     if stat is None:         stat = -1.0     stat = torch.tensor([stat], dtype=torch.float32, device=torch.cuda.current_device())@@ -246,6 +247,8 @@ def logical_and_across_model_parallel_group(input: bool) -> bool:     """     This function gathers a bool value across the model parallel group     """+    if mpu.get_tensor_model_parallel_world_size() == 1 and mpu.get_pipeline_model_parallel_world_size() == 1:+        return input     if input is True:         input = 1     else:diff --git a/mindspeed_llm/core/models/common/embeddings/rotary_pos_embedding.py b/mindspeed_llm/core/models/common/embeddings/rotary_pos_embedding.pyindex bd2b975cb13f4d801c4b7668fb4c4e0e22d3b015..b2ea829d78636728c6bf47db798256555d1c703d 100644--- a/mindspeed_llm/core/models/common/embeddings/rotary_pos_embedding.py+++ b/mindspeed_llm/core/models/common/embeddings/rotary_pos_embedding.py@@ -255,8 +255,16 @@ def apply_rotary_pos_emb_bshd(         *dims, d = t.shape         t = t.reshape(*dims, d // 2, 2).transpose(-2, -1).reshape(*dims, d) -    cos_ = (torch.cos(freqs) * _mscale).to(t.dtype)-    sin_ = (torch.sin(freqs) * _mscale).to(t.dtype)+    cos_ = getattr(freqs, '_cached_cos', None)+    sin_ = getattr(freqs, '_cached_sin', None)+    if cos_ is None or sin_ is None:+        cos_ = (torch.cos(freqs) * _mscale).to(t.dtype)+        sin_ = (torch.sin(freqs) * _mscale).to(t.dtype)+        try:+            freqs._cached_cos = cos_+            freqs._cached_sin = sin_+        except Exception:+            pass          if args.use_fused_rotary_pos_emb:         mode = 1 if rotary_interleaved else 0@@ -264,7 +272,9 @@ def apply_rotary_pos_emb_bshd(     else:         t = (t * cos_) + (_rotate_half(t, rotary_interleaved) * sin_)     -    return torch.cat((t, t_pass), dim=-1)+    if t_pass.shape[-1] > 0:+        return torch.cat((t, t_pass), dim=-1)+    return t   def apply_rotary_pos_emb_thd(@@ -285,9 +295,15 @@ def apply_rotary_pos_emb_thd(     args = get_args()      if args.reset_position_ids:-        position_ids = cu_seqlens.position_ids-        block_size, bsz = position_ids.shape-        freqs = freqs[position_ids.view(-1)].reshape(block_size, bsz, 1, -1)+        cached_freqs = getattr(cu_seqlens, '_cached_rope_freqs', None)+        if cached_freqs is not None:+            freqs = cached_freqs+        else:+            position_ids = cu_seqlens.position_ids+            block_size, bsz = position_ids.shape+            freqs = freqs[position_ids.view(-1)].reshape(block_size, bsz, 1, -1)+            if hasattr(cu_seqlens, 'position_ids'):+                cu_seqlens._cached_rope_freqs = freqs     else:         # when args.reset_position_ids is False, use chunk is faster.         cp_size = parallel_state.get_context_parallel_world_size()diff --git a/mindspeed_llm/core/models/gpt/gpt_model.py b/mindspeed_llm/core/models/gpt/gpt_model.pyindex d83a185bd2a080924bc0422fe0621e708e17b75a..f601f12e0b59fea79e4ce544f1c30923e09f408a 100644--- a/mindspeed_llm/core/models/gpt/gpt_model.py+++ b/mindspeed_llm/core/models/gpt/gpt_model.py@@ -363,6 +363,8 @@ def gpt_forward_wrapper(fn):             max_actual_seq_len = max(max_actual_seq_len, actual_seq_len_list[i] - actual_seq_len_list[i - 1])         packed_seq_params.max_seqlen_q = max_actual_seq_len         packed_seq_params.max_seqlen_kv = max_actual_seq_len+        packed_seq_params.cu_seqlens_q_list = actual_seq_len_list+        packed_seq_params.cu_seqlens_kv_list = actual_seq_len_list          q_index, kv_index = compute_qkv_index(actual_seq_len_list)         packed_seq_params.q_index = q_indexdiff --git a/mindspeed_llm/training/training.py b/mindspeed_llm/training/training.pyindex 66cfad6ad3511eda039cde69f087680f1315304e..9ac319b22cc15d0fdc1d452b4567dbf00cf51f6f 100644--- a/mindspeed_llm/training/training.py+++ b/mindspeed_llm/training/training.py@@ -595,6 +595,8 @@ def train(forward_step_func, model, optimizer, opt_param_scheduler,             raise ValueError('Manual garbage collection interval should be larger than or equal to 0.')         gc.disable()         gc.collect()+    else:+        gc.disable()      total_flops = 0.0     num_microbatches = get_num_microbatches()diff --git a/mindspeed_llm/training/utils.py b/mindspeed_llm/training/utils.pyindex c779adfcf9140eff6e1cae1ac28f45027763ff74..ea5cc2ebfa3ee1cd85a118a99c88e2da791878f1 100644--- a/mindspeed_llm/training/utils.py+++ b/mindspeed_llm/training/utils.py@@ -496,7 +496,7 @@ def get_batch_on_this_tp_rank(data_iterator):     args = get_args()      def _broadcast(item):-        if item is not None:+        if item is not None and mpu.get_tensor_model_parallel_world_size() > 1:             torch.distributed.broadcast(item, mpu.get_tensor_model_parallel_src_rank(),                                         group=mpu.get_tensor_model_parallel_group()) diff --git a/pretrain_gpt.py b/pretrain_gpt.pyindex 5a8506bb3f73e23ca5e1c1e2562d0a861c433cfb..99ae8ec2903ea1ab78b19bbc8673091cf784a0fd 100644--- a/pretrain_gpt.py+++ b/pretrain_gpt.py@@ -304,6 +304,14 @@ def main():              ModelType.encoder_or_decoder,              forward_step) +    import sys+    if torch.distributed.is_initialized():+        torch.distributed.barrier()+        torch.distributed.destroy_process_group()+    sys.stdout.flush()+    sys.stderr.flush()+    os._exit(0)+  if __name__ == "__main__":     main()