-
Notifications
You must be signed in to change notification settings - Fork 186
Add ROCm GPU backend support for stable-diffusion.cpp #980
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
316448c
Add ROCm GPU backend support for stable-diffusion.cpp
makn87amd 0f55f3f
Merge branch with system info code and endpoint
makn87amd 2642a5e
Changes for rocm sd-cpp to conform to pr-992
makn87amd 8df44c2
Fix server_sd.py to pass wrapped_server parameter
makn87amd 5044a38
Update ROCm image generation example and modify CI workflow for ROCm …
makn87amd 42001e8
Fized indentation issue in sd_server.cpp
makn87amd c88e850
Additional formatting modifications
makn87amd cf20269
Merged changes from main 2636350 into pr-980
makn87amd 1d35726
Added sd-cpp default to RECIPE_DEFS
makn87amd f711e77
Changed sdcpp rocm test runner to stx-halo
makn87amd 999f952
Removed 'default' for sd-cpp in RECIPE_DEFS
makn87amd b060460
Fixed server_system_info.py to pass tests
makn87amd d9100ea
Update server_system_info.py
makn87amd f73cdb1
Implemented suggestions from PR review
makn87amd 318ee03
Merge remote-tracking branch 'origin/rocm_gpu_support' into rocm_gpu_…
makn87amd 215c155
Merge main
ramkrishna2910 4646c95
resolve test failures
ramkrishna2910 0b6c0f2
Merge branch 'main' into rocm_gpu_support
jeremyfowers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| ROCm GPU Image Generation Example | ||
|
|
||
| Demonstrates AMD GPU-accelerated image generation with stable-diffusion.cpp. | ||
|
|
||
| Prerequisites: | ||
| pip install openai requests | ||
| lemonade-server serve --sdcpp rocm # Start server with ROCm backend | ||
|
|
||
| Usage: | ||
| python api_image_gen_rocm.py | ||
| """ | ||
|
|
||
| import base64 | ||
| import time | ||
| import requests | ||
| from openai import OpenAI | ||
|
|
||
| # Connect to local lemonade server | ||
| BASE_URL = "http://localhost:8000/api/v1" | ||
| client = OpenAI(base_url=BASE_URL, api_key="not-needed") | ||
|
|
||
| # Models to test (name, steps, cfg_scale) | ||
| MODELS = [ | ||
| ("SD-Turbo", 4, 1.0), | ||
| ("SD-1.5", 20, 7.0), | ||
| ("SDXL-Turbo", 4, 1.0), | ||
| ("SDXL-Base-1.0", 20, 7.0), | ||
| ] | ||
|
|
||
| prompt = "A majestic dragon breathing fire over a medieval castle" | ||
|
|
||
| print("Testing ROCm-accelerated image generation\n") | ||
|
|
||
| for model, steps, cfg_scale in MODELS: | ||
| print(f"Generating with {model}...") | ||
|
|
||
| # Load model with ROCm backend | ||
| requests.post( | ||
| f"{BASE_URL}/load", | ||
| json={"model_name": model, "sd-cpp_backend": "rocm"}, | ||
| timeout=300, | ||
| ) | ||
|
|
||
| # Generate image | ||
| start = time.time() | ||
| response = client.images.generate( | ||
| model=model, | ||
| prompt=prompt, | ||
| size="512x512", | ||
| n=1, | ||
| response_format="b64_json", | ||
| extra_body={"steps": steps, "cfg_scale": cfg_scale}, | ||
| ) | ||
| elapsed = time.time() - start | ||
|
|
||
| # Save image | ||
| image_data = base64.b64decode(response.data[0].b64_json) | ||
| filename = f"{model.lower().replace('-', '_')}_rocm.png" | ||
| with open(filename, "wb") as f: | ||
| f.write(image_data) | ||
|
|
||
| print(f" ✓ Generated in {elapsed:.2f}s → {filename}\n") | ||
|
|
||
| print("Done!") | ||
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.