Skip to content
New issue

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

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

Already on GitHub? # to your account

bug fix for num_steps=1 #2373

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion keras_cv/models/stable_diffusion/stable_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ def generate_image(

# Iterative reverse diffusion stage
num_timesteps = 1000
ratio = (num_timesteps - 1) / (num_steps - 1)
ratio = (
(num_timesteps - 1) / (num_steps - 1)
if num_steps > 1
else num_timesteps
)
timesteps = (np.arange(0, num_steps) * ratio).round().astype(np.int64)

alphas, alphas_prev = self._get_initial_alphas(timesteps)
Expand Down
8 changes: 8 additions & 0 deletions keras_cv/models/stable_diffusion/stable_diffusion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def test_text_tokenizer_golden_value(self):
[49406, 320, 27111, 9038, 320],
)

@pytest.mark.extra_large
def test_num_steps_equal_to_one_no_error(self):
stablediff = StableDiffusion(128, 128)
_ = stablediff.generate_image(
stablediff.encode_text("thou shall not render"),
num_steps=1,
)

@pytest.mark.extra_large
def test_mixed_precision(self):
try:
Expand Down
Loading