Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NPU Support #14801

Merged
merged 3 commits into from
Jan 31, 2024
Merged

Add NPU Support #14801

merged 3 commits into from
Jan 31, 2024

Conversation

wangshuai09
Copy link
Contributor

Description

This PR enables users to leverage the Ascend NPU for using features including txt2img, img2img, etc.

#13263

Screenshots/videos:

Verified on NPU, prompt is panda:

image

image

Verified on Windows with cpu, prompt is sitting panda:

image

image

Checklist:

(python310) root@ascend-01:/root/project/own/stable-diffusion-webui# python -m pytest -vv --verify-base-url test                 
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.10.6, pytest-7.4.4, pluggy-1.4.0 -- /root/miniconda/envs/python310/bin/python
cachedir: .pytest_cache
baseurl: http://127.0.0.1:7862/
rootdir: /root/project/own/stable-diffusion-webui
configfile: pyproject.toml
plugins: cov-4.1.0, base-url-2.0.0
collected 29 items                                                                                                                                                         

test/test_extras.py::test_simple_upscaling_performed PASSED                                                                                                          [  3%]
test/test_extras.py::test_png_info_performed PASSED                                                                                                                  [  6%]
test/test_extras.py::test_interrogate_performed PASSED                                                                                                               [ 10%]
test/test_img2img.py::test_img2img_simple_performed PASSED                                                                                                           [ 13%]
test/test_img2img.py::test_inpainting_masked_performed PASSED                                                                                                        [ 17%]
test/test_img2img.py::test_inpainting_with_inverted_masked_performed PASSED                                                                                          [ 20%]
test/test_img2img.py::test_img2img_sd_upscale_performed PASSED                                                                                                       [ 24%]
test/test_txt2img.py::test_txt2img_simple_performed PASSED                                                                                                           [ 27%]
test/test_txt2img.py::test_txt2img_with_negative_prompt_performed PASSED                                                                                             [ 31%]
test/test_txt2img.py::test_txt2img_with_complex_prompt_performed PASSED                                                                                              [ 34%]
test/test_txt2img.py::test_txt2img_not_square_image_performed PASSED                                                                                                 [ 37%]
test/test_txt2img.py::test_txt2img_with_hrfix_performed PASSED                                                                                                       [ 41%]
test/test_txt2img.py::test_txt2img_with_tiling_performed PASSED                                                                                                      [ 44%]
test/test_txt2img.py::test_txt2img_with_restore_faces_performed PASSED                                                                                               [ 48%]
test/test_txt2img.py::test_txt2img_with_vanilla_sampler_performed[PLMS] PASSED                                                                                       [ 51%]
test/test_txt2img.py::test_txt2img_with_vanilla_sampler_performed[DDIM] PASSED                                                                                       [ 55%]
test/test_txt2img.py::test_txt2img_with_vanilla_sampler_performed[UniPC] PASSED                                                                                      [ 58%]
test/test_txt2img.py::test_txt2img_multiple_batches_performed PASSED                                                                                                 [ 62%]
test/test_txt2img.py::test_txt2img_batch_performed PASSED                                                                                                            [ 65%]
test/test_utils.py::test_options_write PASSED                                                                                                                        [ 68%]
test/test_utils.py::test_get_api_url[sdapi/v1/cmd-flags] PASSED                                                                                                      [ 72%]
test/test_utils.py::test_get_api_url[sdapi/v1/samplers] PASSED                                                                                                       [ 75%]
test/test_utils.py::test_get_api_url[sdapi/v1/upscalers] PASSED                                                                                                      [ 79%]
test/test_utils.py::test_get_api_url[sdapi/v1/sd-models] PASSED                                                                                                      [ 82%]
test/test_utils.py::test_get_api_url[sdapi/v1/hypernetworks] PASSED                                                                                                  [ 86%]
test/test_utils.py::test_get_api_url[sdapi/v1/face-restorers] PASSED                                                                                                 [ 89%]
test/test_utils.py::test_get_api_url[sdapi/v1/realesrgan-models] PASSED                                                                                              [ 93%]
test/test_utils.py::test_get_api_url[sdapi/v1/prompt-styles] PASSED                                                                                                  [ 96%]
test/test_utils.py::test_get_api_url[sdapi/v1/embeddings] PASSED                                                                                                     [100%]

====================================================================== 29 passed in 870.87s (0:14:30) ======================================================================

@AUTOMATIC1111
Copy link
Owner

Some things:

  • the way you added dependencies, they are installed for everyone. This shouldn't be the case. If they're needed for Ascend NPU (are they?) they should only be installed if Ascend NPU is present.
  • I don't like the added bits of torch.npu.set_device(0) code in multiple places. Can You only do it once, when torch is imported for the first time?

@wangshuai09
Copy link
Contributor Author

@AUTOMATIC1111 , thanks for you quick response.
I've extracted NPU releated dependency packages into the requirements_npu.txt and these will only be installed in NPU env.
torch.npu.set_device(0) is needed because the context couldn't share in different thread, abstracted this as a function now and will remove after it was fixed.

@AUTOMATIC1111 AUTOMATIC1111 merged commit 96b5504 into AUTOMATIC1111:dev Jan 31, 2024
3 checks passed
@wangshuai09
Copy link
Contributor Author

@AUTOMATIC1111, Hi, I have wrote a wiki about Install and run on Ascend NPUs, Should I update a new wiki page in this repo or link to the Install and run on Ascend NPUs.

@w-e-w w-e-w mentioned this pull request Feb 17, 2024
@wangshuai09
Copy link
Contributor Author

wangshuai09 commented Mar 12, 2024

@why-not-ava Hi, make sure your code is up to data and then follow the Install and run on Ascend NPUs, the 'webui.sh' will auto install torch_npu

@why-not-ava
Copy link

why-not-ava commented Mar 31, 2024

hello, i always get this error with python 3.10.6 when i run [./webui.sh -f --skip-torch-cuda-test --no-half --listen --port 12000], i have no idea how to solve it.
image

@wangshuai09
Copy link
Contributor Author

Did you install it using following command? @why-not-ava

conda create -n python310 python=3.10.6
conda activate python310
./webui.sh --skip-torch-cuda-test --no-half

@FuturePrayer
Copy link

hi,can the Atlas 200I DK A2 or Orange Pi AIpro run in this way?

@wangshuai09
Copy link
Contributor Author

@FuturePrayer Hi, it can run mainly based on the ability of torch_npu. You can create a issuse for device support at ascend/pytorch.

@cleansely
Copy link

请问下,有测试过sdxl和sd1.5吗,我在800-9000上测试,半精度,xl需要10s

@wangshuai09
Copy link
Contributor Author

The speed is related to sampling steps, width, height, etc. I've tested and it need 9s using sdxl with 20 sampling steps, 512 witdth, 1024 height.

@cleansely
Copy link

@wangshuai09 我这边测试是20step,1024*1024,altas 800环境。您那边应该是altas 800 A2吧,我看代码没有加上torch_npu.npu.set_compile_mode(jit_compile=False)

@pawel665j pawel665j mentioned this pull request Apr 16, 2024
@CyanWoods
Copy link

Did you install it using following command? @why-not-ava

conda create -n python310 python=3.10.6
conda activate python310
./webui.sh --skip-torch-cuda-test --no-half

I come with the same problem, with these commands runned.
image

image

@wangshuai09
Copy link
Contributor Author

@cleansely 我不清楚 altas 800 A2 和 altas 800 的 NPU 型号有区别吗,torch_npu.npu.set_compile_mode(jit_compile=False) 这个参数你设置了吗,对速度影响多大呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants