cassiebreviu / StableDiffusion

Inference Stable Diffusion with C# and ONNX Runtime
MIT License
218 stars 49 forks source link

SchedulerBase.cs Interpolate Index out of range #26

Closed sergiosolorzano closed 10 months ago

sergiosolorzano commented 11 months ago

At Interpolate method:

I think sigmas[-1] is python's equivalent to the last element and hence supposed to be sigmas[range.Length-1]

``// If timesteps[i] is greater than the last element in range, use the last value in sigmas

            else if (index == -range.Length - 1)
            {
                result[i] = sigmas[-1];
            }

A second possible issue with the above mentioned snippet is the condition:

else if (index == -range.Length - 1)

For example, I observe that if range is an array length 1000 with values 0,1,2,...999 and timesteps is an array length 100 with values 0,10,20...999: int index = Array.BinarySearch(range, timesteps[i]); where timesteps[i]=999, index=-1001 whilst I would have expected index=999 because this value is found in range at index 999.

cassiebreviu commented 10 months ago

I will review the pr and get this issue resolved. Thanks!

OgreTransporter commented 9 months ago

Why was the ticket closed? The error is still there! A negative index in arrays or lists does not work!

https://github.com/cassiebreviu/StableDiffusion/blob/0dd55be2bc54db1ec7273a88b0f161336b8d4508/StableDiffusion.ML.OnnxRuntime/SchedulerBase.cs#L48

If you only want to get the last element of the array/list, you can also use the function Last from Linq.

result[i] = sigmas.Last();