Repository: huggingface/diffusers

Issue:
Issue: Error handling of invalid orders
### Describe the bug

When I attempt to create an XYZ grid using all available Samplers (other than Default) with an SDXL model in the X axis, and [Sampler] solver order: 1-5 in the Y axis, and nothing for Z axis, I get the below error (see relevant log export).

Final error is "UnboundLocalError: local variable 'orders' referenced before assignment". 

I reported this to SD.Next here: 
https://github.com/vladmandic/automatic/issues/2454
The author responded: "Sampler DPM++ 1S has valid orders of 1,2,3. Issue occurs when using order out of range.
If you want to have better error handling of invalid orders, you may want to report to https://github.com/huggingface/diffusers/"

### Reproduction

Not sure how to do this in code, but I can share my process.
In SD.Next, Stable Diffusion XL pipeline, I created an XYZ grid with all samplers in X axis, and Solver Order: 1-5 in Y axis.
The issue took a long time to show up so it did complete the earlier solver orders. When it hit a solver order that was not valid, instead of noting that and moving on, it errored out and stopped executing the grid. 

### Logs

```shell
10:34:36-443850 INFO     XYZ grid: images=70 grid=1 14x5 cells=1 steps=3500
10:34:36-443850 INFO     Applying hypertile: unet=256
Progress  2.20it/s █████████████████████████████████ 100% 50/50 00:22 00:00 Base
10:35:08-980475 INFO     Processed: images=1 time=32.52 its=1.54 memory={'ram': {'used': 6.66, 'total': 31.85}, 'gpu': {'used':
                         15.13, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:35:08-996101 INFO     Applying hypertile: unet=256
Progress  2.51it/s █████████████████████████████████ 100% 50/50 00:19 00:00 Base
10:35:35-698241 INFO     Processed: images=1 time=26.69 its=1.87 memory={'ram': {'used': 6.67, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:35:35-698241 INFO     Applying hypertile: unet=256
Progress  2.06it/s █████████████████████████████████ 100% 50/50 00:24 00:00 Base
10:36:06-557953 INFO     Processed: images=1 time=30.86 its=1.62 memory={'ram': {'used': 7.22, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:36:06-560555 INFO     Applying hypertile: unet=256
Progress  2.41it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:36:33-669330 INFO     Processed: images=1 time=27.11 its=1.84 memory={'ram': {'used': 7.26, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:36:33-684957 INFO     Applying hypertile: unet=256
Progress  2.41it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:37:01-641612 INFO     Processed: images=1 time=27.96 its=1.79 memory={'ram': {'used': 7.35, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:37:01-641612 INFO     Applying hypertile: unet=256
Progress  2.26it/s █████████████████████████████████ 100% 50/50 00:22 00:00 Base
10:37:30-738992 INFO     Processed: images=1 time=29.08 its=1.72 memory={'ram': {'used': 7.39, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:37:30-738992 INFO     Applying hypertile: unet=256
Progress  1.22it/s █████████████████████████████████ 100% 50/50 00:40 00:00 Base
10:38:18-354242 INFO     Processed: images=1 time=47.62 its=1.05 memory={'ram': {'used': 7.29, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:38:18-354242 INFO     Applying hypertile: unet=256
Progress  1.20it/s █████████████████████████████████ 100% 50/50 00:41 00:00 Base
10:39:06-645770 INFO     Processed: images=1 time=48.28 its=1.04 memory={'ram': {'used': 7.32, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:39:06-645770 INFO     Applying hypertile: unet=256
Progress  2.48it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:39:34-048889 INFO     Processed: images=1 time=27.39 its=1.83 memory={'ram': {'used': 7.37, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:39:34-064572 INFO     Applying hypertile: unet=256
Progress  2.48it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:40:02-384658 INFO     Processed: images=1 time=28.29 its=1.77 memory={'ram': {'used': 5.47, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:40:02-384658 INFO     Applying hypertile: unet=256
Progress  1.20it/s █████████████████████████████████ 100% 50/50 00:41 00:00 Base
10:40:51-620433 INFO     Processed: images=1 time=49.24 its=1.02 memory={'ram': {'used': 5.98, 'total': 31.85}, 'gpu': {'used':
                         17.52, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:40:51-636044 INFO     Applying hypertile: unet=256
Progress  2.40it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:41:19-625417 INFO     Processed: images=1 time=27.97 its=1.79 memory={'ram': {'used': 6.12, 'total': 31.85}, 'gpu': {'used':
                         17.53, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:41:19-641039 INFO     Applying hypertile: unet=256
Progress  2.49it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:41:46-825088 INFO     Processed: images=1 time=27.18 its=1.84 memory={'ram': {'used': 6.18, 'total': 31.85}, 'gpu': {'used':
                         17.53, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:41:46-840713 INFO     Applying hypertile: unet=256
Progress  1.22it/s █████████████████████████████████ 100% 50/50 00:40 00:00 Base
10:42:33-958474 INFO     Processed: images=1 time=47.12 its=1.06 memory={'ram': {'used': 6.12, 'total': 31.85}, 'gpu': {'used':
                         17.53, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:42:33-958474 INFO     Applying hypertile: unet=256
Progress  2.41it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:43:00-998803 INFO     Processed: images=1 time=27.02 its=1.85 memory={'ram': {'used': 6.18, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:43:01-014406 INFO     Applying hypertile: unet=256
Progress  2.50it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:43:27-917324 INFO     Processed: images=1 time=26.90 its=1.86 memory={'ram': {'used': 6.22, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:43:27-917324 INFO     Applying hypertile: unet=256
Progress  2.06it/s █████████████████████████████████ 100% 50/50 00:24 00:00 Base
10:43:58-357471 INFO     Processed: images=1 time=30.43 its=1.64 memory={'ram': {'used': 6.27, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:43:58-373037 INFO     Applying hypertile: unet=256
Progress  2.42it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:44:25-368944 INFO     Processed: images=1 time=27.00 its=1.85 memory={'ram': {'used': 6.32, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:44:25-384656 INFO     Applying hypertile: unet=256
Progress  2.42it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:44:52-140387 INFO     Processed: images=1 time=26.76 its=1.87 memory={'ram': {'used': 6.36, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:44:52-156098 INFO     Applying hypertile: unet=256
Progress  2.29it/s █████████████████████████████████ 100% 50/50 00:21 00:00 Base
10:45:20-400224 INFO     Processed: images=1 time=28.21 its=1.77 memory={'ram': {'used': 6.22, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:45:20-400224 INFO     Applying hypertile: unet=256
Progress  1.23it/s █████████████████████████████████ 100% 50/50 00:40 00:00 Base
10:46:07-812175 INFO     Processed: images=1 time=47.40 its=1.05 memory={'ram': {'used': 6.25, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:46:07-827750 INFO     Applying hypertile: unet=256
Progress  1.23it/s █████████████████████████████████ 100% 50/50 00:40 00:00 Base
10:46:56-497078 INFO     Processed: images=1 time=48.67 its=1.03 memory={'ram': {'used': 5.66, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:46:56-512694 INFO     Applying hypertile: unet=256
Progress  2.50it/s █████████████████████████████████ 100% 50/50 00:19 00:00 Base
10:47:23-462955 INFO     Processed: images=1 time=26.94 its=1.86 memory={'ram': {'used': 6.08, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:47:23-462955 INFO     Applying hypertile: unet=256
Progress  2.50it/s █████████████████████████████████ 100% 50/50 00:19 00:00 Base
10:47:50-106419 INFO     Processed: images=1 time=26.63 its=1.88 memory={'ram': {'used': 6.26, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:47:50-106419 INFO     Applying hypertile: unet=256
Progress  1.20it/s █████████████████████████████████ 100% 50/50 00:41 00:00 Base
10:48:39-542567 INFO     Processed: images=1 time=49.42 its=1.01 memory={'ram': {'used': 5.45, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:48:39-558186 INFO     Applying hypertile: unet=256
Progress  2.42it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:49:06-583628 INFO     Processed: images=1 time=27.03 its=1.85 memory={'ram': {'used': 6.14, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:49:06-583628 INFO     Applying hypertile: unet=256
Progress  2.50it/s █████████████████████████████████ 100% 50/50 00:19 00:00 Base
10:49:33-497938 INFO     Processed: images=1 time=26.90 its=1.86 memory={'ram': {'used': 6.34, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:49:33-520643 INFO     Applying hypertile: unet=256
Progress  1.19it/s █████████████████████████████████ 100% 50/50 00:41 00:00 Base
10:50:21-962462 INFO     Processed: images=1 time=48.43 its=1.03 memory={'ram': {'used': 6.42, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:50:21-978088 INFO     Applying hypertile: unet=256
Progress  2.39it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:50:49-571212 INFO     Processed: images=1 time=27.59 its=1.81 memory={'ram': {'used': 6.48, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:50:49-577037 INFO     Applying hypertile: unet=256
Progress  2.45it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:51:16-990653 INFO     Processed: images=1 time=27.40 its=1.82 memory={'ram': {'used': 6.52, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:51:16-990653 INFO     Applying hypertile: unet=256
Progress  1.89it/s █████████████████████████████████ 100% 50/50 00:26 00:00 Base
10:51:50-989978 INFO     Processed: images=1 time=33.99 its=1.47 memory={'ram': {'used': 5.5, 'total': 31.85}, 'gpu': {'used': 17.56,
                         'total': 23.99}, 'retries': 0, 'oom': 0}
10:51:50-996977 INFO     Applying hypertile: unet=256
Progress  2.25it/s █████████████████████████████████ 100% 50/50 00:22 00:00 Base
10:52:19-806701 INFO     Processed: images=1 time=28.80 its=1.74 memory={'ram': {'used': 6.22, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:52:19-821209 INFO     Applying hypertile: unet=256
Progress  2.30it/s █████████████████████████████████ 100% 50/50 00:21 00:00 Base
10:52:47-668490 INFO     Processed: images=1 time=27.85 its=1.80 memory={'ram': {'used': 6.4, 'total': 31.85}, 'gpu': {'used': 17.56,
                         'total': 23.99}, 'retries': 0, 'oom': 0}
10:52:47-675555 INFO     Applying hypertile: unet=256
Progress  2.09it/s █████████████████████████████████ 100% 50/50 00:23 00:00 Base
10:53:17-664819 INFO     Processed: images=1 time=29.98 its=1.67 memory={'ram': {'used': 6.48, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:53:17-671882 INFO     Applying hypertile: unet=256
Progress  1.16it/s █████████████████████████████████ 100% 50/50 00:42 00:00 Base
10:54:08-869732 INFO     Processed: images=1 time=51.19 its=0.98 memory={'ram': {'used': 5.56, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:54:08-885460 INFO     Applying hypertile: unet=256
Progress  1.14it/s █████████████████████████████████ 100% 50/50 00:43 00:00 Base
10:55:00-403189 INFO     Processed: images=1 time=51.52 its=0.97 memory={'ram': {'used': 6.27, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:55:00-418917 INFO     Applying hypertile: unet=256
Progress  2.46it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:55:27-935021 INFO     Processed: images=1 time=27.50 its=1.82 memory={'ram': {'used': 6.47, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:55:27-950652 INFO     Applying hypertile: unet=256
Progress  2.44it/s █████████████████████████████████ 100% 50/50 00:20 00:00 Base
10:55:55-304991 INFO     Processed: images=1 time=27.35 its=1.83 memory={'ram': {'used': 6.53, 'total': 31.85}, 'gpu': {'used':
                         17.56, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:55:55-321113 INFO     Applying hypertile: unet=256
Progress  1.10it/s █████████████████████████████████ 100% 50/50 00:45 00:00 Base
10:56:48-057360 INFO     Processed: images=1 time=52.72 its=0.95 memory={'ram': {'used': 5.61, 'total': 31.85}, 'gpu': {'used':
                         17.57, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:56:48-063973 INFO     Applying hypertile: unet=256
Progress  2.37it/s █████████████████████████████████ 100% 50/50 00:21 00:00 Base
10:57:13-170718 INFO     Processed: images=1 time=25.10 its=1.99 memory={'ram': {'used': 10.85, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:57:13-170718 INFO     Applying hypertile: unet=256
Progress  2.35it/s █████████████████████████████████ 100% 50/50 00:21 00:00 Base
10:57:40-697628 INFO     Processed: images=1 time=27.53 its=1.82 memory={'ram': {'used': 6.5, 'total': 31.85}, 'gpu': {'used': 17.58,
                         'total': 23.99}, 'retries': 0, 'oom': 0}
10:57:40-709633 INFO     Applying hypertile: unet=256
Progress  1.12it/s █████████████████████████████████ 100% 50/50 00:44 00:00 Base
10:58:31-496251 INFO     Processed: images=1 time=50.78 its=0.98 memory={'ram': {'used': 6.59, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:58:31-499323 INFO     Applying hypertile: unet=256
Progress  2.12it/s █████████████████████████████████ 100% 50/50 00:23 00:00 Base
10:59:01-295198 INFO     Processed: images=1 time=29.78 its=1.68 memory={'ram': {'used': 6.52, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:59:01-303224 INFO     Applying hypertile: unet=256
Progress  2.19it/s █████████████████████████████████ 100% 50/50 00:22 00:00 Base
10:59:31-340037 INFO     Processed: images=1 time=30.03 its=1.67 memory={'ram': {'used': 6.55, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
10:59:31-348038 INFO     Applying hypertile: unet=256
Progress  1.91it/s █████████████████████████████████ 100% 50/50 00:26 00:00 Base
11:00:03-660307 INFO     Processed: images=1 time=32.30 its=1.55 memory={'ram': {'used': 6.58, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
11:00:03-668276 INFO     Applying hypertile: unet=256
Progress  2.24it/s █████████████████████████████████ 100% 50/50 00:22 00:00 Base
11:00:31-869583 INFO     Processed: images=1 time=28.19 its=1.77 memory={'ram': {'used': 6.64, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
11:00:31-869583 INFO     Applying hypertile: unet=256
Progress  2.29it/s █████████████████████████████████ 100% 50/50 00:21 00:00 Base
11:01:00-117427 INFO     Processed: images=1 time=28.23 its=1.77 memory={'ram': {'used': 6.68, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
11:01:00-130365 INFO     Applying hypertile: unet=256
Progress  2.21it/s █████████████████████████████████ 100% 50/50 00:22 00:00 Base
11:01:28-741124 INFO     Processed: images=1 time=28.61 its=1.75 memory={'ram': {'used': 6.72, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
11:01:28-747124 INFO     Applying hypertile: unet=256
Progress  1.18it/s █████████████████████████████████ 100% 50/50 00:42 00:00 Base
11:02:17-792284 INFO     Processed: images=1 time=49.03 its=1.02 memory={'ram': {'used': 6.59, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
11:02:17-802392 INFO     Applying hypertile: unet=256
Progress  1.19it/s █████████████████████████████████ 100% 50/50 00:41 00:00 Base
11:03:06-410550 INFO     Processed: images=1 time=48.60 its=1.03 memory={'ram': {'used': 6.62, 'total': 31.85}, 'gpu': {'used':
                         17.58, 'total': 23.99}, 'retries': 0, 'oom': 0}
11:03:06-426449 INFO     Applying hypertile: unet=256
11:03:06-442449 ERROR    Exception: local variable 'orders' referenced before assignment
11:03:06-442449 ERROR    Arguments: args=('task(5vd9wyaymefv5xt)', 'realistic photo of a 45 year-old Mexican woman on a
                         farm.\n\ndetailed face, highres, realistic, photorealistic, pores, wrinkles, High Detail, Sharp focus,
                         dramatic, (looking at viewer:1.2), (natural light)\n\nExtremely detailed high quality photo, photorealistic,
                         realistic skin, sharp focus, realistic texture, focused, masterpiece. ', 'shiny skin, blur, bokeh, noise,
                         film grain, bad anatomy, airbrushed, misaligned eyes, bad hands, extra fingers, extra limbs, missing limbs,
                         illustration, drawing, painting, cartoon, anime, text, watermark, signature, ', [], 50, 11, 11, True, False,
                         True, 1, 1, 4, 6, 0.7, 1, -1.0, -1.0, 0, 0, 0, 1280, 1024, False, 0.5, 1.25, 'chaiNNer 4x ESRGAN
                         Helaman-LSDIRplus', True, 20, 0, 0, 5, 1, '', '', [], 3, False, False, 'positive', 'comma', 0, False, False,
                         '', 5, '', ['UniPC', 'DEIS', 'PNDM', 'DDPM', 'DDIM', 'LMSD', 'KDPM2', 'KDPM2 a', 'DPM++ 1S', 'DPM++ 2M',
                         'DPM SDE', 'Euler', 'Euler a', 'Heun'], 24, '1-5', [], 0, '', [], False, True, False, False, False, False,
                         0, 5, 'all', 'all', 'photograph', '', '', '', '1', 'none', False, '', '', 'comma', '', True, '', '20',
                         'female', 'all', 'all', 'all', 0, '', False, False, {'ad_model': 'face_yolov8s.pt', 'ad_prompt': '',
                         'ad_negative_prompt': '', 'ad_confidence': 0.3, 'ad_mask_k_largest': 0, 'ad_mask_min_ratio': 0,
                         'ad_mask_max_ratio': 1, 'ad_x_offset': 0, 'ad_y_offset': 0, 'ad_dilate_erode': 4, 'ad_mask_merge_invert':
                         'None', 'ad_mask_blur': 4, 'ad_denoising_strength': 0.4, 'ad_inpaint_only_masked': True,
                         'ad_inpaint_only_masked_padding': 32, 'ad_use_inpaint_width_height': False, 'ad_inpaint_width': 512,
                         'ad_inpaint_height': 512, 'ad_use_steps': False, 'ad_steps': 28, 'ad_use_cfg_scale': False, 'ad_cfg_scale':
                         7, 'ad_use_checkpoint': False, 'ad_checkpoint': 'Use same checkpoint', 'ad_use_vae': False, 'ad_vae': 'Use
                         same VAE', 'ad_use_sampler': False, 'ad_sampler': 'Default', 'ad_use_noise_multiplier': False,
                         'ad_noise_multiplier': 1, 'ad_use_clip_skip': False, 'ad_clip_skip': 1, 'ad_restore_face': False,
                         'ad_controlnet_model': 'None', 'ad_controlnet_module': 'None', 'ad_controlnet_weight': 1,
                         'ad_controlnet_guidance_start': 0, 'ad_controlnet_guidance_end': 1, 'is_api': ()}, {'ad_model': 'None',
                         'ad_prompt': '', 'ad_negative_prompt': '', 'ad_confidence': 0.3, 'ad_mask_k_largest': 0,
                         'ad_mask_min_ratio': 0, 'ad_mask_max_ratio': 1, 'ad_x_offset': 0, 'ad_y_offset': 0, 'ad_dilate_erode': 4,
                         'ad_mask_merge_invert': 'None', 'ad_mask_blur': 4, 'ad_denoising_strength': 0.4, 'ad_inpaint_only_masked':
                         True, 'ad_inpaint_only_masked_padding': 32, 'ad_use_inpaint_width_height': False, 'ad_inpaint_width': 512,
                         'ad_inpaint_height': 512, 'ad_use_steps': False, 'ad_steps': 28, 'ad_use_cfg_scale': False, 'ad_cfg_scale':
                         7, 'ad_use_checkpoint': False, 'ad_checkpoint': 'Use same checkpoint', 'ad_use_vae': False, 'ad_vae': 'Use
                         same VAE', 'ad_use_sampler': False, 'ad_sampler': 'Default', 'ad_use_noise_multiplier': False,
                         'ad_noise_multiplier': 1, 'ad_use_clip_skip': False, 'ad_clip_skip': 1, 'ad_restore_face': False,
                         'ad_controlnet_model': 'None', 'ad_controlnet_module': 'None', 'ad_controlnet_weight': 1,
                         'ad_controlnet_guidance_start': 0, 'ad_controlnet_guidance_end': 1, 'is_api': ()}, True, False, 1, False,
                         False, False, 1.1, 1.5, 100, 0.7, False, False, True, False, False, 0,
                         'Gustavosta/MagicPrompt-Stable-Diffusion', '', <scripts.animatediff_ui.AnimateDiffProcess object at
                         0x0000028217B34370>, None, False, '0', '0', 'inswapper_128.onnx', 'GFPGAN', 1, True, 'ESRGAN 8x NMKD Faces',
                         1, 1, False, True, 1, 0, 0, False, 0.1, True, False, 'CUDA', False, False, False, False, 'Hyperrealism')
                         kwargs={}
11:03:06-458483 ERROR    gradio call: UnboundLocalError
╭──────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────╮
│ C:\sdnext\modules\call_queue.py:34 in f                                                                                           │
│                                                                                                                                   │
│   33 │   │   │   try:                                                                                                             │
│ ❱ 34 │   │   │   │   res = func(*args, **kwargs)                                                                                  │
│   35 │   │   │   │   progress.record_results(id_task, res)                                                                        │
│                                                                                                                                   │
│ C:\sdnext\modules\txt2img.py:64 in txt2img                                                                                        │
│                                                                                                                                   │
│   63 │   p.script_args = args                                                                                                     │
│ ❱ 64 │   processed = modules.scripts.scripts_txt2img.run(p, *args)                                                                │
│   65 │   if processed is None:                                                                                                    │
│                                                                                                                                   │
│ C:\sdnext\modules\scripts.py:498 in run                                                                                           │
│                                                                                                                                   │
│   497 │   │   parsed = p.per_script_args.get(script.title(), args[script.args_from:script.args                                    │
│ ❱ 498 │   │   processed = script.run(p, *parsed)                                                                                  │
│   499 │   │   s.record(script.title())                                                                                            │
│                                                                                                                                   │
│ C:\sdnext\scripts\xyz_grid.py:667 in run                                                                                          │
│                                                                                                                                   │
│   666 │   │   with SharedSettingsStackHelper():                                                                                   │
│ ❱ 667 │   │   │   processed = draw_xyz_grid(                                                                                      │
│   668 │   │   │   │   p,                                                                                                          │
│                                                                                                                                   │
│ C:\sdnext\scripts\xyz_grid.py:323 in draw_xyz_grid                                                                                │
│                                                                                                                                   │
│   322 │   │   │   │   │   for ix, x in enumerate(xs):                                                                             │
│ ❱ 323 │   │   │   │   │   │   process_cell(x, y, z, ix, iy, iz)                                                                   │
│   324                                                                                                                             │
│                                                                                                                                   │
│                                                      ... 7 frames hidden ...                                                      │
│                                                                                                                                   │
│ C:\sdnext\modules\sd_samplers_diffusers.py:55 in <lambda>                                                                         │
│                                                                                                                                   │
│    54 │   sd_samplers_common.SamplerData('KDPM2 a', lambda model: DiffusionSampler('KDPM2 a',                                     │
│ ❱  55 │   sd_samplers_common.SamplerData('DPM++ 1S', lambda model: DiffusionSampler('DPM++ 1S'                                    │
│    56 │   sd_samplers_common.SamplerData('DPM++ 2M', lambda model: DiffusionSampler('DPM++ 2M'                                    │
│                                                                                                                                   │
│ C:\sdnext\modules\sd_samplers_diffusers.py:108 in __init__                                                                        │
│                                                                                                                                   │
│   107 │   │   │   self.config['algorithm_type'] = 'deis'                                                                          │
│ ❱ 108 │   │   self.sampler = constructor(**self.config)                                                                           │
│   109 │   │   self.sampler.name = name                                                                                            │
│                                                                                                                                   │
│ C:\sdnext\venv\lib\site-packages\diffusers\configuration_utils.py:644 in inner_init                                               │
│                                                                                                                                   │
│   643 │   │   getattr(self, "register_to_config")(**new_kwargs)                                                                   │
│ ❱ 644 │   │   init(self, *args, **init_kwargs)                                                                                    │
│   645                                                                                                                             │
│                                                                                                                                   │
│ C:\sdnext\venv\lib\site-packages\diffusers\schedulers\scheduling_dpmsolver_singlestep.py:199 in __init__                          │
│                                                                                                                                   │
│   198 │   │   self.sample = None                                                                                                  │
│ ❱ 199 │   │   self.order_list = self.get_order_list(num_train_timesteps)                                                          │
│   200 │   │   self._step_index = None                                                                                             │
│                                                                                                                                   │
│ C:\sdnext\venv\lib\site-packages\diffusers\schedulers\scheduling_dpmsolver_singlestep.py:234 in get_order_list                    │
│                                                                                                                                   │
│   233 │   │   │   │   orders = [1] * steps                                                                                        │
│ ❱ 234 │   │   return orders                                                                                                       │
│   235                                                                                                                             │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
UnboundLocalError: local variable 'orders' referenced before assignment
```


