diff --git a/omni/comfyui_windows_setup/README.md b/omni/comfyui_windows_setup/README.md index d9321dc5..0afc4636 100644 --- a/omni/comfyui_windows_setup/README.md +++ b/omni/comfyui_windows_setup/README.md @@ -17,10 +17,11 @@ This guide provides step-by-step instructions for setting up a portable ComfyUI ## Overview -This setup script creates a fully portable ComfyUI installation optimized for Intel XPU (Arc GPUs). The installation includes: +This setup script creates a portable ComfyUI directory layout optimized for Intel XPU (Arc GPUs). The installation includes: - **Python 3.12 Embedded** - Self-contained Python environment - **PyTorch with XPU Support** - Intel GPU acceleration +- **omni_xpu_kernel** - Local wheel installed from the llm-scaler build output - **ComfyUI** - AI image generation workflow interface - **Essential Custom Nodes** - Pre-installed plugins for extended functionality @@ -31,6 +32,46 @@ This setup script creates a fully portable ComfyUI installation optimized for In - **Pre-configured** - Ready to use out of the box - **Custom Nodes Included** - Popular extensions pre-installed +## Script Scope And Validated Follow-Up + +`setup_portable_env.bat` does not build `omni_xpu_kernel`. It only consumes a prebuilt local wheel and installs it into the embedded Python environment. + +In the validated Windows flow, the work was split into two parts: + +1. Pre-build `omni_xpu_kernel` separately from `llm-scaler\omni\omni_xpu_kernel` and place the wheel under ``. +2. Run `setup_portable_env.bat` from `llm-scaler\omni\comfyui_windows_setup`. +3. Let the setup script install Python, PyTorch XPU, the prebuilt local wheel, ComfyUI, the patch, custom nodes, and launcher scripts. +4. After the script completes, run manual verification from the embedded Python environment. +5. After the script completes, optionally configure `extra_model_paths.yaml` and run an end-to-end workflow test. + +The shared model directory and the Z-Image-Turbo workflow test were post-install validation steps. They were not created by the setup script itself. + +In the examples below, these placeholders are used: + +```text + workspace root directory + \llm-scaler\omni\comfyui_windows_setup + \llm_scaler_dist + shared model directory used across ComfyUI installs +``` + +### Validated Windows Layout + +The current validated workspace uses the following paths: + +```text +\ComfyUI +\python_embeded +\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl + +``` + +The portable Python executable is: + +```text +\python_embeded\python.exe +``` + --- ## Prerequisites @@ -67,19 +108,19 @@ Clone the LLM Scaler repository to your desired location: git clone https://github.com/intel/llm-scaler.git cd llm-scaler\omni\comfyui_windows_setup ``` - The required files are located in: ``` llm-scaler\omni\ ├── comfyui_windows_setup\ │ └── setup_portable_env.bat └── patches\ - ├── comfyui_for_multi_arc.patch - └── comfyui_gguf_xpu.patch + └── comfyui_for_multi_arc.patch ``` ### Step 2: Run Setup Script +Before running the setup script, make sure the `omni_xpu_kernel` wheel has already been built. The setup script installs that wheel, but it does not build it. + 1. **Right-click** on `setup_portable_env.bat` 2. Select **"Run as administrator"** (recommended) 3. Wait for the installation to complete (15-30 minutes depending on internet speed) @@ -87,11 +128,27 @@ llm-scaler\omni\ The script will automatically: - Download and configure Python 3.12 Embedded - Install PyTorch with Intel XPU support +- Install the local `omni_xpu_kernel` wheel built from `llm-scaler\omni\omni_xpu_kernel` - Clone ComfyUI from official repository - Apply Intel XPU optimization patches - Install essential custom nodes - Create launcher scripts +The setup script expects the local kernel wheel at: + +```text +\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl +``` + +To use a different wheel, set `OMNI_XPU_KERNEL_WHEEL` before running the script: + +```cmd +set "OMNI_XPU_KERNEL_WHEEL=D:\path\to\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl" +setup_portable_env.bat +``` + +If your network cannot reach `python.org`, place the embedded Python package under the local fallback source directory used by the script and rerun setup. The validated installation used a local embedded Python fallback instead of downloading Python from the public site. + ### Step 3: Verify Installation After installation, navigate to the `comfyui_windows_setup` folder and verify that everything is set up correctly: @@ -105,6 +162,34 @@ Expected output: XPU available: True ``` +Verify the local XPU kernels wheel is installed and loadable: + +```cmd +python_embeded\python.exe -c "import omni_xpu_kernel as ok; print(ok.__version__); print(ok.is_available())" +``` + +Expected output: +```text +0.1.0 +True +``` + +You can also verify that ComfyUI itself imports from the embedded environment: + +```cmd +cd ComfyUI +..\python_embeded\python.exe -c "import main; print('ComfyUI main import: OK')" +``` + +The validated environment also showed: + +```text +torch 2.9.0+xpu +torch.xpu.is_available() == True +omni_xpu_kernel 0.1.0 +omni_xpu_kernel.is_available() == True +``` + --- ## Running ComfyUI @@ -121,10 +206,10 @@ run_comfyui.bat ### Disable Smart Memory Mode -For GPUs with Out of Memory (OOM), use the disable smart memory launcher: +For GPUs with Out of Memory (OOM), use the low VRAM launcher created by the script: ```cmd -run_comfyui_disable_smart_memory.bat +run_comfyui_lowvram.bat ``` ### CPU Mode @@ -151,6 +236,23 @@ Once ComfyUI starts, open your web browser and navigate to: http://127.0.0.1:8188 ``` +If port `8188` is already in use, start ComfyUI on another port: + +```cmd +run_comfyui.bat --listen 127.0.0.1 --port 8190 +``` + +The validated manual launch command is: + +```cmd +set "PYTHONNOUSERSITE=1" +set "PYTHONPATH=" +set "PYTHONHOME=" +set "PATH=%CD%\python_embeded;%CD%\python_embeded\Scripts;%CD%\python_embeded\Library\bin;%PATH%" +cd ComfyUI +..\python_embeded\python.exe main.py --listen 127.0.0.1 --port 8190 +``` + --- ## Installed Custom Nodes @@ -163,7 +265,7 @@ The setup script automatically installs the following custom nodes: | **VideoHelperSuite** | Video processing and generation tools | [Kosinkadink/ComfyUI-VideoHelperSuite](https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite) | | **Easy-Use** | Simplified workflow nodes | [yolain/ComfyUI-Easy-Use](https://github.com/yolain/ComfyUI-Easy-Use) | | **ControlNet Aux** | ControlNet preprocessors | [Fannovel16/comfyui_controlnet_aux](https://github.com/Fannovel16/comfyui_controlnet_aux) | -| **ComfyUI-GGUF** | GGUF model format support | [city96/ComfyUI-GGUF](https://github.com/city96/ComfyUI-GGUF) | +| **ComfyUI-GGUF-XPU** | XPU-oriented GGUF model format support | [analytics-zoo/ComfyUI-GGUF-XPU](https://github.com/analytics-zoo/ComfyUI-GGUF-XPU) | | **KJNodes** | Utility nodes collection | [kijai/ComfyUI-KJNodes](https://github.com/kijai/ComfyUI-KJNodes) | | **ComfyUI-CacheDiT** | DiT model inference acceleration via caching | [Jasonzzt/ComfyUI-CacheDiT](https://github.com/Jasonzzt/ComfyUI-CacheDiT) | @@ -215,7 +317,7 @@ comfyui_windows_setup/ │ │ ├── comfyui-videohelpersuite/ │ │ ├── comfyui-easy-use/ │ │ ├── comfyui_controlnet_aux/ -│ │ ├── ComfyUI-GGUF/ +│ │ ├── ComfyUI-GGUF-XPU/ │ │ ├── ComfyUI-KJNodes/ │ │ └── ComfyUI-CacheDiT/ │ ├── models/ # Model files (download separately) @@ -232,6 +334,121 @@ comfyui_windows_setup/ --- +## Portable ZIP Reuse + +This directory can be packaged as a portable ZIP, but the current validated layout is not fully self-contained for arbitrary Windows machines. + +What is already portable: + +- `python_embeded/` is self-contained. +- `ComfyUI/` and the generated launcher scripts use relative paths. +- `run_comfyui.bat`, `run_comfyui_lowvram.bat`, and `run_comfyui_cpu.bat` can run from the extracted directory without reinstalling Python. + +What is not fully self-contained today: + +- The current `ComfyUI\extra_model_paths.yaml` points to ``, which is a machine-specific absolute path in the validated setup. +- The validated Z-Image-Turbo test used models stored outside this directory. +- `omni_xpu_kernel` on Windows still probes Intel oneAPI runtime directories such as `C:\Program Files (x86)\Intel\oneAPI\dnnl\latest\bin` and `C:\Program Files (x86)\Intel\oneAPI\compiler\latest\bin` when importing the native extension. + +Practical recommendation: + +1. If you want a ZIP for direct unzip testing on another machine, copy the required models into `ComfyUI\models\...` inside this directory and remove or rewrite `ComfyUI\extra_model_paths.yaml`. +2. Use a target machine that already has the required Intel GPU driver. If the packaged environment does not include every DLL needed by `omni_xpu_kernel`, the target machine may also need a compatible Intel oneAPI runtime. +3. Treat the ZIP as portable between similarly prepared Intel XPU Windows machines, not as a fully dependency-free package for any clean Windows host. + +For the current workspace, the directory is portable enough for internal testing after fixing the model path assumptions, but it should not yet be described as a completely standalone redistributable package. + +--- + +## Shared Model Directory + +The setup script does not create shared model paths automatically. For multiple ComfyUI checkouts, you can optionally use a shared model directory instead of copying large model files into each installation. The validated shared directory is: + +```text + +``` + +Recommended subdirectories: + +```text +checkpoints +clip +clip_vision +configs +controlnet +diffusion_models +embeddings +loras +text_encoders +upscale_models +vae +vae_approx +``` + +Create `ComfyUI\extra_model_paths.yaml` with: + +```yaml +shared_models: + base_path: + checkpoints: checkpoints + clip: clip + clip_vision: clip_vision + configs: configs + controlnet: controlnet + diffusion_models: diffusion_models + embeddings: embeddings + loras: loras + text_encoders: text_encoders + upscale_models: upscale_models + vae: vae + vae_approx: vae_approx +``` + +The Z-Image-Turbo validation used these model files: + +```text +\text_encoders\qwen_3_4b.safetensors +\vae\ae.safetensors +\diffusion_models\z_image_turbo_bf16.safetensors +``` + +--- + +## Z-Image-Turbo E2E Validation + +This was a manual post-install validation step after the script had completed successfully. The local installation was validated with the official Z-Image-Turbo node chain expanded into a ComfyUI API prompt: + +```text +UNETLoader -> ModelSamplingAuraFlow -> KSampler -> VAEDecode -> SaveImage +CLIPLoader -> CLIPTextEncode -> ConditioningZeroOut +EmptySD3LatentImage -> KSampler +``` + +Validated settings: + +```text +unet_name: z_image_turbo_bf16.safetensors +clip_name: qwen_3_4b.safetensors +clip type: lumina2 +vae_name: ae.safetensors +shift: 3.0 +sampler: res_multistep +scheduler: simple +cfg: 1.0 +steps: 4 +size: 512x512 +``` + +The test output was generated at: + +```text +ComfyUI\output\z_image_turbo_e2e_00001_.png +``` + +The generated PNG was verified as a valid `512x512` image. The first run loaded about 11.7 GB of model weights and completed in about 57 seconds on the validated Intel XPU system. + +--- + ## Troubleshooting ### Common Issues @@ -282,6 +499,34 @@ comfyui_windows_setup/ - Check firewall settings - Try running with VPN disabled (or enabled, depending on your network) +#### 6. ComfyUI-Manager GitHub Timeout During Startup + +**Symptom**: Startup logs show `Cannot connect to host raw.githubusercontent.com` or `Cannot connect to comfyregistry`. + +**Solution**: +- This is usually not fatal for local inference. +- ComfyUI-Manager can fall back to local mode. +- Configure proxy variables if you need Manager online features. + +#### 7. `comfy-aimdo` DLL Warning + +**Symptom**: Startup logs show `comfy-aimdo failed to load`. + +**Solution**: +- This package is NVIDIA-only in the current environment. +- The warning can be ignored for Intel XPU validation. + +#### 8. Port Already in Use + +**Symptom**: Startup fails with `WinError 10048` for `127.0.0.1:8188`. + +**Solution**: +- Use another port, for example `--port 8190`. +- Check the current listener with: + ```powershell + Get-NetTCPConnection -LocalPort 8188 -ErrorAction SilentlyContinue + ``` + ### Getting Help If you encounter issues not covered above: @@ -301,7 +546,7 @@ If you encounter issues not covered above: ### Q: Can I move the installation to another location? -**A**: Yes! The installation is fully portable. Simply move the entire folder to a new location. The relative paths will continue to work. +**A**: Mostly yes for the directory layout itself: the embedded Python environment, ComfyUI checkout, and launcher scripts use relative paths, so the folder can be moved. In the current validated setup, you still need to account for external model paths and, on some systems, additional runtime DLL dependencies as described in [Portable ZIP Reuse](#portable-zip-reuse). ### Q: How do I update ComfyUI? @@ -318,12 +563,14 @@ git stash pop ### Q: Where should I put my model files? -**A**: Place model files in the appropriate subfolders under `ComfyUI/models/`: +**A**: For a single installation, place model files in the appropriate subfolders under `ComfyUI/models/`: - Checkpoints (SDXL, SD1.5, etc.) → `models/checkpoints/` - LoRA models → `models/loras/` - VAE files → `models/vae/` - ControlNet models → `models/controlnet/` +For multiple local ComfyUI installations, prefer the shared directory described in [Shared Model Directory](#shared-model-directory). + ### Q: Can I use this with NVIDIA GPU? **A**: This setup is optimized for Intel XPU. For NVIDIA GPUs, use the standard ComfyUI installation with CUDA support. @@ -344,7 +591,8 @@ git stash pop |-----------|---------| | Python | 3.12.10 | | PyTorch | 2.9.0+xpu | -| ComfyUI | Commit 532e285 | +| omni_xpu_kernel | 0.1.0 local wheel | +| ComfyUI | Commit 64b8457 | | Setup Script | v1.0 | --- diff --git a/omni/comfyui_windows_setup/setup_portable_env.bat b/omni/comfyui_windows_setup/setup_portable_env.bat index 62634929..967a29b3 100644 --- a/omni/comfyui_windows_setup/setup_portable_env.bat +++ b/omni/comfyui_windows_setup/setup_portable_env.bat @@ -23,16 +23,21 @@ set "PIP_EXE=%PYTHON_DIR%\Scripts\pip.exe" set "PYTHON_VERSION=3.12.10" set "PYTHON_EMBED_URL=https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-embed-amd64.zip" set "GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py" +set "PIP_INSTALL_OPTIONS=--retries 10 --timeout 120 --no-warn-script-location" +if not defined PYTHON_EMBED_SOURCE_DIR if exist "%SCRIPT_DIR%..\..\..\omni\comfyui_windows_setup\python_embeded\python.exe" set "PYTHON_EMBED_SOURCE_DIR=%SCRIPT_DIR%..\..\..\omni\comfyui_windows_setup\python_embeded" +if not defined OMNI_XPU_KERNEL_WHEEL set "OMNI_XPU_KERNEL_WHEEL=%SCRIPT_DIR%..\..\..\llm_scaler_dist\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl" REM ComfyUI Git Configuration (matching Dockerfile) set "COMFYUI_REPO=https://github.com/comfyanonymous/ComfyUI.git" -set "COMFYUI_COMMIT=3dd10a59c00248d00f0cb0ab794ff1bb9fb00a5f" +set "COMFYUI_COMMIT=64b8457f55cd7fb54ca7a956d9c73b505e903e0c" set "COMFYUI_PATCH=%PATCHES_DIR%\comfyui_for_multi_arc.patch" echo ============================================ echo Windows Portable Python Environment Setup echo Target: %PYTHON_DIR% echo ComfyUI: git clone + patch +echo omni_xpu_kernel wheel: %OMNI_XPU_KERNEL_WHEEL% +if defined PYTHON_EMBED_SOURCE_DIR echo Python source: %PYTHON_EMBED_SOURCE_DIR% echo ============================================ echo. @@ -79,11 +84,21 @@ echo. REM ============================================ REM Step 1: Download and Extract Python Embeddable REM ============================================ -echo [Step 1/8] Setting up Python Embeddable Package... +echo [Step 1/9] Setting up Python Embeddable Package... if exist "%PYTHON_EXE%" ( echo Python already exists at %PYTHON_DIR% echo Skipping download... +) else if defined PYTHON_EMBED_SOURCE_DIR if exist "%PYTHON_EMBED_SOURCE_DIR%\python.exe" ( + echo Copying existing Python embeddable package from %PYTHON_EMBED_SOURCE_DIR%... + if not exist "%PYTHON_DIR%" mkdir "%PYTHON_DIR%" + powershell -NoProfile -Command "Copy-Item -Path '%PYTHON_EMBED_SOURCE_DIR%\*' -Destination '%PYTHON_DIR%' -Recurse -Force" + if errorlevel 1 ( + echo ERROR: Failed to copy Python embeddable package from %PYTHON_EMBED_SOURCE_DIR% + pause + exit /b 1 + ) + echo Python copied successfully. ) else ( echo Creating python_embeded directory... if not exist "%PYTHON_DIR%" mkdir "%PYTHON_DIR%" @@ -113,7 +128,7 @@ REM ============================================ REM Step 2: Configure Python Path (Enable pip/site-packages) REM ============================================ echo. -echo [Step 2/8] Configuring Python path... +echo [Step 2/9] Configuring Python path... set "PTH_FILE=%PYTHON_DIR%\python312._pth" if exist "%PTH_FILE%" ( @@ -149,11 +164,11 @@ REM ============================================ REM Step 3: Install pip REM ============================================ echo. -echo [Step 3/8] Installing pip... +echo [Step 3/9] Installing pip... if exist "%PIP_EXE%" ( echo pip already installed, upgrading... - "%PYTHON_EXE%" -m pip install --upgrade pip + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% --upgrade pip ) else ( echo Downloading get-pip.py... curl -L -o "%SCRIPT_DIR%get-pip.py" "%GET_PIP_URL%" @@ -174,7 +189,7 @@ if exist "%PIP_EXE%" ( del "%SCRIPT_DIR%get-pip.py" REM Upgrade pip - "%PYTHON_EXE%" -m pip install --upgrade pip + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% --upgrade pip ) echo pip installed successfully. @@ -183,20 +198,47 @@ REM ============================================ REM Step 4: Install PyTorch with Intel XPU Support REM ============================================ echo. -echo [Step 4/8] Installing PyTorch with Intel XPU support... +echo [Step 4/9] Installing PyTorch with Intel XPU support... -"%PYTHON_EXE%" -m pip install torch==2.9.0 torchvision==0.24.0 torchaudio==2.9.0 --index-url https://download.pytorch.org/whl/xpu +"%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% torch==2.9.0 torchvision==0.24.0 torchaudio==2.9.0 --index-url https://download.pytorch.org/whl/xpu if errorlevel 1 ( echo WARNING: Failed to install PyTorch XPU version echo Trying standard PyTorch... - "%PYTHON_EXE%" -m pip install torch torchvision torchaudio + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% torch torchvision torchaudio + if errorlevel 1 ( + echo ERROR: Failed to install PyTorch. + pause + exit /b 1 + ) ) REM ============================================ -REM Step 5: Clone and Setup ComfyUI from Git +REM Step 5: Install omni_xpu_kernel wheel +REM ============================================ +echo. +echo [Step 5/9] Installing omni_xpu_kernel wheel... + +if not exist "%OMNI_XPU_KERNEL_WHEEL%" ( + echo ERROR: omni_xpu_kernel wheel not found: %OMNI_XPU_KERNEL_WHEEL% + echo Build it first from llm-scaler\omni\omni_xpu_kernel, or set OMNI_XPU_KERNEL_WHEEL to a valid wheel path. + pause + exit /b 1 +) + +"%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% --force-reinstall --no-deps "%OMNI_XPU_KERNEL_WHEEL%" +if errorlevel 1 ( + echo ERROR: Failed to install omni_xpu_kernel wheel + pause + exit /b 1 +) + +echo omni_xpu_kernel wheel installed successfully. + +REM ============================================ +REM Step 6: Clone and Setup ComfyUI from Git REM ============================================ echo. -echo [Step 5/8] Setting up ComfyUI from Git... +echo [Step 6/9] Setting up ComfyUI from Git... cd /d "%SCRIPT_DIR%" @@ -229,13 +271,18 @@ if exist ComfyUI ( cd ComfyUI echo Installing ComfyUI requirements... -"%PYTHON_EXE%" -m pip install -r requirements.txt +"%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% -r requirements.txt +if errorlevel 1 ( + echo ERROR: Failed to install ComfyUI requirements. + pause + exit /b 1 +) REM ============================================ -REM Step 6: Apply Intel XPU Patch to ComfyUI +REM Step 7: Apply Intel XPU Patch to ComfyUI REM ============================================ echo. -echo [Step 6/8] Applying Intel XPU patch to ComfyUI... +echo [Step 7/9] Applying Intel XPU patch to ComfyUI... cd /d "%SCRIPT_DIR%\ComfyUI" @@ -260,10 +307,10 @@ if exist "%COMFYUI_PATCH%" ( ) REM ============================================ -REM Step 7: Install Custom Nodes +REM Step 8: Install Custom Nodes REM ============================================ echo. -echo [Step 7/8] Installing Custom Nodes... +echo [Step 8/9] Installing Custom Nodes... cd /d "%SCRIPT_DIR%\ComfyUI\custom_nodes" @@ -290,7 +337,12 @@ if exist comfyui-videohelpersuite ( echo WARNING: Failed to clone ComfyUI-VideoHelperSuite ) else ( cd comfyui-videohelpersuite - "%PYTHON_EXE%" -m pip install -r requirements.txt + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% -r requirements.txt + if errorlevel 1 ( + echo ERROR: Failed to install ComfyUI-VideoHelperSuite requirements. + pause + exit /b 1 + ) cd .. ) ) @@ -306,7 +358,12 @@ if exist comfyui-easy-use ( echo WARNING: Failed to clone ComfyUI-Easy-Use ) else ( cd comfyui-easy-use - "%PYTHON_EXE%" -m pip install -r requirements.txt + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% -r requirements.txt + if errorlevel 1 ( + echo ERROR: Failed to install ComfyUI-Easy-Use requirements. + pause + exit /b 1 + ) cd .. ) ) @@ -322,7 +379,12 @@ if exist comfyui_controlnet_aux ( echo WARNING: Failed to clone comfyui_controlnet_aux ) else ( cd comfyui_controlnet_aux - "%PYTHON_EXE%" -m pip install -r requirements.txt + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% -r requirements.txt + if errorlevel 1 ( + echo ERROR: Failed to install comfyui_controlnet_aux requirements. + pause + exit /b 1 + ) cd .. ) ) @@ -341,7 +403,12 @@ if exist ComfyUI-GGUF-XPU ( ) else ( cd ComfyUI-GGUF-XPU git checkout %GGUF_COMMIT% - "%PYTHON_EXE%" -m pip install -r requirements.txt + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% -r requirements.txt + if errorlevel 1 ( + echo ERROR: Failed to install ComfyUI-GGUF-XPU requirements. + pause + exit /b 1 + ) cd .. ) ) @@ -349,15 +416,28 @@ if exist ComfyUI-GGUF-XPU ( REM --- ComfyUI-KJNodes --- echo. echo Installing ComfyUI-KJNodes... +set "KJNODES_COMMIT=c6ce76d00bb8177d1b0286cad891df08eff5226e" + if exist ComfyUI-KJNodes ( - echo ComfyUI-KJNodes already exists, skipping... + echo ComfyUI-KJNodes already exists, updating to specified commit... + cd ComfyUI-KJNodes + git fetch origin %KJNODES_COMMIT% + git checkout %KJNODES_COMMIT% + cd .. ) else ( git clone https://github.com/kijai/ComfyUI-KJNodes.git if errorlevel 1 ( echo WARNING: Failed to clone ComfyUI-KJNodes ) else ( cd ComfyUI-KJNodes - "%PYTHON_EXE%" -m pip install -r requirements.txt + git fetch origin %KJNODES_COMMIT% + git checkout %KJNODES_COMMIT% + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% -r requirements.txt + if errorlevel 1 ( + echo ERROR: Failed to install ComfyUI-KJNodes requirements. + pause + exit /b 1 + ) cd .. ) ) @@ -373,7 +453,12 @@ if exist ComfyUI-CacheDiT ( echo WARNING: Failed to clone ComfyUI-CacheDiT ) else ( cd ComfyUI-CacheDiT - "%PYTHON_EXE%" -m pip install cache-dit --no-deps + "%PYTHON_EXE%" -m pip install %PIP_INSTALL_OPTIONS% cache-dit --no-deps + if errorlevel 1 ( + echo ERROR: Failed to install cache-dit. + pause + exit /b 1 + ) cd .. ) ) @@ -382,10 +467,10 @@ echo. echo Custom nodes installation complete. REM ============================================ -REM Step 8: Create Launcher Scripts +REM Step 9: Create Launcher Scripts REM ============================================ echo. -echo [Step 8/8] Creating launcher scripts... +echo [Step 9/9] Creating launcher scripts... cd /d "%SCRIPT_DIR%" @@ -459,6 +544,13 @@ echo PyTorch verification: "%PYTHON_EXE%" -c "import torch; print(f'PyTorch version: {torch.__version__}')" "%PYTHON_EXE%" -c "import torch; print(f'XPU available: {torch.xpu.is_available() if hasattr(torch, \"xpu\") else \"N/A\"}')" +echo. +echo omni_xpu_kernel verification: +"%PYTHON_EXE%" -c "import omni_xpu_kernel as ok; print(f'omni_xpu_kernel version: {ok.__version__}'); print(f'omni_xpu_kernel available: {ok.is_available()}')" +if errorlevel 1 ( + echo WARNING: omni_xpu_kernel import verification failed. +) + echo. echo Installed Custom Nodes: dir /b "%SCRIPT_DIR%ComfyUI\custom_nodes" diff --git a/omni/omni_xpu_kernel/WHL_BUILD_INSTALL.md b/omni/omni_xpu_kernel/WHL_BUILD_INSTALL.md index af21b331..4eb4212c 100644 --- a/omni/omni_xpu_kernel/WHL_BUILD_INSTALL.md +++ b/omni/omni_xpu_kernel/WHL_BUILD_INSTALL.md @@ -1,123 +1,319 @@ -# omni_xpu_kernel (llm-scaler) Build and Install Notes +# omni_xpu_kernel Build and Install Notes -This document summarizes how to build the updated omni_xpu_kernel from llm-scaler on Windows using a conda environment, then install it into the ComfyUI embedded Python environment. +This document records the validated Windows flow for building the `omni_xpu_kernel` wheel from `llm-scaler`, installing it into the portable ComfyUI embedded Python environment, and verifying it with an Intel XPU ComfyUI run. -## 1. Prerequisites -- Intel oneAPI Base Toolkit installed -- VS2022 C++ components installed -- conda environment: omni_env -- ComfyUI embedded Python located at: %EMBED_PYTHON_DIR% -- Variables (adjust as needed): - - %WORKSPACE%: workspace root - - %EMBED_PYTHON_DIR%: embedded Python directory (example: %WORKSPACE%\omni\comfyui_windows_setup\python_embeded) - - %LLM_SCALER_DIR%: llm-scaler repo directory (example: %WORKSPACE%\llm-scaler) - - %OUTPUT_DIR%: build output directory (example: %WORKSPACE%\llm_scaler_dist) +## What Was Required To Make The Windows Flow Work -### Variable setup example (cmd) -You can put these variables at the top of your command prompt or script for consistent configuration: +The validated Windows build/install flow depended on these fixes and guardrails: +- Build with the conda environment Python, not a user-site Python. +- Force `PYTHONNOUSERSITE=1` and clear `PYTHONPATH` before importing PyTorch. +- Compile the native extension with `/DNOMINMAX` and `/DWIN32_LEAN_AND_MEAN` to avoid Windows header macro conflicts. +- Link against the XPU PyTorch libraries from the conda environment. +- Register DLL directories at import time so the built `.pyd` files can find PyTorch and oneAPI runtime DLLs on Windows. +- Install the final wheel into the ComfyUI embedded Python with `--no-deps` so the XPU PyTorch stack is not replaced. + +Without those pieces, the common failures were: wrong PyTorch selected during build, native compile errors, and a wheel that built successfully but failed to import on Windows. + +## Validated Local Paths + +The current validated workspace uses: + +```text +Workspace: C:\workspace +Repository: C:\workspace\llm-scaler +Kernel source: C:\workspace\llm-scaler\omni\omni_xpu_kernel +Build script: C:\workspace\llm-scaler\omni\omni_xpu_kernel\scripts\build_llm_scaler_conda.cmd +Wheel output: C:\workspace\llm_scaler_dist +Build log: C:\workspace\build_log.txt +ComfyUI: C:\workspace\llm-scaler\omni\comfyui_windows_setup\ComfyUI +Embedded Python: C:\workspace\llm-scaler\omni\comfyui_windows_setup\python_embeded\python.exe ``` -set "WORKSPACE=C:\workspace" -set "LLM_SCALER_DIR=%WORKSPACE%\llm-scaler" -set "EMBED_PYTHON_DIR=%WORKSPACE%\omni\comfyui_windows_setup\python_embeded" -set "OUTPUT_DIR=%WORKSPACE%\llm_scaler_dist" + +The validated wheel was: + +```text +C:\workspace\llm_scaler_dist\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl ``` -## 2. Build (in conda environment) -Build script location: -- [scripts/build_llm_scaler_conda.cmd](scripts/build_llm_scaler_conda.cmd) +It contains the native Python 3.12 Windows extensions, including `_C.cp312-win_amd64.pyd` and `lgrf_sdp.cp312-win_amd64.pyd`. -Script contents (full example, with variables): +## Prerequisites +Install or prepare: + +- Intel oneAPI Base Toolkit +- Visual Studio 2022 C++ build tools +- Miniforge or conda +- A conda environment named `omni_env` +- XPU PyTorch in the conda build environment +- The portable ComfyUI embedded Python environment if you want to install and test the wheel immediately + +The current build script expects: + +```text +C:\Program Files (x86)\Intel\oneAPI\setvars.bat +C:\ProgramData\miniforge3\Scripts\activate.bat +C:\Program Files\Microsoft Visual Studio\18\Community ``` -@echo off -set "VS2022INSTALLDIR=C:\Program Files\Microsoft Visual Studio\18\Community" + +Adjust `scripts\build_llm_scaler_conda.cmd` if your oneAPI, conda, Visual Studio, workspace, or output paths differ. + +## Build The Wheel + +From PowerShell: + +```powershell +Set-Location C:\workspace +cmd /c "C:\workspace\llm-scaler\omni\omni_xpu_kernel\scripts\build_llm_scaler_conda.cmd" +``` + +From Command Prompt: + +```cmd +cd /d C:\workspace +cmd /c "C:\workspace\llm-scaler\omni\omni_xpu_kernel\scripts\build_llm_scaler_conda.cmd" +``` + +The script does the important environment setup before invoking `pip wheel`: + +```cmd call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" call C:\ProgramData\miniforge3\Scripts\activate.bat omni_env -set "WORKSPACE=C:\workspace" -set "LLM_SCALER_DIR=%WORKSPACE%\llm-scaler" -set "EMBED_PYTHON_DIR=%WORKSPACE%\omni\comfyui_windows_setup\python_embeded" -set "OUTPUT_DIR=%WORKSPACE%\llm_scaler_dist" -set "PATH=%CONDA_PREFIX%\Library\bin;%CONDA_PREFIX%\Lib\site-packages\torch\lib;%PATH%" -cd /d %LLM_SCALER_DIR%\omni\omni_xpu_kernel -python -m pip wheel . -w %OUTPUT_DIR% --no-build-isolation --no-deps > %WORKSPACE%\build_log.txt 2>&1 +set "PYTHONNOUSERSITE=1" +set "PYTHONPATH=" +set "CONDA_PYTHON=%CONDA_PREFIX%\python.exe" +set "TORCH_LIB=%CONDA_PREFIX%\Lib\site-packages\torch\lib" +set "OMNI_XPU_DEVICE=bmg" +set "PATH=%CONDA_PREFIX%;%CONDA_PREFIX%\Scripts;%CONDA_PREFIX%\Library\bin;%TORCH_LIB%;%ONEDNN_LIB%;%PATH%" +"%CONDA_PYTHON%" -m pip wheel . -w "C:\workspace\llm_scaler_dist" --no-build-isolation --no-deps ``` -How to run the .cmd file (common options): -- Double-click it in File Explorer. -- From Command Prompt: - - `cmd /c scripts\build_llm_scaler_conda.cmd` -- From PowerShell: - - `cmd /c "scripts\build_llm_scaler_conda.cmd"` +Before building, it prints the Python executable, PyTorch version/path, and whether the XPU header exists: -Key points: -- Initialize oneAPI: setvars.bat -- Activate conda: omni_env -- Set torch DLL search path -- Produce wheel to %OUTPUT_DIR% +```text +c10\xpu\impl\xpu_cmake_macros.h +``` -Output: -- %OUTPUT_DIR%\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl +This check is useful because one common failure mode is accidentally importing a user-site PyTorch instead of the conda environment PyTorch. The script prevents that with `PYTHONNOUSERSITE=1`, an empty `PYTHONPATH`, and an explicit `%CONDA_PREFIX%\python.exe`. -## 3. Install the newly built wheel (embedded Python) -Use --no-deps to avoid pulling dependencies again: +Expected output: - - Wheel path: - - %OUTPUT_DIR%\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl - - Install command: - - pip install --force-reinstall --no-deps +```text +Wheel build succeeded. Output directory: C:\workspace\llm_scaler_dist +omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl +``` -Command example (with variables): +The validated wheel contents included at least: +```text +omni_xpu_kernel/_C.cp312-win_amd64.pyd +omni_xpu_kernel/lgrf_sdp.cp312-win_amd64.pyd ``` -"%EMBED_PYTHON_DIR%\python.exe" -m pip install --force-reinstall --no-deps "%OUTPUT_DIR%\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl" + +If the build fails, inspect: + +```text +C:\workspace\build_log.txt ``` -## 4. Verify (optional) -- Import omni_xpu_kernel -- Check __version__ +The script prints the last 120 log lines automatically on failure. -Command example (with variables): +## Install Into Portable ComfyUI Python +Install the wheel into the embedded Python environment with `--no-deps` so the ComfyUI PyTorch XPU stack is not replaced: + +```cmd +"C:\workspace\llm-scaler\omni\comfyui_windows_setup\python_embeded\python.exe" -m pip install --force-reinstall --no-deps "C:\workspace\llm_scaler_dist\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl" +``` + +The ComfyUI setup script also performs this step automatically. It uses this default wheel path: + +```text +C:\workspace\llm_scaler_dist\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl +``` + +To override it before running `setup_portable_env.bat`: + +```cmd +set "OMNI_XPU_KERNEL_WHEEL=D:\path\to\omni_xpu_kernel-0.1.0-cp312-cp312-win_amd64.whl" +setup_portable_env.bat +``` + +This is the same integration path used by the validated Windows ComfyUI setup: build the wheel first, then let the portable setup consume that local wheel. + +## Verify The Installed Wheel + +Use the embedded Python, not the system Python: + +```cmd +"C:\workspace\llm-scaler\omni\comfyui_windows_setup\python_embeded\python.exe" -c "import omni_xpu_kernel as ok; print(ok.__version__); print('available:', ok.is_available())" ``` -"%EMBED_PYTHON_DIR%\python.exe" -c "import omni_xpu_kernel as ok, importlib.metadata as im; print('omni_xpu_kernel:', ok); print('version:', im.version('omni-xpu-kernel'))" + +Expected output: + +```text +0.1.0 +available: True ``` ---- +Also verify PyTorch XPU from the same embedded Python: -To update or rebuild, repeat steps 2 → 3. +```cmd +"C:\workspace\llm-scaler\omni\comfyui_windows_setup\python_embeded\python.exe" -c "import torch; print(torch.__version__); print(torch.xpu.is_available())" +``` ---- +Validated output included: -## FAQ +```text +2.9.0+xpu +True +``` -### 1) XPU symbol link errors (c10::xpu::XPUStream) -Add missing link libraries in llm-scaler code: +If `ok.is_available()` is `False`, do not continue to ComfyUI startup yet. Fix the embedded runtime first, because ComfyUI will only inherit the same broken environment. - - Source file: - - [setup.py](setup.py) +## Why Windows DLL Search Setup Matters - - Add on Windows: - - torch_xpu.lib - - c10_xpu.lib +On Windows Python 3.8 and newer, modifying `PATH` is not always enough for `.pyd` dependencies. The package initialization registers runtime DLL directories before importing the native extension. This is required for dependencies from locations such as: - - Add on Linux: - - -ltorch_xpu - - -lc10_xpu +```text +python_embeded\Lib\site-packages\torch\lib +python_embeded\Library\bin +Intel oneAPI runtime directories +``` -### 2) Restore embedded PyTorch to XPU build -Reinstall the XPU build of PyTorch in embedded Python (to avoid fallback to standard builds): +Without this, importing `omni_xpu_kernel` can fail even when the dependent DLLs are visible in `PATH`. - - Reference script: - - [setup_portable_env.bat](../../../omni/comfyui_windows_setup/setup_portable_env.bat) - - Key versions: - - torch==2.9.0+xpu - - torchvision==0.24.0+xpu - - torchaudio==2.9.0+xpu - - --index-url https://download.pytorch.org/whl/xpu +## ComfyUI Validation -Command example (with variables): +After installing the wheel and setting up ComfyUI, start the portable server from: +```text +C:\workspace\llm-scaler\omni\comfyui_windows_setup ``` -"%EMBED_PYTHON_DIR%\python.exe" -m pip install torch==2.9.0+xpu torchvision==0.24.0+xpu torchaudio==2.9.0+xpu --index-url https://download.pytorch.org/whl/xpu + +Example manual launch on port `8190`: + +```cmd +set "PYTHONNOUSERSITE=1" +set "PYTHONPATH=" +set "PYTHONHOME=" +set "PATH=%CD%\python_embeded;%CD%\python_embeded\Scripts;%CD%\python_embeded\Library\bin;%PATH%" +cd ComfyUI +..\python_embeded\python.exe main.py --listen 127.0.0.1 --port 8190 +``` + +The validated startup log showed: + +```text +pytorch version: 2.9.0+xpu +Device: xpu:0 Intel(R) Arc(TM) 140V GPU (16GB) +[omni_xpu_kernel] Loaded successfully +[omni_xpu_kernel] FP8 GEMM (oneDNN W8A16) loaded +[omni_xpu_kernel] Loaded rotary ``` + +A Z-Image-Turbo E2E workflow was submitted through the ComfyUI API using: + +```text +UNETLoader: z_image_turbo_bf16.safetensors +CLIPLoader: qwen_3_4b.safetensors, type=lumina2 +VAELoader: ae.safetensors +ModelSamplingAuraFlow: shift=3.0 +KSampler: steps=4, cfg=1.0, sampler=res_multistep, scheduler=simple +EmptySD3LatentImage: 512x512, batch_size=1 +``` + +The output was saved as: + +```text +C:\workspace\llm-scaler\omni\comfyui_windows_setup\ComfyUI\output\z_image_turbo_e2e_00001_.png +``` + +It was verified as a valid `512x512` PNG. The first run completed in about 57 seconds after loading the model weights. + +## Troubleshooting + +### User-site PyTorch Is Imported During Build + +Symptoms include missing XPU headers or linking against the wrong PyTorch install. + +Use the build script settings: + +```cmd +set "PYTHONNOUSERSITE=1" +set "PYTHONPATH=" +"%CONDA_PREFIX%\python.exe" -c "import torch; print(torch.__version__, torch.__file__)" +``` + +The printed PyTorch path must be under `%CONDA_PREFIX%`. + +### C++ `min` / `max` Macro Compile Errors + +Windows headers can define `min` and `max` macros that conflict with C++ code. The Windows compile command uses: + +```text +/DNOMINMAX +/DWIN32_LEAN_AND_MEAN +``` + +### Missing XPU Link Symbols + +If link errors mention symbols such as `c10::xpu::XPUStream`, ensure the Windows link libraries include: + +```text +torch_xpu.lib +c10_xpu.lib +``` + +The Linux equivalents are: + +```text +-ltorch_xpu +-lc10_xpu +``` + +### oneDNN Runtime Not Found + +The build script tries to auto-detect: + +```text +%ProgramFiles(x86)%\Intel\oneAPI\dnnl\latest\include +%ProgramFiles(x86)%\Intel\oneAPI\dnnl\latest\lib +``` + +If your oneAPI layout differs, set `ONEDNN_INCLUDE` and `ONEDNN_LIB` before building. + +### Embedded Python Reinstalls A Non-XPU PyTorch + +Reinstall the XPU build in the embedded Python: + +```cmd +"C:\workspace\llm-scaler\omni\comfyui_windows_setup\python_embeded\python.exe" -m pip install --force-reinstall torch==2.9.0 torchvision==0.24.0 torchaudio==2.9.0 --index-url https://download.pytorch.org/whl/xpu +``` + +Then reinstall the local wheel with `--no-deps`. + +### ComfyUI Port Already In Use + +If startup fails with `WinError 10048` for `127.0.0.1:8188`, use a different port: + +```cmd +..\python_embeded\python.exe main.py --listen 127.0.0.1 --port 8190 +``` + +Check listeners with PowerShell: + +```powershell +Get-NetTCPConnection -LocalPort 8188 -ErrorAction SilentlyContinue +``` + +## Rebuild Checklist + +1. Confirm `omni_env` uses the desired XPU PyTorch. +2. Run `scripts\build_llm_scaler_conda.cmd`. +3. Confirm the wheel appears under `C:\workspace\llm_scaler_dist`. +4. Install it into `comfyui_windows_setup\python_embeded` with `--no-deps`. +5. Verify `omni_xpu_kernel.is_available()` from embedded Python. +6. Start ComfyUI and confirm XPU plus `omni_xpu_kernel` startup log messages. +7. Run a small workflow such as the Z-Image-Turbo `512x512`, 4-step API prompt. diff --git a/omni/omni_xpu_kernel/omni_xpu_kernel/__init__.py b/omni/omni_xpu_kernel/omni_xpu_kernel/__init__.py index 0620a5b8..5525f6ef 100644 --- a/omni/omni_xpu_kernel/omni_xpu_kernel/__init__.py +++ b/omni/omni_xpu_kernel/omni_xpu_kernel/__init__.py @@ -17,18 +17,51 @@ import os import sys +from pathlib import Path __version__ = "0.1.0" __author__ = "Intel" # Lazy loading of native extension _native_module = None +_dll_directory_handles = [] + + +def _add_windows_dll_directories(): + if os.name != "nt" or not hasattr(os, "add_dll_directory"): + return + + candidates = [ + Path(sys.executable).parent, + Path(sys.prefix) / "Library" / "bin", + ] + + try: + import torch + candidates.append(Path(torch.__file__).parent / "lib") + except Exception: + pass + + program_files_x86 = os.environ.get("ProgramFiles(x86)", r"C:\Program Files (x86)") + candidates.extend([ + Path(program_files_x86) / "Intel" / "oneAPI" / "dnnl" / "latest" / "bin", + Path(program_files_x86) / "Intel" / "oneAPI" / "compiler" / "latest" / "bin", + ]) + + for path in candidates: + if path.is_dir(): + try: + _dll_directory_handles.append(os.add_dll_directory(str(path))) + except OSError: + pass def _load_extension(): """Load the native C++ extension module.""" global _native_module if _native_module is not None: return _native_module + + _add_windows_dll_directories() try: from omni_xpu_kernel import _C diff --git a/omni/omni_xpu_kernel/scripts/build_llm_scaler_conda.cmd b/omni/omni_xpu_kernel/scripts/build_llm_scaler_conda.cmd index 56ca54e4..906cda71 100644 --- a/omni/omni_xpu_kernel/scripts/build_llm_scaler_conda.cmd +++ b/omni/omni_xpu_kernel/scripts/build_llm_scaler_conda.cmd @@ -1,11 +1,78 @@ @echo off -set "VS2022INSTALLDIR=C:\Program Files\Microsoft Visual Studio\18\Community" -call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" -call C:\ProgramData\miniforge3\Scripts\activate.bat omni_env +setlocal enabledelayedexpansion + set "WORKSPACE=C:\workspace" set "LLM_SCALER_DIR=%WORKSPACE%\llm-scaler" set "EMBED_PYTHON_DIR=%WORKSPACE%\omni\comfyui_windows_setup\python_embeded" set "OUTPUT_DIR=%WORKSPACE%\llm_scaler_dist" -set "PATH=%CONDA_PREFIX%\Library\bin;%CONDA_PREFIX%\Lib\site-packages\torch\lib;%PATH%" +set "BUILD_LOG=%WORKSPACE%\build_log.txt" +set "CONDA_ENV=omni_env" +set "CONDA_ACTIVATE=C:\ProgramData\miniforge3\Scripts\activate.bat" +set "ONEAPI_SETVARS=C:\Program Files (x86)\Intel\oneAPI\setvars.bat" +set "VS2022INSTALLDIR=C:\Program Files\Microsoft Visual Studio\18\Community" + +if not exist "%ONEAPI_SETVARS%" ( + echo ERROR: oneAPI setvars.bat not found: !ONEAPI_SETVARS! + exit /b 1 +) + +if not exist "%CONDA_ACTIVATE%" ( + echo ERROR: Conda activate.bat not found: !CONDA_ACTIVATE! + exit /b 1 +) + +call "%ONEAPI_SETVARS%" +if errorlevel 1 exit /b %errorlevel% + +call "%CONDA_ACTIVATE%" %CONDA_ENV% +if errorlevel 1 exit /b %errorlevel% + +if not defined CONDA_PREFIX ( + echo ERROR: CONDA_PREFIX is not set after activating %CONDA_ENV%. + exit /b 1 +) + +set "PYTHONNOUSERSITE=1" +set "PYTHONPATH=" +set "CONDA_PYTHON=%CONDA_PREFIX%\python.exe" +set "TORCH_LIB=%CONDA_PREFIX%\Lib\site-packages\torch\lib" + +if not exist "%CONDA_PYTHON%" ( + echo ERROR: Python not found in conda env: %CONDA_PYTHON% + exit /b 1 +) + +if not exist "%TORCH_LIB%" ( + echo ERROR: PyTorch lib directory not found: %TORCH_LIB% + exit /b 1 +) + +if not defined OMNI_XPU_DEVICE set "OMNI_XPU_DEVICE=bmg" + +if not defined ONEDNN_INCLUDE if exist "%ProgramFiles(x86)%\Intel\oneAPI\dnnl\latest\include\oneapi\dnnl\dnnl.hpp" set "ONEDNN_INCLUDE=%ProgramFiles(x86)%\Intel\oneAPI\dnnl\latest\include" +if not defined ONEDNN_LIB if exist "%ProgramFiles(x86)%\Intel\oneAPI\dnnl\latest\lib\dnnl.lib" set "ONEDNN_LIB=%ProgramFiles(x86)%\Intel\oneAPI\dnnl\latest\lib" + +set "PATH=%CONDA_PREFIX%;%CONDA_PREFIX%\Scripts;%CONDA_PREFIX%\Library\bin;%TORCH_LIB%;%ONEDNN_LIB%;%PATH%" + +if not exist "%OUTPUT_DIR%" mkdir "%OUTPUT_DIR%" cd /d %LLM_SCALER_DIR%\omni\omni_xpu_kernel -python -m pip wheel . -w %OUTPUT_DIR% --no-build-isolation --no-deps > %WORKSPACE%\build_log.txt 2>&1 +if errorlevel 1 exit /b %errorlevel% + +echo Build log: %BUILD_LOG% +echo Conda env: %CONDA_PREFIX% +"%CONDA_PYTHON%" -c "import pathlib, torch; p=pathlib.Path(torch.__file__).parent; h=p/'include'/'c10'/'xpu'/'impl'/'xpu_cmake_macros.h'; print('Python:', pathlib.Path(__import__('sys').executable)); print('Torch:', torch.__version__, torch.__file__); print('XPU header:', h, h.exists())" +if errorlevel 1 exit /b %errorlevel% + +if exist build rmdir /s /q build +if exist omni_xpu_kernel.egg-info rmdir /s /q omni_xpu_kernel.egg-info +del /q "%BUILD_LOG%" 2>nul + +"%CONDA_PYTHON%" -m pip wheel . -w "%OUTPUT_DIR%" --no-build-isolation --no-deps > "%BUILD_LOG%" 2>&1 +if errorlevel 1 ( + echo ERROR: Wheel build failed. Last log lines: + powershell -NoProfile -Command "Get-Content -Path '%BUILD_LOG%' -Tail 120" + exit /b 1 +) + +echo Wheel build succeeded. Output directory: %OUTPUT_DIR% +dir /b "%OUTPUT_DIR%\omni_xpu_kernel-*.whl" diff --git a/omni/omni_xpu_kernel/setup.py b/omni/omni_xpu_kernel/setup.py index 140fbead..aeb65fc9 100644 --- a/omni/omni_xpu_kernel/setup.py +++ b/omni/omni_xpu_kernel/setup.py @@ -149,6 +149,8 @@ def build_extension(self, ext): cmd = [ icpx, "-fsycl", + "/DNOMINMAX", + "/DWIN32_LEAN_AND_MEAN", ] if is_lgrf: