[IPEX] Support SDE samplers#1579
Merged
Merged
Conversation
This is a W/A since `torch.Generator()` API doesn't support `xpu` backend at the moment. So replacing it with `torch.xpu.Generator()` API provided by IPEX.
Contributor
Author
|
Adding @Disty0 who might be interested in this :-) |
Collaborator
|
Nice! Less steps for end users. Also removed .vscode line in the .gitignore file since it already has .vscode/ in it. |
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.
Description
This is a W/A since
torch.Generator()API doesn't supportxpubackend at the moment. So replacing it withtorch.xpu.Generator()API provided by IPEX.Notes
Original error message for IPEX, when
DPM++ 2M SDEorDPM++ 2M SDE Karrassampler is used:08:08:02-165066 ERROR Please apply this patch to repositories/k-diffusion/k_diffusion/sampling.py: https://github.com/crowsonkb/k-diffusion/pull/68/files 08:08:02-241772 ERROR Exception: Device type XPU is not supported for torch.Generator() api. 08:08:02-243317 ERROR Arguments: args=('task(vf0n135fwtjw20x)', 'iron man', '', [], 20, 1, False, False, 1, 1, 6, 1, -1.0, -1.0, 0, 0, 0, False, 512, 512, False, 0.7, 2, 'Latent', 0, 0, 0, [], 0, False, 'MultiDiffusion', False, True, 1024, 1024, 96, 96, 48, 4, 'None', 2, False, 10, 1, 1, 64, False, False, False, False, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 0.4, 0.4, 0.2, 0.2, '', '', 'Background', 0.2, -1.0, False, 512, 64, True, True, True, False, False, 7, 100, 'Constant', 0, 'Constant', 0, 4, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x7fe29c1aedd0>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x7fe29c1ae920>, <scripts.controlnet_ui.controlnet_ui_group.UiControlNetUnit object at 0x7fe3d3c02350>, False, False, 'positive', 'comma', 0, False, False, '', 0, '', [], 0, '', [], 0, '', [], True, False, False, False, 0, False, None, None, False, None, None, False, None, None, False, 50) kwargs={} 08:08:02-247736 ERROR gradio call: RuntimeError ╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮ │ /sd-webui/modules/call_queue.py:34 in f │ │ │ │ 33 │ │ │ try: │ │ ❱ 34 │ │ │ │ res = func(*args, **kwargs) │ │ 35 │ │ │ │ progress.record_results(id_task, res) │ │ │ │ /sd-webui/modules/txt2img.py:56 in txt2img │ │ │ │ 55 │ if processed is None: │ │ ❱ 56 │ │ processed = processing.process_images(p) │ │ 57 │ p.close() │ │ │ │ ... 14 frames hidden ... │ │ │ │ /deps/venv/lib/python3.10/site-packages/torchsde/_brownian/brownian_interval.py:234 in _randn │ │ │ │ 233 │ │ size = self._top._size │ │ ❱ 234 │ │ return _randn(size, self._top._dtype, self._top._device, seed) │ │ 235 │ │ │ │ /deps/venv/lib/python3.10/site-packages/torchsde/_brownian/brownian_interval.py:32 in _randn │ │ │ │ 31 def _randn(size, dtype, device, seed): │ │ ❱ 32 │ generator = torch.Generator(device).manual_seed(int(seed)) │ │ 33 │ return torch.randn(size, dtype=dtype, device=device, generator=generator) │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ RuntimeError: Device type XPU is not supported for torch.Generator() api.After this fix, the
SDEsamplers can be used for IPEX without manually applying the local patch fork_diffusion. However, the performance seems to be the same as that ofk_diffusionpatch: crowsonkb/k-diffusion#68Environment and Testing
OS: Windows 11
Docker: nuullll/ipex-arc-sd:v0.2 (oneAPI 2023.1)
DPM++ 2M SDE: ~5.9 it/s

DPM++ 2M SDE Karras: ~5.9it/s
