ITADN

XPU: `from_pretrained(device_map=...)` fails under WSL2 because `caching_allocator_warmup` does not guard `mem_get_info`

#48127Openstudioego 创建于 2 天前
S
studioegocommented
### System Info ``` - `transformers` version: 5.16.0.dev0 - Platform: Linux-6.18.33.2-microsoft-standard-WSL2-x86_64-with-glibc2.43 - Python version: 3.12.14 - Huggingface_hub version: 1.28.0 - Safetensors version: 0.8.0 - Accelerate version: 1.14.0 - Accelerate config: not found - DeepSpeed version: not installed - PyTorch version (accelerator?): 2.13.0+xpu (XPU) - Using distributed or parallel set-up in script?: no - Using XPU in script?: yes - XPU type: Intel(R) Graphics [0xb080] ``` Host: Windows 11 + WSL2, Intel Arc B390 (Panther Lake Xe3 iGPU). ### Who can help? @Cyrilvallez (model loading) @IlyasMoutawwakil (Intel XPU) ### Information - [ ] The official example scripts - [X] My own modified scripts ### Tasks - [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...) - [X] My own task or dataset (give details below) ### Reproduction Any `from_pretrained(..., device_map=...)` onto XPU fails under WSL2: ```python from transformers import AutoModelForCausalLM AutoModelForCausalLM.from_pretrained( "hf-internal-testing/tiny-random-MistralForCausalLM", device_map={"": "xpu:0"}, ) ``` ``` File "src/transformers/modeling_utils.py", line 4428, in _load_pretrained_model caching_allocator_warmup(model, expanded_device_map, load_config.hf_quantizer) File "src/transformers/modeling_utils.py", line 5050, in caching_allocator_warmup free_device_memory, total_device_memory = accelerator_module.mem_get_info(index) File "torch/xpu/memory.py", line 209, in mem_get_info return torch._C._xpu_getMemoryInfo(device) RuntimeError: The device (Intel(R) Graphics [0xb080]) doesn't support querying the available free memory. You can file an issue at https://github.com/pytorch/pytorch/issues to help us prioritize its implementation. ``` The underlying query fails on its own: ```python >>> import torch >>> torch.xpu.mem_get_info(0) RuntimeError: The device (Intel(R) Graphics [0xb080]) doesn't support querying the available free memory. ... ``` and `import torch` already warns at startup: ``` torch/xpu/__init__.py:251: UserWarning: Can't initialize Level Zero Sysman ``` ### Expected behavior Model loading should succeed. `caching_allocator_warmup()` is a best-effort speed optimization — its own comment says it exists "to kick off the caching allocator to avoid having to Malloc afterwards". But the `mem_get_info` call at [`modeling_utils.py#L5050`](https://github.com/huggingface/transformers/blob/main/src/transformers/modeling_utils.py#L5050) is unguarded, so when a backend cannot answer the query the exception propagates all the way out of `from_pretrained()`. An optimization failure becomes a hard model loading failure. This is not an exotic corner. WSL2 does not expose the Level Zero Sysman interface, and PyTorch's `_xpu_getMemoryInfo` depends on it, so `torch.xpu.mem_get_info()` fails for **every** Intel GPU under WSL2 — integrated or discrete. The result is that `device_map` onto XPU is unusable on that platform. PyTorch has several open reports of the same underlying gap (pytorch/pytorch#164429, pytorch/pytorch#161403, pytorch/pytorch#164057, pytorch/pytorch#159728, pytorch/pytorch#159027), but it is tracked as a feature request rather than a bug, so a fix there is not imminent. The function already skips warmup for devices it cannot handle — `mps` and `neuron` both `continue` a few lines below. Doing the same when the free-memory query is unavailable would degrade gracefully and unblock these users today, regardless of what PyTorch does later. I have a patch that does this, verified on the hardware above (before: the traceback shown; after: a warning and a successful load). Happy to open a PR if this approach sounds right.
3 条评论