-
Notifications
You must be signed in to change notification settings - Fork 8
Fix miles multi-node NCCL and verbs library resolution #485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
74f3364
cd9bb6d
54a3f01
06c4c07
628741c
ff5d45b
b0e5eab
2e281de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """Import mooncake's TransferEngine only when Miles uses P2P weight transfer. | ||
|
|
||
| On some Modal EFA hosts the runtime bind-mounts the host's libibverbs over | ||
| the system path, and its private ABI (IBVERBS_PRIVATE_*) does not match the | ||
| image's libmlx5 — mooncake's TransferEngine import raises. The import sits at | ||
| module level on miles' actor import chain, so it kills training runs that | ||
| never use it (colocated weight sync runs on Ray IPC; TransferEngine only | ||
| backs the p2p update_weight_from_distributed path). | ||
|
|
||
| Trying and catching that import is not safe: the failed dlopen can leave | ||
| glibc's TLS bookkeeping partially mutated, and a later CUDA/NCCL load aborts | ||
| in ``_dl_allocate_tls_init``. This patch therefore removes the module-level | ||
| import entirely and performs it only inside the P2P setup function. Colocated | ||
| runs never touch mooncake; an actual P2P run gets a clear error at point of use. | ||
|
|
||
| Executed at image-build time via ``python3 <this file>``. | ||
| """ | ||
|
|
||
| import pathlib | ||
|
|
||
| MARKER = "PATCHED_MOONCAKE_IMPORT_TOLERANCE" | ||
|
|
||
| TARGET = pathlib.Path( | ||
| "/root/miles/miles/backends/megatron_utils/update_weight/" | ||
| "update_weight_from_distributed/p2p_transfer_utils.py" | ||
| ) | ||
|
|
||
| OLD_IMPORT = "from mooncake.engine import TransferEngine" | ||
| NEW_IMPORT = "# " + MARKER + ": imported lazily by the P2P setup below" | ||
|
|
||
| OLD_USE = " transfer_engine = TransferEngine()" | ||
| NEW_USE = ( | ||
| " try:\n" | ||
| " from mooncake.engine import TransferEngine\n" | ||
| " except (ImportError, OSError) as exc:\n" | ||
| " raise RuntimeError(\n" | ||
| ' "p2p weight transfer requires mooncake\'s TransferEngine, "\n' | ||
| ' "which failed to import on this host (verbs stack mismatch)."\n' | ||
| " ) from exc\n" | ||
| " transfer_engine = TransferEngine()" | ||
|
Comment on lines
+32
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed on the validation boundary. The AWS validation run |
||
| ) | ||
|
|
||
|
|
||
| def _patch_file(target: pathlib.Path) -> None: | ||
| if not target.exists(): | ||
| raise SystemExit( | ||
| f"{target} not found; miles layout changed — re-check the patch." | ||
| ) | ||
|
|
||
| src = target.read_text() | ||
| if MARKER in src: | ||
| print("mooncake import tolerance patch already applied") | ||
| return | ||
|
|
||
| if OLD_IMPORT not in src or OLD_USE not in src: | ||
| raise SystemExit( | ||
| "mooncake import tolerance patch did not match; miles' " | ||
| "p2p_transfer_utils.py has changed. Re-check the import and the " | ||
| "TransferEngine() call site before shipping." | ||
| ) | ||
|
|
||
| src = src.replace(OLD_IMPORT, NEW_IMPORT, 1) | ||
| src = src.replace(OLD_USE, NEW_USE, 1) | ||
| target.write_text(src) | ||
| print("Patched mooncake TransferEngine import to load lazily for P2P only") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| _patch_file(TARGET) | ||
Uh oh!
There was an error while loading. Please reload this page.