Repository navigation
Conversation
Signed-off-by: Xingjian Guo <222823329+Gxj230958@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🟡 Changes recommended
The concurrency test still passes when gil_scoped_release is removed, leaving the central GIL-release behavior without regression coverage.
1 open issue
What changed in this PR
This PR releases the Python GIL during native CPU Adam updates, allowing independent optimizer workers and the training thread to make progress concurrently.
Changes:
- Keeps registry lookup and step-state updates under the GIL, then copies optimizer configuration before releasing it for kernel execution.
- Adds concurrent CPUAdam and CPU FusedAdam tests comparing parameters and both moments against PyTorch AdamW over four steps.
| File | Description |
|---|---|
tests/unit/ops/adam/test_cpu_adam.py |
Adds concurrent optimizer correctness checks against AdamW. |
csrc/adam/cpu_adam_impl.cpp |
Copies per-call optimizer state and releases the GIL during native updates. |
Review effort: Balanced
| barrier.wait(timeout=30) | ||
| optimizer.step() |
Signed-off-by: Xingjian Guo <222823329+Gxj230958@users.noreply.github.com>
|
@Gxj230958 please resolve conflicts. Thanks |
Signed-off-by: Xingjian Guo <222823329+Gxj230958@users.noreply.github.com>
|
@sfc-gh-truwase @tjruwase @tohtana @loadams All conflicts resolved. Could you review and approve the CI workflows? Thanks. |

Release the Python GIL during native CPU Adam updates so independent CPU workers
can update concurrently and the training thread can submit gradient downloads
and updated-weight uploads. The optimizer registry lookup and step-state update
retain the GIL; each kernel invocation uses its own copy of the scalar optimizer
configuration.
CPU
FusedAdamshares that configuration across parameter groups, so the changecovers its caller as well as
DeepSpeedCPUAdam. The added concurrent-update testruns two independent optimizers with different hyperparameters and compares
parameters and both moments against PyTorch AdamW over four steps. The separate
ZenFlow update path retains its existing behavior.
test_cpu_adam_native_update_releases_gilindependently verifies Python-threadprogress during the native call for both CPUAdam and CPU FusedAdam. The barrier
test checks numerical correctness; the native-call test checks GIL release.
Removing only
gil_scoped_releasefails both native-call cases while bothbarrier-based numerical cases pass.
The open CPUAdam/GIL pull-request and issue searches on November 8, 2026 found
no existing change implementing this native-update GIL release.
Complete training measurements
Public pretrained Qwen3-0.6B trains with BF16 parameters and FP32 CPU AdamW
master weights and moments. A bounded four-worker pipeline uses 8 MiB buckets,
eight OpenMP threads per worker and affinity to 48 physical cores on the NPU's
local NUMA node. Both variants use the same native compiler flags, sequence
length 256, microbatch one, two-way accumulation and global clipping at 1.0.
The public document inputs are separate from calibration inputs.
Each entry is the median of six complete training steps after two warmup steps
in a fresh process. Variant order alternates across three paired seeds. Loading,
optimizer construction and compilation precede timing.
The median paired speedup is 1.151×. Peak process CPU RSS is at most
8.577 GiB for either variant. All paired gradient norms match exactly, and the
maximum same-input loss difference across the 24 warmup/measured step pairs is
4.77e-7. These throughput measurements exercise concurrent CPUAdam throughthe bucket pipeline; the ZeRO engine comparison below validates updates.
Validation
Hardware: two Intel Xeon Platinum 8468 sockets and one Ascend 910B2C, with
driver 25.0.rc1.1, CANN 8.5.1, PyTorch 2.9.0 and torch-npu
2.9.0.post1+gitdc51c2d. Submission validation uses DeepSpeed
0.19.10+02f7978, based on master revision02f7978481cb3d3297f111c02b16d768b890b256. The paired training measurementsuse revision
1a956270f42fbe7ffa485fdff45499eb77318469; the native CPU Adamsources are unchanged between these revisions.
5dc44e8453df8d02139c2a761aec4d2f4983b451plus this change, including upstream gradient scaling and BF16 parameter-copy
coverage: strict Adam/AdamW state updates, concurrent
CPUAdam/CPU FusedAdam updates, native-update GIL release, unsupported AMSGrad
rejection and preservation of optimizer-state dtypes across checkpoint restoration.
during CPUAdam and CPU FusedAdam native calls. Arguments and tensors are
prepared before observation, and a longer interpreter switch interval excludes
bytecode scheduling around the call. Observation uses at most 20 calls and a
five-second deadline checked between calls, with bounded thread waits.
pybind11::gil_scoped_release release;removed produces two expectedthread-progress assertion failures; both concurrent numerical tests still pass.
three-way gradient accumulation, global clipping, pipeline depths one and
three, and checkpoint restore. Maximum tested FP32 weight error:
4.47e-8.passes four accumulated updates. Maximum reference weight difference:
0.00048828125.The focused tests can be selected in a CPU DeepSpeed installation with:
The CI selector requests the complete
tests/unit/v1scope for the C++ change.The CPU workflow also runs
tests/unit, which includes the added regression.Limitations
Device integration covers single-rank Ascend BF16 CPU offload and the FP32/BF16
optimizer reference cases above. ZeRO stages 1/3, multi-rank execution, FP16,
CUDA, XPU and other accelerators were not measured. Short training comparisons
establish update agreement and execution cost; they do not establish downstream
convergence.