GLM-5.3 · Training

T04 · Training joint

Valid

Qwen3-8B system training 4dev · Joint Optimization

1.13×PERFORMANCE RATIO
113TOOL EVENTS
1TEXT 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 agentGLM-5.3 · 113 visible calls

InspectEditValidateExecuteBuildProfileRollbackOther
68Inspect
20Edit
19Validate
5Execute
1Profile

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 timeline60 groups · 113 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 and file and log inspection related to source & workspace.

    1 call · #0001–#0001

    ls -l -a <path>echo <flag>echo <val>ls -l -a <path> <n> > <path>head -n <n>
  2. Inspect · Task requirements

    Requested file and log inspection related to task requirements.

    2 calls · #0002–#0003

    Read <path>
  3. Inspect · Source & workspace

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

    1 call · #0004–#0004

    cd <path>find <path> -type <val>sortecho <val><command> <args>cat <val>
  4. Validate · Benchmark & validation setup

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

    1 call · #0005–#0005

    cd <path><command> <args>cat <val>
  5. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    2 calls · #0006–#0007

    cd <path>cat <path>Read <path>
  6. Inspect · Task requirements

    Requested file and log inspection related to task requirements.

    1 call · #0008–#0008

    cd <path>cat <path>echo <val>echo <path>
  7. Inspect · Device memory

    Requested runtime inspection, file and log inspection and environment setup or inspection related to device memory.

    1 call · #0009–#0009

    npu-smi info <n> >& <path>head -n <n>echo <val>envgrep -i -E <val>sort
  8. Inspect · Source & workspace

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

    1 call · #0010–#0010

    date -uecho <flag>ls <path>echo <val>cat <path>ls -R <path> <n> > <path>
    1 more command sketches
    head -n <n>
  9. Validate · Benchmark & validation setup

    Requested workspace file updates, script or workload execution and execution waits related to benchmark & validation setup.

    1 call · #0011–#0011

    cd <path>mkdir -p <path>nohup <val> <path> > <path> <n> >& <path>echo <val>sleep <n>ls -l -a <path> <n> > <path>
    1 more command sketches
    head
  10. Inspect · Dependencies & build setup

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

    1 call · #0012–#0012

    grep -r -n <val> --include <path> <path>head -n <n>echo <val>ls <path>echo
  11. Inspect · Source & workspace

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

    3 calls · #0013–#0015

    cat <path>echo <val>sed -n <val> <path>cd <path>wc -l <path>grep -n <val> <path>
    1 more command sketches
    head -n <n>
  12. Inspect · Benchmark & validation setup

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

    1 call · #0016–#0016

    cd <path>ls -l -aecho <val>tail -n <n> <val>
  13. Inspect · Source & workspace

    1 tool error

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

    3 calls · #0017–#0019

    sed -n <val> <path>cd <path>echo <path>grep -n <val> <path> <n> > <path>grep -n <val> -A <n> <path>sed -n <val>
  14. Inspect · Benchmark & validation setup

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

    1 call · #0020–#0020

    cd <path>wc -c <val> <val>grep -n <val> <val>head -n <n>
  15. Validate · Benchmark & validation setup

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

    1 call · #0021–#0021

    cd <path>grep -n <val> <val>tail -n <n>echo <val>tail -n <n> <val>ls
    2 more command sketches
    cat <path> <n> > <path>head -n <n>
  16. Inspect · Source & workspace

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

    3 calls · #0022–#0024

    cd <path>grep -r -n <val> <path>head -n <n>echo <val>sed -n <val> <path>grep -n <val>
    2 more command sketches
    grep -n <val> -A <n> <path>grep -r -n <val> --include <path> <path> <path> <path> <n> > <path>
  17. Inspect · Parallelism & communication

    Requested file and log inspection and workspace inspection related to parallelism & communication.

    1 call · #0025–#0025

    cd <path>cat <path>echo <val>find <path> -name <val>headcat <val> <path> -name <val>
    1 more command sketches
    head <flag>
  18. Inspect · Benchmark & validation setup

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

    1 call · #0026–#0026

    cd <path>ls -l -agrep -a <val> <val>tail -n <n>echo <val>tail -c <n> <path>
  19. Validate · Benchmark & validation setup

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

    2 calls · #0027–#0028

    sleep <n>cd <path>grep -a <val> <val>tail -n <n>lsecho <val>
    3 more command sketches
    tail -n <n> <val>cat <path>nohup <val> <path> > <path> <n> >& <path>
  20. Inspect · Attention kernels

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

    4 calls · #0029–#0032

    ls <path>echo <val>find <val> -name <path>xargs <val> <flag> <args>head -n <n>sed -n <val> <path>
    5 more command sketches
    grep -n <val> <flag> <args>grep -r -n <val> <path>headls -R <path> <n> > <path>grep -r -n <val> <path> <path> <n> > <path>
  21. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0033–#0033

    sed -n <val> <path>
  22. Execute · Benchmark & validation setup

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

    1 call · #0034–#0034

    <command> <args>free -ghead -n <n>cd <path>lsgrep -a <val> <val> <n> > <path>
    1 more command sketches
    tail -n <n>
  23. Edit · Source & workspace

    Requested code edits related to source & workspace.

    5 calls · #0035–#0039

    Write <path>Edit <path>
  24. Inspect · Benchmark & validation setup

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

    1 call · #0040–#0040

    cd <path>grep -a <val> <val>tail -n <n>echotail -n <n> <val>
  25. Execute · Benchmark & validation setup

    Requested workspace inspection, execution waits and script or workload execution related to benchmark & validation setup.

    3 calls · #0041–#0043

    ls -R <path> <n> > <path>echo <val>ls <path>sleep <n>cd <path>ls <val> <n> > <path>
    2 more command sketches
    python3 -c <script>python3 - <script>
  26. Edit · Source & workspace

    Requested code edits related to source & workspace.

    5 calls · #0044–#0048

    Write <path>Edit <path>
  27. Inspect · Source & workspace

    Requested workspace file updates, script or workload execution and file and log inspection related to source & workspace.

    1 call · #0049–#0049

    chmod <val> <path>cd <path>timeout <n> <val> <path> <val> <n> <n> >& <path>tail -n <n>
  28. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0050–#0050

    Edit <path>
  29. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0051–#0051

    tail -n <n> <path>
  30. Edit · Source & workspace

    Requested code edits related to source & workspace.

    1 call · #0052–#0052

    Edit <path>
  31. Inspect · Source & workspace

    Requested script or workload execution and file and log inspection related to source & workspace.

    1 call · #0053–#0053

    cd <path>timeout <n> <val> <path> <val> <n> <n> >& <path>tail -n <n>
  32. Inspect · Benchmark & validation setup

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

    1 call · #0054–#0054

    cd <path>grep <flag> <args>head -n <n>echo <path>head -n <n> <val>
  33. Inspect · Source & workspace

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

    3 calls · #0055–#0057

    sleep <n>cat <path> <n> > <path>tail -n <n>tail -n <n> <path>echo <val>cd <path>
    3 more command sketches
    grep -n <val> <path>sed -n <val>head -n <n>
  34. Edit · Source & workspace

    Requested code edits and source searches related to source & workspace.

    3 calls · #0058–#0060

    Write <path>cd <path>sed -i <path> <path>grep -n <val> -A <n> <path>
  35. Inspect · Source & workspace

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

    3 calls · #0061–#0063

    cd <path><command> <args>echo <val> >> <path>sleep <n>tail -n <n> <path>echo <flag>
    7 more command sketches
    grep -a <val> <path>tail -n <n>cat <path> <n> > <path>echo <val>cat <path>echogrep <flag> <args>
  36. Execute · Benchmark & validation setup

    Requested workspace file updates, workspace inspection and script or workload execution related to benchmark & validation setup.

    1 call · #0064–#0064

    cp -r <path> <path>ls <path>python3 - <script>grep -n <val> <path>
  37. Inspect · Device memory

    Requested environment setup or inspection, execution waits and source searches related to device memory.

    1 call · #0065–#0065

    cd <path>env <vars> nohup <val> <path> <val> <n> > <path> <n> >& <path>sleep <n>grep -a <val> <path>tail -n <n>echo <val>
  38. Inspect · Source & workspace

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

    5 calls · #0066–#0070

    sleep <n>cat <path>echo <val>tail -n <n> <path>cd <path>grep -n <val> <path>
    5 more command sketches
    head -n <n>headsed -n <val> <path>find <val> -name <path>grep -n <val> -A <n> <path>
  39. Inspect · Optimizer & gradients

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

    2 calls · #0071–#0072

    grep -a <val> <path>tail -n <n>echo <val>grep <flag> <args>ls -l -a <path>head -n <n>
    3 more command sketches
    cd <path>env <vars> nohup <val> <path> <val> <n> > <path> <n> >& <path>sleep <n>
  40. Inspect · Source & workspace

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

    13 calls · #0073–#0085

    sleep <n>cat <path>tail -n <n>echo <val>grep -a -A <n> <val> <path>cd <path>
    11 more command sketches
    grep -r -n <val> --include <path> <path> <path> <n> > <path>head -n <n>grep -r -n <val> --include <path> <path> <path>sed -n <val> <path>grep -r -n <val> --include <path> <path>env <vars> nohup <val> <path> <val> <n> > <path> <n> >& <path>grep -n <val> <path>grep -a <val> <path>tail -n <n> <path>grep -n <val> -A <n> <path>sed -n <val>
  41. Inspect · Device memory

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

    1 call · #0086–#0086

    <command> <args>grep -a <val> <path> <path> <n> > <path>tail -n <n>
  42. Edit · Source & workspace

    Requested code edits related to source & workspace.

    3 calls · #0087–#0089

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

    Requested script or workload execution, execution waits and workspace inspection related to benchmark & validation setup.

    5 calls · #0090–#0094

    cd <path>python3 -c <script>nohup <val> <path> > <path> <n> >& <path>echo <val>sleep <n>ls
    15 more command sketches
    grep -a <val> <val> <n> > <path>tail -n <n>grep <flag> <args>head -n <n>python3 -c <script> <n> > <path>ls <val> <n> > <path><command> <args>grep -a <val> <val> <val> <n> > <path>tail -n <n> <val>tail <flag>ls -l -agrep <val>tail -n <n> <val> <n> > <path>ps <val>grep -c <val>
  44. Validate · Checkpoints & weight state

    1 tool error

    Requested script or workload execution, file and log inspection and execution waits related to checkpoints & weight state.

    2 calls · #0095–#0096

    <command> <args>cd <path>python3 -c <script>echo <path>df -h <path>tail -n <n>
    5 more command sketches
    sleep <n>du <flag> <args>ls <val> <n> > <path>echo <val>grep -a <val> <val> <n> > <path>
  45. Validate · Benchmark & validation setup

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

    1 call · #0097–#0097

    cd <path>nohup <val> -c <path> > <path> <n> >& <path>echo <val>
  46. Validate · Checkpoints & weight state

    Requested execution waits, workspace inspection and script or workload execution related to checkpoints & weight state.

    2 calls · #0098–#0099

    sleep <n>cd <path>ls <val> <n> > <path>python3 -c <script><command> <args>tail -n <n>
    2 more command sketches
    du <flag> <args>grep -a <val> <val> <n> > <path>
  47. Inspect · Checkpoints & weight state

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

    1 call · #0100–#0100

    ps <val>grep -E <val>grep -v <val>awk <val>head -n <n>ls -l -a <path>
    1 more command sketches
    head
  48. Inspect · Source & workspace

    Requested script or workload execution, repository inspection and file and log inspection related to source & workspace.

    1 call · #0101–#0101

    python3 -c <script>git status --shorthead
  49. Validate · Benchmark & validation setup

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

    1 call · #0102–#0102

    cd <path>git status --shortecho <val>grep -a <val> <path> <n> > <path>tail -n <n>ls <path>
    1 more command sketches
    grep -c <val>
  50. Inspect · Checkpoints & weight state

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

    1 call · #0103–#0103

    tail -n <n> <path>grep -a <val> <path>tail -n <n>
  51. Validate · Benchmark & validation setup

    1 tool error

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

    1 call · #0104–#0104

    <command> <args>python3 -c <script>
  52. Inspect · Benchmark & validation setup

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

    1 call · #0105–#0105

    grep -a <val> <path>tail -n <n>ls <path>grep -E <val>
  53. Validate · Benchmark & validation setup

    Requested process termination, runtime inspection and source searches related to benchmark & validation setup.

    1 call · #0106–#0106

    pkill -f <path> <n> > <path>ps <val>grep -c <val>echo <val>
  54. Inspect · Source & workspace

    Requested file and log inspection related to source & workspace.

    1 call · #0107–#0107

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

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

    1 call · #0108–#0108

    grep -a <val> <path>tail -n <n>ls <path> <n> > <path>echo <val>
  56. Edit · Device memory

    Requested code edits related to device memory.

    1 call · #0109–#0109

    Write <path>
  57. Inspect · Device memory

    Requested workspace inspection related to device memory.

    1 call · #0110–#0110

    cd <path>ls<command> <args>
  58. Edit · Device memory

    Requested code edits related to device memory.

    1 call · #0111–#0111

    Write <path>
  59. Inspect · Benchmark & validation setup

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

    1 call · #0112–#0112

    grep -a <val> <path>tail -n <n>ls <path>grep -E <val>ps <val>grep -c <val>
  60. Profile · Checkpoints & weight state

    Requested file and log inspection and script or workload execution related to checkpoints & weight state.

    1 call · #0113–#0113

    cd <path>wc -l <path> <path>python3 -c <script> <n> >& <path>tail -n <n>

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_llm · 2 changed files

