Skip to content

update(rocm): add mlxcelverse sync, drift checks and fork PR packages - #2078

Merged
inureyes merged 7 commits into
mainfrom
update/issue-1813-mlxcelverse-sync
Sep 30, 2026
Merged

inureyes merged 7 commits into
mainfrom
update/issue-1813-mlxcelverse-sync

Conversation

@inureyes

@inureyes inureyes commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Part of #1813. The issue stays open after this merge: its acceptance item for proposing the fixes to the fork with a recorded link is done by the maintainer submitting the prepared packages by hand.

Summary

Tooling and procedure for the ROCm overlay's two upstreams (the MLX pin and NripeshN/mlx rocm-support), a drift check that catches a core overlay that was already wrong before a bump, and the overlay's fork-side fixes prepared as PRs for the fork. Nothing was submitted to NripeshN/mlx or ml-explore/mlx; the packages are for manual submission.

  • scripts/mlxcelverse/rocm_overlay.py: records (offline), drift (rebuilds each core file as pin + the fork's own change and requires the residual to match the reviewed patches-rocm/CORE_RESIDUAL.diff, each entry noted with its LOCAL_FIXES item; every backend file differing from the fork must be named in LOCAL_FIXES), sync (3-way merges to a new fork commit, carrying local fixes and local-only files), retarget (3-way merges core files to a new pin), plus helpers for check_api_drift.sh (build a candidate tree with make -k, list compile errors and undefined mlx::core symbols).
  • make verify-rocm-overlay (records check plus a synthetic-history test, about 2 s, offline) is in both verify and verify-rocm, so a pin bump that skips the ROCm retarget fails on a Mac too. drift, sync_from_fork.sh and check_api_drift.sh fetch or build and stay manual.
  • docs/mlxcelverse/rocm-overlay.md: pin-bump and fork-sync procedure, including make verify-rocm and a "ROCm overlay" section for bump PR bodies and reports; CONTRIBUTING.md, patches-rocm/README.md, docs/architecture.md point to it.
  • docs/mlxcelverse/upstream/: eleven packages (patch against fork head 75915908, PR title and body, reproduction) covering LOCAL_FIXES items 8, 10 to 14 and 16 to 27 (item 27 from fix(rocm): run CPU-stream BLAS single-threaded over fine-grained memory #2079, with its standalone cblas_sgemm reproducer); index with apply status, the unpackaged items and why (1 to 6 retarget-only, 7 needs Propagate CPU errors to events ml-explore/mlx#3742, 9 no root cause, 15 needs #4035), and a summary of the fork's contribution rules and ml-explore/mlx's AI usage policy (#4331, which forbids AI-written PR descriptions) for the maintainer to decide on.
  • Records: README backend count 106 -> 108; LOCAL_FIXES names the files of items 2, 7, 11 and 20; rope.hip's only difference from the fork, a rewrapped comment, is reverted.

Verification

On gfx1151 (this host):

  • sync_from_fork.sh --check against the fork head (unchanged since the recorded commit) reproduces patches-rocm/ byte for byte, with a freshly fetched cache. That is the acceptance item, but it is trivially true when the commit has not moved; the meaningful run is a forward sync of a copy claiming an older fork commit (53cbdf8c, 34 files changed since), which merged 30 files cleanly and flagged 4 real interactions with local fixes.
  • drift passes: 11 of 15 core files rebuild byte for byte; the residual is items 1 and 24.
  • rocm_overlay_test.sh: 29 checks, including an overlay that silently drops an upstream line, an unrecorded backend change (also one named only by a same-named file elsewhere), a fork conflict, a fork ahead of the pin, a retarget, and a fork tree with a .. entry.
  • All eleven patches apply to the fork head with git apply --check (07 after 05 and 06) and in sequence with git am. Rebased onto main after fix(rocm): run CPU-stream BLAS single-threaded over fine-grained memory #2079; drift and the records check pass with item 27, which the records check now accepts in its section order (27 in the kernel section above build item 26).
  • make verify-versions verify-kernel-dtype-keys verify-kernel-port-dispatch verify-llama-compat verify-rocm-overlay verify-fmt and cargo test --features rocm --test dead_doc_pointers pass.

Not verified: check_api_drift.sh was not run end to end, so the acceptance item "lists the six known breaks against the fork's merge base plus current upstream" is unchecked (check_api_drift.sh --rocm-from fork:75915908dfe5028335d318b10340313744fd3a8d); building the fork's code was not permitted in this session. For the same reason the packages were not compiled against the fork and their reproductions were not run on a fork build; the index lists these as steps before submission. Metal and CUDA: not available here; this change touches no Metal or CUDA code and verify-rocm-overlay is pure Python and git.

Changes during review

  • Review: drift no longer counts a backend file as named in LOCAL_FIXES when only a same-named file elsewhere is (for example mlx/device.cpp for mlx/backend/rocm/device.cpp); .DS_Store is ignored; a GNU-only grep in the test was made portable.
  • Security: every write or delete derived from a git tree goes through a path check, so a fork commit with a .. entry cannot make sync or export-tree write outside the overlay (reproduced with a crafted tree before the fix); tree listings use -z; option-like fetch arguments are refused.

@inureyes inureyes added type:chore Maintenance tasks (build, CI, etc.) priority:medium Medium priority area:core mlxcel-core: MLX FFI, primitives, KV cache, layers platform:linux Linux (CUDA / packaging) specific status:review Under review status:done Completed and removed status:review Under review labels Sep 30, 2026
The ROCm overlay had no tooling for its two upstreams, and its pin-bump check (+/- line counts) could not see a core overlay that was already wrong before a bump.

scripts/mlxcelverse/rocm_overlay.py rebuilds each core file as "pin + the fork's own change" and diffs the overlay against it; the residual must match the reviewed patches-rocm/CORE_RESIDUAL.diff (4 of 15 files, LOCAL_FIXES items 1 and 24). It also syncs to a new fork commit (sync_from_fork.sh, 3-way merges carrying every local fix), retargets core files to a new pin, and check_api_drift.sh builds a candidate tree and lists compile errors and undefined mlx::core symbols. The offline records check and a synthetic-history test run as make verify-rocm-overlay, in verify and verify-rocm, so a pin bump that skips the ROCm retarget fails on any host.

docs/mlxcelverse/ adds the pin-bump and fork-sync procedure and ten PR packages for NripeshN/mlx rocm-support (patch, PR text, reproduction), prepared for manual submission, with a slot for item 27. README backend count is 108; LOCAL_FIXES names the files of items 2, 7, 11 and 20; rope.hip's comment-only drift from the fork is reverted.

Refs #1813
rocm_overlay.py drift requires every backend file that differs from the fork to be named in LOCAL_FIXES.md, but it accepted the bare file name anywhere, including as the tail of another path. mlx/device.cpp therefore named mlx/backend/rocm/device.cpp, and the top-level CMakeLists.txt named mlx/backend/rocm/CMakeLists.txt, so an unrecorded change to the most often edited backend files passed. A short name now counts only on its own, and a bare file name only when no other overlay file shares it; the current LOCAL_FIXES.md still passes because it names every modified file by path.

records and the overlay file walk ignore .DS_Store, which Finder drops into any directory it shows and which would otherwise fail make verify on a Mac as a stray record or an extra core file. The test's negative grep uses -E instead of the GNU-only \| alternation. The procedure doc no longer claims sync --check at the recorded commit can detect an overlay changed outside the procedure: it is an identity by construction, and drift is the check that does.

rocm_overlay_test.sh gains the tail-name and .DS_Store cases (27 checks; the tail-name case fails on the previous tool). make verify-rocm-overlay and an offline drift against the recorded commits pass.

Refs #1813
The overlay CMake comment lists CORE_RESIDUAL.diff among the records, check_api_drift.sh no longer trips set -u on an empty git option array under bash before 4.4, and single-entry package tables say item rather than items.

Refs #1813
sync and export-tree wrote every path listed by `git ls-tree` on a fetched fork commit as `root / path`. Git stores and lists a `..` tree entry verbatim and a fetch does not fsck by default, so a hostile fork tree (or a --fork-url) could make `sync_from_fork.sh` write or delete an arbitrary file, for example mlx/backend/rocm/../../../../.bashrc. Export-tree also wrote overlay files through whatever symlinks the extracted MLX archive contained.

Every write and unlink of a tree-derived path now goes through safe_dest, which rejects absolute paths, empty, `.`, `..` and `.git` components, and any destination that resolves outside the output root. ls_tree and changed_paths use -z so names are read raw instead of C-quoted.

rocm_overlay_test.sh builds a fork commit with a `..` entry via mktree and asserts sync and export-tree both refuse it and nothing lands outside the output directory; against the previous tool the file escaped. make verify-rocm-overlay passes (29 checks, about 2 s).
A commit or ref starting with a dash reached git fetch unchecked and would be parsed as an option such as --upload-pack; it is now rejected. sync --check also removes its scratch copy when the comparison raises.

Refs #1813
Item 27 (#2079, CPU-stream OpenBLAS single-threaded over fine-grained memory) replaces the pending slot as package 11: a patch against fork head 75915908 that applies cleanly on its own and after packages 01 to 10, PR notes, and the standalone cblas_sgemm reproducer. The records check now accepts LOCAL_FIXES numbers grouped by section (27 sits in the kernel section above build item 26) as long as each of 1..N appears once.

Refs #1813
@inureyes
inureyes force-pushed the update/issue-1813-mlxcelverse-sync branch from 82dcd78 to 53c8f12 Compare September 30, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers platform:linux Linux (CUDA / packaging) specific priority:medium Medium priority status:done Completed type:chore Maintenance tasks (build, CI, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant