Repository navigation
perf(rocm): stage weights through pinned slot ring and schedule safetensors on GPU - #2485
Merged
Merged
Conversation
…ensors on GPU Bring ROCm Load::eval_gpu and load_safetensors to parity with the CUDA path: - Check (cu::is_available() || rocm::is_available()) in the ROCm safetensors.cpp overlay so load_safetensors schedules Load on Device::gpu instead of falling back to Device::cpu. - Replace per-tensor hipHostMalloc + hipLaunchHostFunc(hipHostFree) in mlx/backend/rocm/load.cpp with four reused 64 MiB hipHostMallocPortable slots per device and per-slot hipEventDisableTiming events, with pageable fallback under MLXCEL_ROCM_PINNED_LOAD=0 (or MLXCEL_CUDA_PINNED_LOAD=0). - Export rocm::load_transfer_stats() in load_staging.h and wire it into weight_load_transfer_stats under MLXCEL_BRIDGE_ROCM_BACKEND. - Update ROCm overlay records and PR #2474 technical reports with gfx1151 measurements.
4 of 6 tasks
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
Follow-up to #2474 (Ref #1564) after validating weight materialization and staging on ROCm (
gfx1151, AMD Radeon 8060S Graphics, ROCm 7.15):load_safetensorson the GPU stream on ROCm:src/lib/mlxcelverse/overlays/rocm/mlx/io/safetensors.cppchecked onlycu::is_available()when selecting the defaultLoadstream, so ROCm builds defaulted toDevice::cpu(Load::eval_cpu), bypassingLoad::eval_gpuand introducing cross-stream CPU-to-GPU fences whenever a loader derived tensors fromLoadarrays. It now checks(cu::is_available() || rocm::is_available()).StagingPoolinmlx/backend/rocm/load.cpp: Replaced per-tensorhipHostMalloc(&out_ptr, nbytes, hipHostMallocDefault)+hipLaunchHostFunc(encoder.stream(), hip_host_free_callback, out_ptr)with four reused 64 MiBhipHostMallocPortableslots per HIP device and per-slothipEventDisableTimingevents, bounding pinned staging memory at 256 MiB per device and eliminating KFD page-pinning churn under eagereval_all.MLXCEL_ROCM_PINNED_LOAD=0(orMLXCEL_CUDA_PINNED_LOAD=0) selects the synchronous pageable fallback.LoadTransferStats): Addedsrc/lib/mlxcelverse/overlays/rocm/mlx/backend/rocm/load_staging.hand wiredrocm::load_transfer_stats()intoweight_load_transfer_statsinsrc/lib/mlxcel-core/cpp/mlx_cxx_ext.cppunderMLXCEL_BRIDGE_ROCM_BACKEND.Measurements (
gfx1151, warm page cache,--no-chat-template -p "The capital of France is" -n 16 --temp 0 --seed 0)hipHostMalloc+pread+hipMemcpyAsync+hipHostFree: 617.22 ms (hipHostMalloc=297.26 ms,pread=156.37 ms,hipMemcpyAsync=47.67 ms,hipHostFree=115.91 ms)StagingPool: 162.98 ms (3.79× faster,read=160.20 ms,wait=0.04 ms,enqueue=1.05 ms)MLXCEL_PROFILE_TTFT=1):[TTFT]upload countersQwen3-0.6B-4bit(704 tensors, 0.34 GB)eager + pinnedeval=85.66ms pinned=704 memcpy=705, prefillweights=0Qwen3-0.6B-4bitlazy + pinnedweights=704/0.34GB upload=68.34ms pinned=704Qwen3-VL-2B-Instruct-4bit(704 text / 315 skipped vision, 0.97 GB)eager + pinnedeval=108.40ms pinned=704 memcpy=706, prefillweights=0Qwen3-VL-2B-Instruct-4bitlazy + pinnedweights=704/0.97GB upload=105.01ms pinned=704Meta-Llama-3.1-8B-Instruct-4bit(743 tensors, 4.52 GB)eager + pinnedeval=407.59ms staging=313.19ms pinned=743 memcpy=749, prefillweights=0Meta-Llama-3.1-8B-Instruct-4biteager + pageableeval=459.69ms pageable=743 memcpy=743Meta-Llama-3.1-8B-Instruct-4bitlazy + pinnedweights=743/4.52GB upload=373.87ms pinned=743 memcpy=749Meta-Llama-3.1-8B-Instruct-4bitlazy + pageableweights=743/4.52GB upload=479.22ms pageable=743Qwen3-30B-A3B-4bit(1,351 tensors, 17.17 GB)eager + pinnedeval=9175.45ms staging=8537.43ms pinned=1351 memcpy=1499, prefillweights=0Qwen3-30B-A3B-4biteager + pageableeval=13424.21ms pageable=1351 memcpy=1351Qwen3-30B-A3B-4bitlazy + pinnedweights=1351/17.17GB upload=9908.50ms pinned=1351 memcpy=1499Qwen3-30B-A3B-4bitlazy + pageableweights=1351/17.17GB upload=12985.53ms pageable=1351Test plan
cargo test --profile test-fast -p mlxcel-core --features rocm -- weight_materialize --test-threads=1(10/10 passed, includingpinned_upload_chunks_and_wraps_the_slot_ringon ROCm)cargo test --profile test-fast -p mlxcel --lib --features rocm -- ttft_profile(7/7 passed)cargo test --profile test-fast -p mlxcel --lib --features rocm -- loading::(371 passed)make verify-rocm-overlay(records + drift + ownership mock passed)scripts/ci/rocm_smoke.sh(passed, 249.61 tok/s)cargo clippy --workspace --all-targets --features rocm -- -D warningsandcargo fmt --all -- --checkeager+pinned,eager+pageable,lazy+pinned, andlazy+pageableonQwen3-0.6B-4bit,Qwen3-VL-2B-Instruct-4bit,Meta-Llama-3.1-8B-Instruct-4bit,gpt-oss-20b-MXFP4-Q4, andQwen3-30B-A3B-4bitRef #1564, #2474