Skip to content

feat(install): add Intel GPU (XPU/SYCL) auto-detection and llama.cpp SYCL compilation - #9084

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
jischebeck:feat/intel-gpu-xpu-support
Oct 5, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
jischebeck:feat/intel-gpu-xpu-support

Conversation

@jischebeck

@jischebeck jischebeck commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR introduces automatic detection of Intel GPUs (non-mac Linux hosts) and configures the environment to use Intel XPU PyTorch wheels and compile llama.cpp with Intel SYCL support.

Focus is on minimal changes, instead of adding Intel GPU as full GPU candidate.

Changes Included

  1. Intel GPU Probing & Detection:

    • Added _has_intel_xpu_gpu() which checks for oneAPI tools (sycl-ls, xpu-smi) and PCI device IDs (0x8086 vendor, 0x03* VGA class).
    • Restructured fallbacks in get_torch_index_url() to check for an Intel GPU before defaulting to CPU-only PyTorch (crucial on hybrid GPU systems, e.g., AMD iGPU + Intel dGPU).
    • Updated status output in the installer summary to output Intel GPU (XPU) when routed.
  2. Llama.cpp SYCL Support:

    • Enabled -DGGML_SYCL=ON -DGGML_SYCL_F16=ON CMake options in setup.sh when an Intel card is present.
    • Configured CMake C/C++ compiler targets to oneAPI's icx/icpx if available.

Verification Done

  • Confirmed correct resolution of xpu wheels on non-mac Linux systems with Intel GPUs (bypassing unconfigured AMD iGPU nodes).

Fixes #8931

chatgpt-codex-connector[bot]

This comment was marked as outdated.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed studio/setup.sh has no Intel vendor probe today and the llama.cpp build has no SYCL path, so the direction here is right, but this also bundles a diffusers archive download cache in studio/install_python_stack.py and reroutes the Darwin and non-x86_64 fallbacks to the xpu index, which publishes no macOS or aarch64 wheels. Could you split out the diffusers caching and keep the xpu fallback to x86_64 Linux only?

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@Imagineer99

Copy link
Copy Markdown
Member

Addressed the maintainer scope request in c56afce: the unrelated Diffusers cache change has been removed from this PR, while automatic XPU routing remains restricted to supported Linux x86_64/Python combinations.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from jischebeck Aug 19, 2026
@unslothai unslothai deleted a comment from jischebeck Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
chatgpt-codex-connector[bot]

This comment was marked as outdated.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 1a284d0b61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jischebeck

Copy link
Copy Markdown
Contributor Author

Confirmed studio/setup.sh has no Intel vendor probe today and install.sh only reaches the xpu index through an explicit pin, and the fallback is now correctly limited to Linux x86_64 with a supported interpreter. One small thing: in install.sh the new helper lands between the comment block for _amd_gpu_present_via_pci and that function, so could you move it above or below that comment?

I moved the intel code down, so that the AMD comment is matching with the main code. Unfortunately my correction for the whisper.cpp compilation was added too, I can post it in a separate pr if required.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the helper now sits clear of the _amd_gpu_present_via_pci comment block and that main still routes Intel hosts to CPU wheels without an explicit pin, so this covers the gap in #8931; could you split out the whisper.cpp UNSLOTH_WHISPER_FORCE_COMPILE message change, and confirm what an AMD plus Intel iGPU host (device IDs 0x7d or 0x64 series) now gets where it previously took the CPU index?

@danielhanchen

Copy link
Copy Markdown
Member

Thanks for moving the Intel helper and keeping the XPU fallback to Linux x86_64. Could you move the scripts/build_whisper_cpp.sh change into its own PR so this one stays on XPU detection and the SYCL build?

mahiatlinux added a commit to goodmai/unsloth that referenced this pull request Sep 25, 2026
The torch.xpu block in _get_gpu_memory is never reached on a Studio Intel
install, which runs the Vulkan llama.cpp build, and where it is reached it
feeds XPU ordinals to placement that pins through CUDA_VISIBLE_DEVICES.
--force-global-env is ignored before a subcommand and duplicates
UNSLOTH_TORCH_INDEX_FAMILY=xpu and running studio/backend/run.py directly.
The build doc says a ~/.local/bin wrapper is picked up automatically, but
Studio checks PATH only after its own managed llama.cpp. Intel SYCL support
for Studio is tracked in unslothai#8931 and unslothai#9084.
mahiatlinux added a commit that referenced this pull request Sep 26, 2026
…#11907)

* Export: add save_pretrained_openvino and push_to_hub_openvino support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* CLI: add --force-global-env to studio launcher

* style: fix ruff formatting for --force-global-env

* fix: detect Intel XPU in llama.cpp GPU memory probe

* style: fix ruff formatting for llama_cpp.py (Intel XPU patch)

* docs: add instructions for Intel Arc SYCL compilation

* docs: add wrapper script instructions for Intel Arc SYCL build

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Drop the Studio XPU probe, --force-global-env and INTEL_ARC_BUILD.md

