Skip to content

pick seed <= u32::MAX when using metal#3045

Merged
greenrazer merged 1 commit into
huggingface:mainfrom
rgbkrk:limit-seed-macos-metal
Aug 20, 2025
Merged

pick seed <= u32::MAX when using metal#3045
greenrazer merged 1 commit into
huggingface:mainfrom
rgbkrk:limit-seed-macos-metal

Conversation

@rgbkrk

@rgbkrk rgbkrk commented Aug 4, 2025

Copy link
Copy Markdown
Contributor

Problem

Running the stable diffusion example with Metal results in an error with the seed (possibly) being out of range.

$ cargo run --example stable-diffusion --release --features=metal -- --prompt "a cosmonaut on a horse (hd, realistic, high-def)" --sd-version turbo
   Compiling candle-transformers v0.9.1 (/Users/kylekelley/code/src/github.com/huggingface/candle/candle-transformers)
   Compiling candle-examples v0.9.1 (/Users/kylekelley/code/src/github.com/huggingface/candle/candle-examples)
    Finished `release` profile [optimized] target(s) in 13.34s
     Running `target/release/examples/stable-diffusion --prompt 'a cosmonaut on a horse (hd, realistic, high-def)' --sd-version turbo`
Using seed 14094623835642992148
Error: Metal error Metal seed must be less than or equal to u32::MAX

Caused by:
    Metal seed must be less than or equal to u32::MAX

The user can manually set --seed but we can make this easier.

Solution

Generate the seed up to u32::MAX when metal is enabled.

@greenrazer greenrazer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Comment thread candle-examples/examples/stable-diffusion/main.rs
@greenrazer greenrazer self-assigned this Aug 5, 2025
@rgbkrk rgbkrk force-pushed the limit-seed-macos-metal branch 2 times, most recently from 6e48425 to 5250b76 Compare August 19, 2025 17:23
@rgbkrk

rgbkrk commented Aug 19, 2025

Copy link
Copy Markdown
Contributor Author

Addressed review feedback. I had to add cfg_if as a dependency as well.

@greenrazer greenrazer force-pushed the limit-seed-macos-metal branch from 5250b76 to 1dadffd Compare August 20, 2025 00:15

@greenrazer greenrazer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this! I mistakenly thought cfg_if was in the standard library. To avoid adding external dependencies, I’ll need to roll back these most recent changes before merging. Really appreciate your work here, my mistake for not checking the dependency requirements first.

@greenrazer greenrazer merged commit 16e1d73 into huggingface:main Aug 20, 2025
9 checks passed
@rgbkrk rgbkrk deleted the limit-seed-macos-metal branch August 21, 2025 23:08
@rgbkrk

rgbkrk commented Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

No problem, thanks for maintaining the package.

john-sharratt pushed a commit to john-sharratt/candle that referenced this pull request May 7, 2026
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.

2 participants