Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Gets stuck in infinte loops when requested to generate code #58

Closed
sukhoy opened this issue Mar 29, 2023 · 10 comments
Closed

Gets stuck in infinte loops when requested to generate code #58

sukhoy opened this issue Mar 29, 2023 · 10 comments

Comments

@sukhoy
Copy link

sukhoy commented Mar 29, 2023

I used ./gpt4all-lora-quantized-OSX-m1

> Give me a C++ algorithm for the integer square root (isqrt).
The following is an implementation of iSqrt() function which returns the integer Square Root of its argument, in terms of unsigned long ints on 32-bit systems. It uses Newton's method to find a better approximation as it iterates through each iteration until convergence or exceeding maximum number of iterations allowed (10).
```cpp
#include <iostream>
using namespace std; // for cout << endl;
unsigned long int iSqrt( unsigned long int n ) {
    if (n <= 2) return n *= 3/2 + sqrt((double)(n*n)); else{
        double x = pow(-1.0, floor(.5*(log(fabs(n)))+1./4))/(sqrt(6)*pow(x,3)/pi); // Newton's method for integer square root calculation;
    unsigned long int result= (unsigned)floor((double)(x)); 	// convert double to signed integer.
        if ((result-fabs(n/2+1))) { x = pow(-1.0,( floor(.5*(log(fabs(x)))) + .75))/(sqrt(6)*pow(x,3)/pi); } // Newton's method for double square root calculation;
        if (result-floor((double)(n/2+1))) { x = pow(-1.0,( floor(.5*(log(fabs(x)))) + .75))/(sqrt(6)*pow(x,3)/pi); } // Newton's method for double square root calculation;
        if (result-floor((double)(n/2+1))) { x = pow(-1.0,( floor(.5*(log(fabs(x)))) + .75))/(sqrt(6)*pow(x,3)/pi); } // Newton's method for double square root calculation;
 ... keeps repeating the last line until stopped ...

Another session:

> Give me a C++ algorithm for the integer square root (isqrt).
Here's one way to implement iSqrt in C++, using an array of integers and dynamic programming techniques:
```cpp
int sqr(const int& num) { // returns squared value, not just a number
    constexpr auto MAX = (std::numeric_limits<decltype>::max)*2;// max possible square root for any integer <= this limit

    if (num < 0 || std::abs(int64_t{1}) == num) { // handle special cases like -ve numbers and 1 itself
        return sqr(-std::fmod<decltype>(-std::floor, int64_t{2}, MAX));//return floor of the square root for negative number or just take it as is if positive.
    } else { // handle normal cases like nonnegative numbers > 1 (iSqrt)
        constexpr auto sqr = std::pow(std::fabs<decltype>(num),2);//return squared value of the input integer number for isqrt calculation

        if ((int64_t{0} == num && int64_t{1}) || (sqr <= MAX)) { //handle special cases like 0 and sqrt(1) which are both irrational numbers.
            return std::fmod<decltype>(-std::floor, sqr);//return floor of the square root for these two values as they have no rational value to represent them in iSqrt calculation.
        } else { //handle normal cases like nonnegative integers > 1 (iSquare)
            constexpr auto num2 = std::fabs<decltype>(num);//return absolute value of the input integer number for sqr(x).

            if ((sqr <= MAX && int64_t{0} == num || (int64_t{1}) > 3) //handle special cases like sqrt(2), which is irrational and has no rational value to represent it in iSqrt calculation.
                return std::fmod<decltype>(-std::floor, int64_t{num/int64_t{1}});//return floor of the square root for these two values as they have irrational numbers and no rational value to represent them in iSqrt calculation.
            else { //handle normal cases like nonnegative integers > 2 (iSquare)
                constexpr auto num3 = std::fabs<decltype>(num);//return absolute value of the input integer number for sqr(x).

                if ((sqr <= MAX && int64_t{0} == num || (int64_t{1}) > 2) //handle special cases like sqrt(3), which is irrational and has no rational value to represent it in iSqrt calculation.
                    return std::fmod<decltype>(-std::floor, int64_t{num/int64_t{1}});//return floor of the square root for these two values as they have irrational numbers and no rational value to represent them in iSqrt calculation.
                else { //handle normal cases like nonnegative integers > 3 (iSquare)
                    constexpr auto num4 = std::fabs<decltype>(num);//return absolute value of the input integer number for sqr(x).
@Johnreidsilver
Copy link

Also happens sometimes in Linux, like a loop of verbiage

#48

@xdevfaheem
Copy link

It is Said in the Training Log About This...

@sukhoy
Copy link
Author

sukhoy commented Mar 30, 2023

There it produced valid code. Here there’s no valid code. No idea if the underlying issue is the same.

@hawkeye-sama
Copy link

Same here

image

@aleksusklim
Copy link

There should be options repeat_last_n and repeat_penalty, you may try to set like --repeat_last_n 4096 --repeat_penalty 1.5, but will it correctly work or not is a different question.

@sukhoy
Copy link
Author

sukhoy commented Mar 30, 2023

It won't correctly work, at least in my example. It answers a different question.

> Give me a C++ algorithm for the integer square root (isqrt)
Here'll be your code snippet to calculate sqrt of any positive number in cpp using function overloading technique :  ```cpp`int i, j; // Declare two variables int arr[10];//Declaring array with capacity as per requirement `void main() { scanf("%d", &n); printf("Enter Number\t"); getchar(); } while(arr != NULL && n > -2){ if((j = atoi(&std::cin >> std::ws)) == EOF || !isdigit(*&eof)){ eprintf("\r" << "Invalid input.\nTry Again."); continue;} else{if(!strcmp_icaseins(_T('\x7F'), _T(' '), strtok())) return;`

Well, fair enough. Sounds like useful code generation is a bit too hard for it atm :-)

@sukhoy
Copy link
Author

sukhoy commented Mar 30, 2023

Just to wrap things up, here's a response from GPT-4. Spoiler alert: it gets it perfectly right.

image

@aleksusklim
Copy link

It even tries to circumvent repeat penalty!

### Instructions (cont.):


### Response:


### Instructuions(cont):


#####Instruction: ####Response:

#####Instruction: ###Response:

#########Instruction: # Response:

#################Instruction: ##Response:

******************Instruction: ****Response:*****

#################Instruction: **Response:*********/

/////////////////////Instruction: /////Response://////////

////////////////////////////Instruction:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://

////////////////////////////Instruction: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::/

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::~

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::o

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::l

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::r

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::v

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::t

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::c

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::a

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::d

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::b

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::f

////////////////////////////Instruction: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::g

////////////////////////////Instruction: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::h

////////////////////////////Instruction: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::i

////////////////////////////Instruction: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::j

////////////////////////////Instruction: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::k

////////////////////////////Instruction: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::l

////////////////////////////Instruction: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::m

@iSuslov
Copy link

iSuslov commented Apr 1, 2023

@AndriyMulyar Why is it closed without any notice? This bug still exists.

@AndriyMulyar
Copy link
Contributor

Closed as this is not an issue that can be solved with a pull request. We are training improved models to deploy on edge which will progressively perform better on more difficult tasks such as the one you posed.

I encourage you to keep using OpenAI and we'll focus on making edge LLMs sicker, more powerful and based on a strong open source foundation!

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

No branches or pull requests

7 participants