Ai00-X / ai00_server

A localized open-source AI server that is better than ChatGPT.
https://ai00-x.github.io/ai00_server/
MIT License
434 stars 54 forks source link

2 bugs in mirostat sampler #105

Closed cahya-wirawan closed 2 months ago

cahya-wirawan commented 2 months ago

Hi,

  1. The first bug is in the function estimate_s. The function is unstable because the probability in denominator could be 0.0. As result, num below become NaN.
Screenshot 2024-04-20 at 16 04 23
  1. The second bug is in the function compute_k. This function is very unstable, the result is overflow. Screenshot 2024-04-20 at 18 26 04

A plot of the formula *k = (eps 2.0_f32.powf(tau) / (1.0 - n.powf(-eps))).powf(1.0 / s)** using wolframalpha show its stability:

Screenshot 2024-04-20 at 18 17 15
cryscan commented 2 months ago

The power in the formula is n^(-eps) so it should be 65536^(1-x), and this is what I get: 0dfe9c2e2e77fe3837a0999ba6f61300

And yes, estimate_s is unstable.

cryscan commented 2 months ago

Just pushed a fix. would you like to try again?

cahya-wirawan commented 2 months ago

yes, may bad, I overlook -eps. I tried the fix, it runs now without overflow so far. However, the formula is in my opinion unstable because k is undefined for s==1.0 and s==0. k is also huge or overflow for -0.5<s<0.

Screenshot 2024-04-21 at 15 54 37