以下の内容はhttps://touch-sp.hateblo.jp/entry/2025/12/10/185451より取得しました。


【Core Ultra iGPU】WSL2 で Intel iGPU を使って PyTorch を動かす(NVlabs/Sana で画像生成)

はじめに

タイトルにあるようにWSL2でiGPUを使ってPyTorchを動かしてみました。

必要なのはこちらに従いWSL2側にIntel software for general purpose GPU capabilitiesをインストールすることでした。

使用したPC

Copilot+PCに分類されるノートPCです。
「THIRDWAVE F-14LN5LA メモリ32GB搭載」

Windows 11 Home
Core Ultra 5 228V (Lunar Lake)
Intel Arc 130V GPU
32GBメモリ

動作環境

Ubuntu 24.04 on WSL2
uv 0.9.16
Python 3.13

結果


Pythonスクリプト

import os

os.environ["UR_L0_ENABLE_RELAXED_ALLOCATION_LIMITS"] = "1"

import torch
from diffusers import SanaPAGPipeline

pipe = SanaPAGPipeline.from_pretrained(
    "Efficient-Large-Model/Sana_1600M_1024px_BF16_diffusers",
    variant="bf16",
    torch_dtype=torch.bfloat16,
    pag_applied_layers="transformer_blocks.8",
).to("xpu")

prompt = 'Ultra-realistic, high-quality photo of an anthropomorphic capybara with a tough, streetwise attitude, wearing a worn black leather jacket, dark sunglasses, and ripped jeans. The capybara is leaning casually against a gritty urban wall covered in vibrant graffiti. The scene is set in a dimly lit alleyway with moody lighting, scattered trash, and an edgy, rebellious vibe — like a character straight out of an underground comic book.'

image = pipe(
    prompt=prompt,
    guidance_scale=5.0,
    pag_scale=2.0,
    num_inference_steps=20,
    generator=torch.manual_seed(42),
)[0]

image[0].save("with_pag.jpg")

Python環境構築

pyproject.tomlを示します。

[project]
name = "sana"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
    "accelerate==1.12.0",
    "beautifulsoup4==4.14.3",
    "diffusers==0.35.2",
    "ftfy==6.3.1",
    "hf-xet==1.2.0",
    "pytorch-triton-xpu==3.5.0",
    "torch==2.9.1+xpu",
    "transformers==4.57.3",
]

[[tool.uv.index]]
name = "torch-xpu"
url = "https://download.pytorch.org/whl/xpu"
explicit = true

[tool.uv.sources]
torch = [{ index = "torch-xpu" }]
pytorch-triton-xpu = [{ index = "torch-xpu" }]




以上の内容はhttps://touch-sp.hateblo.jp/entry/2025/12/10/185451より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14