### System Info

Version Platform Description

Windows 11, Vivaldi

Using VENV: C:\sdnext\venv
10:00:36-084245 INFO Starting SD.Next
10:00:36-099876 INFO Python 3.10.6 on Windows
10:00:36-179570 INFO Version: app=sd.next updated=2023-11-07 hash=ca7cd437
url=https://github.com/vladmandic/automatic.git/tree/master
10:00:36-399245 INFO Platform: arch=AMD64 cpu=Intel64 Family 6 Model 183 Stepping 1, GenuineIntel system=Windows
release=Windows-10-10.0.22621-SP0 python=3.10.6
10:00:36-414260 INFO nVidia CUDA toolkit detected: nvidia-smi present
10:00:36-468667 INFO Startup: standard
10:00:36-468667 INFO Verifying requirements
10:00:36-477170 INFO Verifying packages
10:00:36-477170 INFO Verifying submodules
10:00:51-957444 INFO Extensions enabled: ['Lora', 'sd-extension-chainner', 'sd-extension-system-info',
'sd-webui-agent-scheduler', 'stable-diffusion-webui-images-browser', 'stable-diffusion-webui-rembg',
'adetailer', 'OneButtonPrompt', 'sd-dynamic-prompts', 'sd-webui-animatediff',
'sd-webui-aspect-ratio-helper', 'sd-webui-reactor', 'Stable-Diffusion-Webui-Civitai-Helper',
'StyleSelectorXL']
10:00:51-971533 INFO Verifying requirements
10:00:51-987240 INFO Updating Wiki
10:00:52-473754 INFO Extension preload: {'extensions-builtin': 0.0, 'extensions': 0.0}
10:00:52-473754 INFO Command line args: ['--upgrade'] upgrade=True
10:00:57-903639 INFO Load packages: torch=2.1.0+cu121 diffusers=0.22.0 gradio=3.43.2
10:00:58-374614 INFO Engine: backend=Backend.DIFFUSERS compute=cuda mode=no_grad device=cuda
cross-optimization="Scaled-Dot-Product"
10:00:58-421892 INFO Device: device=NVIDIA GeForce RTX 4090 n=1 arch=sm_90 cap=(8, 9) cuda=12.1 cudnn=8801 driver=546.01
10:00:59-144140 INFO Available VAEs: path="models\VAE" items=4
10:00:59-144140 INFO Disabling uncompatible extensions: backend=Backend.DIFFUSERS ['multidiffusion-upscaler-for-automatic1111',
'a1111-sd-webui-lycoris']
10:00:59-316801 INFO Available models: path="models\Stable-diffusion" items=74 time=0.17
10:01:00-572565 INFO Extension: script='extensions-builtin\sd-webui-agent-scheduler\scripts\task_scheduler.py' Using sqlite file: extensions-builtin\sd-webui-agent-scheduler\task_scheduler.sqlite3
10:01:01-688158 INFO Extension: script='extensions\adetailer\scripts!adetailer.py' [-] ADetailer initialized. version: 23.11.0,
num models: 9
10:01:02-316187 INFO Extensions time: 2.80 { Lora=0.71 sd-webui-agent-scheduler=0.25 stable-diffusion-webui-images-browser=0.06
stable-diffusion-webui-rembg=0.74 adetailer=0.31 OneButtonPrompt=0.16 sd-webui-animatediff=0.08
sd-webui-aspect-ratio-helper=0.06 sd-webui-reactor=0.28 }
10:01:02-394326 INFO Load UI theme: name="invoked" style=Dark base=style.css
10:01:04-503736 INFO Local URL: http://127.0.0.1:7860/
10:01:04-503736 INFO Initializing middleware
10:01:04-629910 INFO [AgentScheduler] Task queue is empty
10:01:04-629910 INFO [AgentScheduler] Registering APIs
10:01:04-913231 INFO Select: model="AA-FaceRealism\juggernautXL_version6Rundiffusion [1fe6c7ec54]"
Loading weights: C:\sdnext\models\Stable-diffusion\AA-FaceRealism\juggernautXL_version6Rundiffusion.safetensors ━━━━━━ 0.0/7… -:--:-- GB
10:01:05-039853 INFO Setting Torch parameters: device=cuda dtype=torch.float32 vae=torch.float32 unet=torch.float32
context=inference_mode fp16=False bf16=False
10:01:05-039853 INFO Loading VAE: model=models\VAE\sdxl_vae.safetensors source=settings
10:01:05-055356 INFO Diffusers: vae="Stable Diffusion XL" class=StableDiffusionXLPipeline
file="C:\sdnext\models\Stable-diffusion\AA-FaceRealism\juggernautXL_version6Rundiffusion.safetensors"
size=6776MB
10:01:05-086621 INFO Diffusers: model="Stable Diffusion XL" class=StableDiffusionXLPipeline
file="C:\sdnext\models\Stable-diffusion\AA-FaceRealism\juggernautXL_version6Rundiffusion.safetensors"
size=6776MB

