Repository navigation
fix(hf): rebuild CUDA-only kernels for a CPU-only resolved map (#5579) - #5657
Merged
Merged
Conversation
`SUPPORTS_CPU_OFFLOAD` means "safe when Accelerate runs the layer on a GPU execution device", not "safe to execute on CPU". On ROCm, `from_pretrained(device_map="auto")` with a `max_memory` that leaves the model on CPU resolves to an all-CPU map; AUTO had picked `AwqGEMMTritonLinear`, the reselect filter skipped every module because of that flag, and the first forward handed CPU tensors to Triton: ValueError: Pointer argument (...) cannot be accessed from Triton (cpu tensor?) Keep the flag's meaning but honour it only when the resolved map actually has a non-CPU execution device. With no GPU entry, rebuild every CPU/disk-placed kernel that does not declare DEVICE.CPU (or DEVICE.ALL) in `SUPPORTS_DEVICES`; kernels that declare CPU support are left alone. CUDA behaviour is unchanged (Marlin lacks the flag, Triton layers keep their GPU execution device). Adds tests/test_hf_bridge_cpu_only_reselect_5579.py (CPU-only, 8 nodes; 4 fail on clean main): CPU-only and disk-only maps rebuild a Triton-like kernel, a GPU-bearing map keeps it, CPU/ALL-device kernels are kept, and a kernel without the declaration still rebuilds.
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.
What
On ROCm,
AutoModelForCausalLM.from_pretrained(<AWQ-GEMM ckpt>, device_map="auto", max_memory={"cpu": "30GiB"})keepsAwqGEMMTritonLinearfor every layer. The resolved map is all-CPU, so Transformers dispatches on CPU and nothing moves the layer to the GPU; the first forward then fails withValueError: Pointer argument (...) cannot be accessed from Triton (cpu tensor?).hf_gptqmodel_reselect_offloaded_kernelsskipped those modules becauseAwqGEMMTritonLinear.SUPPORTS_CPU_OFFLOAD = True. That flag means "safe when Accelerate offloads the layer to a GPU execution device", which does not hold when the map has no GPU entry. CUDA happened to work only because Marlin lacks the flag.Fix
_device_map_has_execution_device(map): true when any resolved entry is a GPU ordinal / non-CPU device (0,"cuda:0",torch.device("cuda", 0);"cpu","disk",Noneare not)._kernel_supports_cpu(kernel):DEVICE.CPUorDEVICE.ALLinSUPPORTS_DEVICES.SUPPORTS_CPU_OFFLOADonly when the map has an execution device. With a CPU-only map it rebuilds every CPU/disk-placed kernel that does not declare CPU support. Kernels that declare CPU are left alone; GPU-bearing maps behave exactly as before.Tests
New
tests/test_hf_bridge_cpu_only_reselect_5579.py(CPU-only, 8 nodes; 4 fail on cleanmain):{"": "cpu"},torch.device("cpu")) and disk-only maps rebuild a Triton-like kernel;{"model.layers.0": 0, "model.layers.1": "cpu"}) keeps it;_device_map_has_execution_deviceunit cases.Verification
tests/test_hf_bridge_cpu_only_reselect_5579.py-> 8 passed.tests/test_hf_bridge_cpu_offload_5022.py-> 23 passed, 1 failed withCUDA_HOMEunset (Marlin JIT); the same test fails identically on cleanmainin this environment.tests/test_hf_bridge_thirdparty_offload_5262.py+tests/test_post_init_payload_5261.py-> 16 passed, 13 failed, all 13 the same pre-existing MarlinCUDA_HOMEJIT error.bash format/check.shclean.Not verified locally
No ROCm device here, so the gfx1201 end-to-end load is not re-measured. The unit tests pin the filter decision that caused the crash.