Repository navigation
fix: stop parallel MLX lib test aborts and lint examples in CI - #3674
Merged
Merged
Conversation
#3624 added ServerConfig::diffusing_interval without a runtime-settings classification, so server_config_schema_classifies_all_117_fields fails on main (118 declared fields, 117 classified) and every settings-schema test that walks the read-only table panics on the unknown field. Classify it as read-only with the worker reason (the diffusion worker takes the interval at spawn), expose its startup value as an integer, list it in the read-only field fixture, and give the WebUI a startup label. Refs #3660
… buffer In builds without NDEBUG, MLX's CUDA allocator tracks live allocations so CommandEncoder::verify_graph can reject a graph that registered freed memory. move_to_unified_memory and move_to_device_memory freed the old pointer and only then called swap_allocation. Between the two, another thread could be handed the freed address and track it, and the late swap then moved that thread's live entry to the new pointer. Its next verify_graph aborted the process with "invalid memory registered when calling <Primitive>::eval_gpu" although no memory was invalid. Building an array of a page or more from host data takes this path, so parallel lib tests hit it even when only one thread was evaluating. Overlay mlx/backend/cuda/allocator.cpp from the pinned commit with the swap moved ahead of the free. Release builds do not track allocations and are unaffected. Refs #3660
Lib tests that evaluate MLX arrays or read them back now take mlx_test_guard() as their first statement, so they no longer run concurrently with other GPU tests under cargo test's default thread count. Helpers that took the default-device lock or the guard after fixture weights were built (merge and host-preprocessor cpu_device, switch_layers metal_kernel_or_skip, dinov2 attention_routing, the pipeline last-row helper) now take the guard themselves or leave it to a caller that takes it first, and the sanitize tests take the guard before the env lock in every test. tests/mlx_test_guard_coverage.rs gains a second scan reusing parse_fns, body_end and the shared walker: a lib test that reaches an eval or host readback call, directly, through a test helper in the same file, or through a uniquely named helper in a test-support module, must take the guard before the first such call. Method and associated-function calls, comments, strings and production functions are not followed by name, which keeps CPU-only tests out. The CI clippy step adds --examples; examples reuse the lib's check output and feature-gated ones are skipped. Refs #3660
`cargo clippy -p mlxcel --lib --tests -- -D warnings` fails on main: #3654 wrote two CLIP std constants with more digits than f32 holds (clippy::excessive_precision), and #3655 multiplies by one in a token count (clippy::identity_op). Truncate the constants to the digits f32 keeps (the values are bit-identical) and drop the factor. Refs #3660
#3673 added MLXCEL_TEST_QWEN35_MTP_BASE in the qwen3_5_mtp drafter tests without documenting or allowlisting it, so the env-var-docs gate fails on main. It is the checkpoint path of an opt-in real-model test, the same as its MLXCEL_TEST_QWEN35_MTP_DRAFTER sibling, so it joins that allowlist group. Refs #3660
…xture The checked string fixture in tests/fixtures/webui/strings.json must list every key the feature string modules declare. This branch added settings.startup.diffusing_interval and #3676 added settings.startup.swa_full on main, but neither entry reached the fixture, so the WebUI drift and shell tests failed on the merged tree. Both entries now sit next to the same neighbours as in startup-strings.ts. The full WebUI vitest suite (858 tests) and the WebUI contract check pass. Refs #3660
The embedded WebUI bundle under src/webui/assets carries a source digest, and the diffusing_interval startup string changed the WebUI sources, so build_bundle.py --verify reported a stale manifest. Rebuilt with node 26.5.1 and pnpm 12.23.0 as CI pins them; build_bundle.py --verify passes. Refs #3660
This was referenced Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Parallel
cargo test --libaborted with "invalid memory registered when calling ::eval_gpu". Guarding every MLX-evaluating test was not enough: the abort kept firing with only one thread inside MLX (gdb thread dumps at the abort showed the other test threads in CPU code). The root cause is a race in MLX's debug-only CUDA allocation tracker, fixed here in an overlay. The tests are also guarded and a coverage scan keeps them that way.Root cause (MLX CUDA allocator)
In builds without
NDEBUG(a plaincargo test),move_to_unified_memoryandmove_to_device_memoryfreed the old pointer and only then calledswap_allocation. In between, another thread could be handed the freed address and track it; the late swap then moved that thread's live entry to the new pointer, and that thread's nextverify_graphaborted although no memory was invalid. Building any array of a page or more from host data goes throughmove_to_device_memory, so any test creating arrays could trigger it. New overlayoverlays/cuda/mlx/backend/cuda/allocator.cpp(base5a48f9cc) moves the swap ahead of the free. Release andtest-fastbuilds do not track allocations and were never affected, which is why the gates never saw it.Guards and scan
mlx_test_guard()as their first statement, including every test named in the issue. Helpers that took the device lock or the guard after fixture weights were built now take the guard themselves or leave it to a caller that takes it first. The sanitize tests now take the guard beforeenv_lock()everywhere, so the two locks are always acquired in the same order.tests/mlx_test_guard_coverage.rsaddsmlx_evaluating_lib_tests_take_mlx_test_guard, reusingparse_fns/body_end. Triggers:eval/.eval()/try_eval/eval_all/async_eval,item_*, raw-byte readbacks andarray_to_vec_f32, followed through test helpers in the same file and uniquely named helpers in*test_support*/testing.rs. The guard (or a guard-taking helper) must come before the first trigger. Method calls, associated functions, comments, strings and production functions are not matched by name, so CPU-only tests stay out. The allowlist is empty. The self-test iseval_scanner_flags_readbacks_and_accepts_guard_helpers.Examples lint
examples/xla_kimi_linear_oracle.rswas already fixed by #3636.cargo clippy -p mlxcel --lib --tests --examplesis clean, and the incremental cost is about a second because examples reuse the lib check and feature-gated ones are skipped, so the CI clippy step now passes--examples.Fixes for main breakage
These landed on main while this PR was open, and the verification needs them:
diffusing_intervalsettings classification (#3624), theFAMILY_ORDERentry for LLaVA-OneVision (#3651), two clippy lints (#3654, #3655), and guards for two new tests (#3654, #3657).Test plan
gpu-lock run --tag mlx-parallel-tests -- env RUST_MIN_STACK=16777216 cargo test --features cuda --lib -- --test-threads=4aborted (AddMM/AsType/Matmuleval_gpu) at base and in 4 runs with guards only.14080 passed; 0 failed; 272 ignored(about 550 s), no aborts. One confirmation run after the final rebase onto main also passed (14098 passed; 0 failed; 272 ignored).cargo test --test mlx_test_guard_coverage,cargo test --bin mlxcel family_order,cargo fmt --check,cargo clippy -p mlxcel --lib --tests --examples -- -D warnings, and thescripts/cicontract checks (including the WebUI contract).The issue's command omits
--features cuda. Without it MLX builds with no GPU backend, soeval_gpuand the allocator tracker never run and the abort cannot occur. All runs above add--features cuda.Closes #3660