### Who can help?

_No response_


Discussion:
@LankyPoet 

we don't have any plan to add order 4 and 5 in DPM schedulers 
Is this what you are asking? I don't think we should file this as a bug report no?

let me know if I misunderstood something



Thanks. Sorry if I didn't word my post correctly. I am not asking to add higher orders to the existing samplers.
I was using the XYZ grid and when I told it to step through higher sampler solver order 1-5 with all samplers, the entire process errored out. 
My request is that diffusers should be able to handle this error without stopping the entire process. Maybe note "highest order for sampler X is 3, using that instead of 4/5". Anything rather than stop the entire grid from finishing. 
ohh I see what you mean 
we can probably raise a error message here if it helps

I think what you requested might be outside of our scope and should be handled by applications that using us

cc @patrickvonplaten 
Thank you again for considering this. I did initially report to the app author, here is what he said:

https://github.com/vladmandic/automatic/issues/2454
The author responded: "Sampler DPM++ 1S has valid orders of 1,2,3. Issue occurs when using order out of range.
If you want to have better error handling of invalid orders, you may want to report to https://github.com/huggingface/diffusers/"
@LankyPoet, could you try to reproduce the issue using just diffusers code? Otherwise it'd be hard for us to move forward here 
Thanks. Trying to figure out how to accomplish that, I only know the GUI of the app I use. Will update if I can figure it out.
@patrickvonplaten this is a pretty trivial item, root cause is 