The torch.xpu block in _get_gpu_memory is never reached on a Studio Intel
install, which runs the Vulkan llama.cpp build, and where it is reached it
feeds XPU ordinals to placement that pins through CUDA_VISIBLE_DEVICES.
--force-global-env is ignored before a subcommand and duplicates
UNSLOTH_TORCH_INDEX_FAMILY=xpu and running studio/backend/run.py directly.
The build doc says a ~/.local/bin wrapper is picked up automatically, but
Studio checks PATH only after its own managed llama.cpp. Intel SYCL support
for Studio is tracked in #8931 and #9084.

* Export OpenVINO IR with optimum-cli in a separate process

save_pretrained_openvino failed for every model: optimum-intel reloads the
staged merge in this process and traces it through transformers classes
whose forwards Unsloth has already patched (Llama and Qwen3 read
self.max_seq_length, the vision models hit compiled forwards), so the
TorchScript trace always failed. The merge itself is fine: the same
checkpoint exports cleanly in an interpreter that never imported unsloth.

Merge through unsloth_generic_save for LoRA and full fine-tunes alike, then
run `python -m optimum.commands.optimum_cli export openvino` on the staging
checkpoint with an explicit --task, which the CLI cannot infer from a local
directory. The CLI also writes openvino_tokenizer.xml and
openvino_detokenizer.xml, which openvino_genai pipelines require.

Also:
- None and "fp16" pass --weight-format fp16; with no weight format
  optimum-intel int8-compresses every model over 1B parameters.
- quantization_type and any extra optimum-cli options, now passed as
  keywords, are checked with optimum-intel's own parser before the merge.
- push_to_hub_openvino forwards private, commit_message,
  commit_description, create_pr and revision, and checks the repo first.
- Local exports stage beside the destination instead of in TMPDIR, and the
  whole staging directory is removed, including on failure.
- The child process gets no Hub credential and trusts remote code only
  when the model was loaded through it.

* Remove the unused sentence-transformers OpenVINO shim

Nothing in unsloth/models/sentence_transformer.py calls
unsloth_save_pretrained_openvino; FastSentenceTransformer only wires the
torchao and GGUF exports.

* Run the OpenVINO export tests in CI

tests/saving is excluded from the auto-discovered repo tests, and the
consolidated job only runs the files it lists, so test_openvino_export.py
never ran. The real-export test inside it skips without optimum-intel.

* Check optimum-intel's transformers bounds for the architecture before merging

optimum-intel declares per-architecture transformers bounds and enforces
them only inside the export, after the 16bit merge has been written. Under
Unsloth's default transformers 5.5.0, optimum-intel 2.2.0 refuses
qwen2_vl, qwen2_5_vl, qwen3_vl, qwen3_5 and gemma3_text that way. Read the
bounds first in a short child process (optimum's export registry loads the
OpenVINO runtime) and raise before the merge, as the compressed export does
for llm-compressor's ceiling. Any probe failure defers to the export.

* Warn about a missing OpenVINO tokenizer after the export, not before

A LoRA merge copies the base model's tokenizer even when none is passed,
so the export usually has openvino_tokenizer.xml and the up-front warning
was wrong. Warn when the output actually lacks it, which also covers a
missing openvino-tokenizers install.

* Consolidate the OpenVINO export tests

Same behaviours covered in fewer, denser tests. The real export now uses
hf-internal-testing/tiny-random-LlamaForCausalLM and skips when optimum-intel
is not installed or the model is not reachable.

* Require an explicit task for encoder-decoder OpenVINO exports

Every non-VLM defaulted to text-generation-with-past, so a T5/BART-style
model wrote a full 16bit merge before optimum-cli rejected the task. No
single default fits encoder-decoder models (T5/BART export as
text2text-generation, Whisper as speech recognition), so ask for the task
before merging and honour one passed as task = ....

---------

Co-authored-by: Aleksei Boklag <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maheswar Kumar <[email protected]>
Co-authored-by: mahiatlinux <[email protected]>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…unslothai#11907)

* Export: add save_pretrained_openvino and push_to_hub_openvino support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* CLI: add --force-global-env to studio launcher

* style: fix ruff formatting for --force-global-env

* fix: detect Intel XPU in llama.cpp GPU memory probe

* style: fix ruff formatting for llama_cpp.py (Intel XPU patch)

* docs: add instructions for Intel Arc SYCL compilation

* docs: add wrapper script instructions for Intel Arc SYCL build

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Drop the Studio XPU probe, --force-global-env and INTEL_ARC_BUILD.md

The torch.xpu block in _get_gpu_memory is never reached on a Studio Intel
install, which runs the Vulkan llama.cpp build, and where it is reached it
feeds XPU ordinals to placement that pins through CUDA_VISIBLE_DEVICES.
--force-global-env is ignored before a subcommand and duplicates
UNSLOTH_TORCH_INDEX_FAMILY=xpu and running studio/backend/run.py directly.
The build doc says a ~/.local/bin wrapper is picked up automatically, but
Studio checks PATH only after its own managed llama.cpp. Intel SYCL support
for Studio is tracked in unslothai#8931 and unslothai#9084.