Base commit: 72c49a6260c73669678b8f39b1ba41a4789bb555

diff --git a/mindspeed_llm/training/qwen3_8b_4dev.py b/mindspeed_llm/training/qwen3_8b_4dev.pynew file mode 100644index 0000000000000000000000000000000000000000..42ef5072a8d3ff774170b686541177463c6d19d4--- /dev/null+++ b/mindspeed_llm/training/qwen3_8b_4dev.py@@ -0,0 +1,349 @@+# Copyright (c) 2026 Huawei Technologies Co., Ltd. All rights reserved.+"""Foreground supervisor of the four-device Qwen3-8B training system.++The task harness starts this module directly and keeps it in the foreground::++    python -B -m mindspeed_llm.training.qwen3_8b_4dev \\+        --run-spec <spec.json> --device-ids 0,1,2,3 \\+        --master-addr 127.0.0.1 --master-port <port> \\+        --runtime-dir <fresh> --output-dir <task-owned> \\+        [--checkpoint-dir <dir>] [--save-at <n>] [--resume]++The supervisor owns the process graph: exactly one worker process per assigned+Ascend device, all sharing the supervisor's process group, session and standard+streams.  Workers print the Megatron training observations straight onto the+inherited stdout, so the host sees every update as it completes.  The+supervisor stays in the foreground until every worker has finished, tears its+workers down on a signal or a worker failure, and never leaves a child behind.+"""++from __future__ import annotations++import argparse+import errno+import json+import os+import signal+import subprocess+import sys+import time+from pathlib import Path++_REPO_ROOT = Path(__file__).resolve().parents[2]+WORKER_MODULE = "mindspeed_llm.training.qwen3_8b_4dev_worker"+_TEARDOWN_TIMEOUT_S = 60.0++# ---------------------------------------------------------------------------+# Parallel layout and scheduling policy for the four-device system.+#+# Four devices, a 16-sample global batch and an 8.2B-parameter model fix the+# committed work per update; what is left to choose is how that work is spread+# over the devices.  A 2 x 2 pipeline/data grid with one-sample micro-batches+# keeps eight micro-batches in flight, which is the smallest pipeline bubble of+# the layouts that fit in the 64 GiB of a 910B (a flat data-parallel layout+# needs the whole model plus its optimizer state on every device and runs out+# of memory, and a wider micro-batch halves the micro-batch count and doubles+# the bubble).+#+# The grid is still unbalanced as shipped: the last pipeline stage carries the+# 622M-parameter tied output projection on top of its decoder layers, which+# costs about three decoder layers of forward/backward work per micro-batch.+# Handing the first stage one extra decoder layer -- 19 of the 36 -- lines the+# two stages up and shortens the stage time that the 1F1B schedule repeats+# (micro-batches + stages - 1) times per update.+# ---------------------------------------------------------------------------+LAYOUT = {+    "tensor_model_parallel_size": 1,+    "pipeline_model_parallel_size": 2,+    "context_parallel_size": 1,+    "micro_batch_size": 1,+    "num_workers": 0,+    "recompute_activations": False,+    "extra": ("--decoder-first-pipeline-num-layers", "19"),+}+++def _layout() -> dict:+    """Layout policy; the environment override exists for tuning experiments."""+    layout = dict(LAYOUT)+    raw = os.environ.get("QWEN3_4DEV_LAYOUT")+    if raw:+        layout.update(json.loads(raw))+    return layout+++def build_argv(spec, *, train_iters, checkpoint=None, save_at=None, resume=False,+               layout=None) -> list:+    """Translate a task run specification into a Megatron argument vector."""+    model = spec["model"]+    optimizer = spec["optimizer"]+    work = spec["work"]+    if layout is None:+        layout = _layout()+    tensor_parallel = int(layout["tensor_model_parallel_size"])+    pipeline_parallel = int(layout["pipeline_model_parallel_size"])++    argv = [+        "--use-mcore-models",+        "--spec",+        "mindspeed_llm.tasks.models.spec.qwen3_spec",+        "layer_spec",+        "--transformer-impl",+        "local",+        "--distributed-backend",+        "nccl",+        "--tensor-model-parallel-size",+        str(tensor_parallel),+        "--pipeline-model-parallel-size",+        str(pipeline_parallel),+        "--context-parallel-size",+        str(int(layout["context_parallel_size"])),+        "--num-layers",+        str(model["num_layers"]),+        "--hidden-size",+        str(model["model_width"]),+        "--ffn-hidden-size",+        str(model["ffn_width"]),+        "--num-attention-heads",+        str(model["num_attention_heads"]),+        "--group-query-attention",+        "--num-query-groups",+        str(model["num_query_groups"]),+        "--kv-channels",+        str(model["kv_channels"]),+        "--qk-layernorm",+        "--seq-length",+        str(work["sequence_length"]),+        "--max-position-embeddings",+        str(work["sequence_length"]),+        "--micro-batch-size",+        str(int(layout["micro_batch_size"])),+        "--global-batch-size",+        str(work["global_batch_size"]),+        "--train-iters",+        str(train_iters),+        "--lr",+        str(optimizer["learning_rate"]),+        "--min-lr",+        str(optimizer["minimum_learning_rate"]),+        "--lr-decay-style",+        str(optimizer["learning_rate_decay_style"]),+        "--weight-decay",+        str(optimizer["weight_decay"]),+        "--adam-beta1",+        str(optimizer["adam_beta1"]),+        "--adam-beta2",+        str(optimizer["adam_beta2"]),+        "--clip-grad",+        str(optimizer["clip_grad"]),+        "--attention-dropout",+        "0.0",+        "--hidden-dropout",+        "0.0",+        "--seed",+        str(spec["seed"]),+        "--bf16",+        "--mock-data",+        "--tokenizer-type",+        "NullTokenizer",+        "--vocab-size",+        str(model["vocab_size"]),+        "--make-vocab-size-divisible-by",+        "1",+        "--position-embedding-type",+        "rope",+        "--use-rotary-position-embeddings",+        "--rotary-base",+        str(model["rotary_base"]),+        "--disable-bias-linear",+        "--normalization",+        "RMSNorm",+        "--norm-epsilon",+        "1e-6",+        "--swiglu",+        "--attention-softmax-in-fp32",+        "--use-flash-attn",+        "--use-fused-rotary-pos-emb",+        "--use-fused-swiglu",+        "--use-fused-rmsnorm",+        "--no-masked-softmax-fusion",+        "--no-gradient-accumulation-fusion",+        "--use-distributed-optimizer",+        "--reuse-fp32-param",+        "--overlap-grad-reduce",+        "--overlap-param-gather",+        "--use-ascend-coc",+        "--num-workers",+        str(int(layout["num_workers"])),+        "--log-interval",+        "1",+        "--eval-iters",+        "0",+        "--eval-interval",+        str(train_iters),+    ]+    if layout.get("recompute_activations"):+        argv.append("--recompute-activations")+    argv.extend(str(item) for item in layout.get("extra", ()))+    if checkpoint is not None and resume:+        argv.extend(("--load", str(checkpoint)))+    elif checkpoint is not None and save_at is not None:+        argv.extend(+            (+                "--save",+                str(checkpoint),+                "--save-interval",+                str(save_at),+                "--exit-interval",+                str(save_at),+            )+        )+    return argv+++def _device_ids(raw: str) -> list:+    devices = [item.strip() for item in raw.split(",") if item.strip()]+    if not devices or any(not item.isdigit() for item in devices):+        raise SystemExit(f"--device-ids is invalid: {raw!r}")+    if len(devices) != len(set(devices)):+        raise SystemExit(f"--device-ids contains duplicates: {raw!r}")+    return devices+++def _worker_env(devices, master_addr, master_port, rank) -> dict:+    env = {key: value for key, value in os.environ.items() if not key.startswith("TASK_")}+    env.update(+        {+            "RANK": str(rank),+            "WORLD_SIZE": str(len(devices)),+            "LOCAL_RANK": str(rank),+            "MASTER_ADDR": str(master_addr),+            "MASTER_PORT": str(master_port),+            "ASCEND_RT_VISIBLE_DEVICES": ",".join(devices),+            "OMP_NUM_THREADS": env.get("OMP_NUM_THREADS", "8"),+            "PYTHONUNBUFFERED": "1",+        }+    )+    return env+++def _spawn(devices, master_addr, master_port, megatron_argv) -> list:+    argv = [sys.executable, "-B", "-m", WORKER_MODULE, *megatron_argv]+    return [+        subprocess.Popen(+            argv,+            cwd=str(_REPO_ROOT),+            env=_worker_env(devices, master_addr, master_port, rank),+            stdin=subprocess.DEVNULL,+        )+        for rank in range(len(devices))+    ]+++def _terminate(workers) -> None:+    for worker in workers:+        if worker.poll() is None:+            try:+                worker.terminate()+            except OSError as exc:+                if exc.errno != errno.ESRCH:+                    raise+    deadline = time.monotonic() + _TEARDOWN_TIMEOUT_S+    for worker in workers:+        try:+            worker.wait(timeout=max(0.0, deadline - time.monotonic()))+        except subprocess.TimeoutExpired:+            pass+    for worker in workers:+        if worker.poll() is None:+            try:+                worker.kill()+            except OSError as exc:+                if exc.errno != errno.ESRCH:+                    raise+    for worker in workers:+        worker.wait()+++def main(argv=None) -> int:+    parser = argparse.ArgumentParser(description=__doc__)+    parser.add_argument("--run-spec", required=True, type=Path)+    parser.add_argument("--device-ids", required=True)+    parser.add_argument("--master-addr", default="127.0.0.1")+    parser.add_argument("--master-port", required=True, type=int)+    parser.add_argument("--runtime-dir", required=True, type=Path)+    parser.add_argument("--output-dir", required=True, type=Path)+    parser.add_argument("--checkpoint-dir", type=Path, default=None)+    parser.add_argument("--save-at", type=int, default=None)+    parser.add_argument("--resume", action="store_true")+    parser.add_argument("--train-iters", type=int, default=None,+                        help="override the optimizer update count of the run spec")+    options = parser.parse_args(argv)++    for path in (options.runtime_dir, options.output_dir):+        path.mkdir(parents=True, exist_ok=True)++    spec = json.loads(options.run_spec.read_text(encoding="utf-8"))+    train_iters = options.train_iters+    if train_iters is None:+        train_iters = int(spec["work"]["optimizer_updates"])+    megatron_argv = build_argv(+        spec,+        train_iters=train_iters,+        checkpoint=options.checkpoint_dir,+        save_at=options.save_at,+        resume=options.resume,+    )+    devices = _device_ids(options.device_ids)+    workers = _spawn(devices, options.master_addr, options.master_port, megatron_argv)+    terminating = {"active": True}++    def _forward(signum, _frame):  # pragma: no cover - signal path+        if terminating["active"]:+            _terminate(workers)+        sys.exit(128 + int(signum))++    for signum in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP):+        try:+            signal.signal(signum, _forward)+        except (ValueError, OSError):  # pragma: no cover - non-main thread+            pass++    failures = []+    try:+        pending = {worker.pid: (rank, worker) for rank, worker in enumerate(workers)}+        while pending:+            for pid in list(pending):+                rank, worker = pending[pid]+                try:+                    returncode = worker.wait(timeout=0.2)+                except subprocess.TimeoutExpired:+                    continue+                except KeyboardInterrupt:  # pragma: no cover - signal path+                    _terminate(workers)+                    return 130+                del pending[pid]+                if returncode != 0:+                    failures.append((rank, returncode))+                    if terminating["active"]:+                        terminating["active"] = False+                        _terminate([item for _, item in pending.values()])+                    pending.clear()+                    break+    finally:+        terminating["active"] = False+        _terminate(workers)++    if failures:+        rank, returncode = failures[0]+        print(+            f"qwen3_8b_4dev: worker rank {rank} exited with {returncode}",+            file=sys.stderr,+            flush=True,+        )+        return returncode or 1+    return 0+++if __name__ == "__main__":+    raise SystemExit(main())diff --git a/mindspeed_llm/training/qwen3_8b_4dev_worker.py b/mindspeed_llm/training/qwen3_8b_4dev_worker.pynew file mode 100644index 0000000000000000000000000000000000000000..143aee007bb6fc2e9dbdaacbed3d57dec57f7b4a--- /dev/null+++ b/mindspeed_llm/training/qwen3_8b_4dev_worker.py@@ -0,0 +1,79 @@+# Copyright (c) 2026 Huawei Technologies Co., Ltd. All rights reserved.+"""Single-device worker of the four-device Qwen3-8B training system.++The worker is spawned once per assigned Ascend device by+``mindspeed_llm.training.qwen3_8b_4dev`` and receives the Megatron argument+vector derived from the task run specification as its own command line.  The+whole argument vector is handed straight to the public ``pretrain_gpt``+entrypoint, so model, optimizer, data, checkpoint and logging semantics stay+exactly the ones the framework ships with.++Importing this module imports the ``mindspeed_llm`` package first, and that+package applies its Megatron patches while reading ``sys.argv`` -- which is why+the Megatron arguments have to be the worker's own arguments rather than being+reconstructed here after the fact.+"""++from __future__ import annotations++import os+import sys+import threading+import time+from pathlib import Path++_RENDEZVOUS_TIMEOUT_S = 60.0++_REPO_ROOT = Path(__file__).resolve().parents[2]+if str(_REPO_ROOT) not in sys.path:+    sys.path.insert(0, str(_REPO_ROOT))+++def _shutdown() -> None:+    """Leave the worker without paying for interpreter teardown.++    Every optimizer update, checkpoint write and logging observation of the run+    has completed by the time this runs, so the only work left for a normal+    interpreter exit is to garbage-collect tens of gigabytes of device state and+    to tear down the HCCL communicators -- pure shutdown latency that the task+    charges to the measured steady-state window.  A final rendezvous guarantees+    that every rank has finished its committed work, and then the process leaves+    immediately instead.  The rendezvous is bounded so that a rank that somehow+    fell behind cannot hold the run open indefinitely.+    """+    rendezvous = threading.Event()++    def _rendezvous() -> None:  # pragma: no cover - best effort+        try:+            import torch++            if torch.distributed.is_initialized():+                torch.distributed.barrier()+        except Exception:+            pass+        rendezvous.set()++    thread = threading.Thread(target=_rendezvous, daemon=True)+    thread.start()+    rendezvous.wait(_RENDEZVOUS_TIMEOUT_S)+    try:+        sys.stdout.flush()+        sys.stderr.flush()+    except Exception:  # pragma: no cover+        pass+    time.sleep(0.05)+    os._exit(0)+++def main() -> int:+    # Megatron parses sys.argv; pretend to be the public pretraining script.+    sys.argv = [str(_REPO_ROOT / "pretrain_gpt.py")] + sys.argv[1:]+    from pretrain_gpt import main as pretrain_main++    pretrain_main()+    _shutdown()+    return 0+++if __name__ == "__main__":+    raise SystemExit(main())