https://github.com/huggingface/diffusers/blob/8092017d3f67b8da09a85c2368ea5d88ae8b4a6e/src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py#L212-L234

there is if/elif/elif but no else so `orders` param never gets set. simple solution is change last `if order == 3` to `if order >= 3`

i understand that order > 3 is not supported by this scheduler, but it is by some others and goal is to enable usage in our xyz grid so user can test multiple settings to produce a grid.

I don't think the solver's order is supposed to be larger than 3 - see: https://github.com/huggingface/diffusers/blob/8092017d3f67b8da09a85c2368ea5d88ae8b4a6e/src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py#L96
I agree, ask is to either force 3 as max or add assert - both/either to avoid runtime errors. Diffusers perform validation for most of other user inputs.

Happy to throw a `ValueError` when order is > 3 - @LankyPoet would you maybe like to open an issue? 
Yes but isn’t that what this issue already addresses? I can create another
but I feel like it is duplicating.

On Tue, Nov 21, 2023 at 9:21 AM Patrick von Platen ***@***.***>
wrote:

> Happy to throw a ValueError when order is > 3 - @LankyPoet
> <https://github.com/LankyPoet> would you maybe like to open an issue?
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/diffusers/issues/5705#issuecomment-1821016791>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BDALA3MOJMVT7Y7PJGGKXQTYFS2FVAVCNFSM6AAAAAA7C66BA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGAYTMNZZGE>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>