* Export OpenVINO IR with optimum-cli in a separate process

save_pretrained_openvino failed for every model: optimum-intel reloads the
staged merge in this process and traces it through transformers classes
whose forwards Unsloth has already patched (Llama and Qwen3 read
self.max_seq_length, the vision models hit compiled forwards), so the
TorchScript trace always failed. The merge itself is fine: the same
checkpoint exports cleanly in an interpreter that never imported unsloth.

Merge through unsloth_generic_save for LoRA and full fine-tunes alike, then
run `python -m optimum.commands.optimum_cli export openvino` on the staging
checkpoint with an explicit --task, which the CLI cannot infer from a local
directory. The CLI also writes openvino_tokenizer.xml and
openvino_detokenizer.xml, which openvino_genai pipelines require.

Also:
- None and "fp16" pass --weight-format fp16; with no weight format
  optimum-intel int8-compresses every model over 1B parameters.
- quantization_type and any extra optimum-cli options, now passed as
  keywords, are checked with optimum-intel's own parser before the merge.
- push_to_hub_openvino forwards private, commit_message,
  commit_description, create_pr and revision, and checks the repo first.
- Local exports stage beside the destination instead of in TMPDIR, and the
  whole staging directory is removed, including on failure.
- The child process gets no Hub credential and trusts remote code only
  when the model was loaded through it.

* Remove the unused sentence-transformers OpenVINO shim

Nothing in unsloth/models/sentence_transformer.py calls
unsloth_save_pretrained_openvino; FastSentenceTransformer only wires the
torchao and GGUF exports.

* Run the OpenVINO export tests in CI

tests/saving is excluded from the auto-discovered repo tests, and the
consolidated job only runs the files it lists, so test_openvino_export.py
never ran. The real-export test inside it skips without optimum-intel.

* Check optimum-intel's transformers bounds for the architecture before merging

optimum-intel declares per-architecture transformers bounds and enforces
them only inside the export, after the 16bit merge has been written. Under
Unsloth's default transformers 5.5.0, optimum-intel 2.2.0 refuses
qwen2_vl, qwen2_5_vl, qwen3_vl, qwen3_5 and gemma3_text that way. Read the
bounds first in a short child process (optimum's export registry loads the
OpenVINO runtime) and raise before the merge, as the compressed export does
for llm-compressor's ceiling. Any probe failure defers to the export.

* Warn about a missing OpenVINO tokenizer after the export, not before

A LoRA merge copies the base model's tokenizer even when none is passed,
so the export usually has openvino_tokenizer.xml and the up-front warning
was wrong. Warn when the output actually lacks it, which also covers a
missing openvino-tokenizers install.

* Consolidate the OpenVINO export tests

Same behaviours covered in fewer, denser tests. The real export now uses
hf-internal-testing/tiny-random-LlamaForCausalLM and skips when optimum-intel
is not installed or the model is not reachable.

* Require an explicit task for encoder-decoder OpenVINO exports

Every non-VLM defaulted to text-generation-with-past, so a T5/BART-style
model wrote a full 16bit merge before optimum-cli rejected the task. No
single default fits encoder-decoder models (T5/BART export as
text2text-generation, Whisper as speech recognition), so ask for the task
before merging and honour one passed as task = ....

---------

Co-authored-by: Aleksei Boklag <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maheswar Kumar <[email protected]>
Co-authored-by: mahiatlinux <[email protected]>
@danielhanchen danielhanchen self-assigned this Oct 5, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 5, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 5, 2026
@unslothai unslothai deleted a comment from Imagineer99 Oct 5, 2026
@unslothai unslothai deleted a comment from Imagineer99 Oct 5, 2026
@danielhanchen
danielhanchen force-pushed the feat/intel-gpu-xpu-support branch from a33575d to 5a4b404 Compare October 5, 2026 09:33
@danielhanchen

Copy link
Copy Markdown
Member

Thank you so much for the PR and for the work on Intel GPU support, and for patiently going through the review rounds!

We decided not to take the code changes here. The installer and GPU routing in install.sh and studio/setup.sh run on every Linux install, so changes to how we pick the PyTorch index and the llama.cpp backend need to be validated on real hardware across many configurations (NVIDIA, ROCm, hybrid AMD + Intel hosts, machines with and without oneAPI) before we ship them. We would rather handle the Intel XPU auto-detection and the SYCL llama.cpp build on our side, together with Intel hardware testing, than merge it as is. Your PR and the discussion here will be the reference for that work, and #8931 stays open to track it.

So you are still credited, I reduced this PR to a single empty commit authored by you and am merging that, which lists you as a contributor to Unsloth. Thanks again, and we hope to see more contributions from you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Unsloth studio: install for Intel GPU (not only with vulkan llama.cpp)

3 participants