@LankyPoet he meant "to open a PR to fix this":) 
> @LankyPoet he meant "to open a PR to fix this":)

I tried my best but don't think I did it right. The pull request shows up in my own account, not in huggingface. I am sorry I am new to this. Here is the updated file if you can pull it in?
https://github.com/huggingface/diffusers/compare/main...LankyPoet:diffusers:LankyPoet-dpmsolverpatch-1

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md) are likely to be ignored.
@yiyixuxu Hi, I see the stale note, not sure if you saw my last reply and if it was usable? Thank you.
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md) are likely to be ignored.
Hi, again just sending a reminder in case this has not been addressed. I think it's a good thing to incorporate to improve error-handling.
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md) are likely to be ignored.
@yiyixuxu 

Since this is a really easy fix it could be tagged with `contributions-welcome` and `good first issue`. If no one takes it I can do it.
I've taken this into work 🤗 

Resolving patch:
diff --git a/src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py b/src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
--- a/src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
+++ b/src/diffusers/schedulers/scheduling_dpmsolver_singlestep.py
@@ -223,6 +223,8 @@ def get_order_list(self, num_inference_steps: int) -> List[int]:
         """
         steps = num_inference_steps
         order = self.config.solver_order
+        if order > 3:
+            raise ValueError("Order > 3 is not supported by this scheduler")
         if self.config.lower_order_final:
             if order == 3:
                 if steps % 3 == 0:


Test patch: