Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

foreign exception error #76

Open
ralyodio opened this issue May 18, 2023 · 12 comments
Open

foreign exception error #76

ralyodio opened this issue May 18, 2023 · 12 comments
Labels
bug Something isn't working ffi bug confirmed the exception should be caught in foreign language

Comments

@ralyodio
Copy link

ralyodio commented May 18, 2023

llama.cpp: loading model from /home/ubuntu/models/ggml-gpt4all-j-v1.3-groovy.bin
fatal runtime error: Rust cannot catch foreign exceptions
Aborted2023-05-18T11:49:39.270396Z  INFO surrealdb::net: SIGTERM received. Start graceful shutdown...    
2023-05-18T11:49:39.270450Z  INFO surrealdb::net: Shutdown complete. Bye!    

==> /var/log/descriptive-web.log <==
@ralyodio
Copy link
Author

ralyodio commented May 18, 2023

again catch and throw but we shouldn't be crashing or exiting when this happens.

also are any of these models supported right now? https://gpt4all.io/models/models.json

@hlhr202
Copy link
Member

hlhr202 commented May 18, 2023

This is not a llama based model, so it cannot be used on llama.cpp backend.
According to its hugging face page, the model is based on GPT-J
I m not sure if llm-rs backend supports this or not, but llama.cpp definitely not.

@hlhr202 hlhr202 added the invalid This doesn't seem right label May 18, 2023
@ralyodio
Copy link
Author

ralyodio commented May 18, 2023

yeah should it crash though?? log an error I understand. but crash??

i have this code wrapped in a try/catch from my side and it isn't catching.

@hlhr202
Copy link
Member

hlhr202 commented May 18, 2023

yeah should it crash though?? log an error I understand. but crash??

i have this code wrapped in a try/catch from my side and it isn't catching.

this error is not catchable at current stage. or you can open issue on llama.cpp github space. loading model file is unsafe for rust side and i can only get a nullptr when loaded failed. but in this case, i cant even get any response from the low level side.

generally, you shouldnt use this model with llama.cpp at all. the termination and error is not thrown to upper level. its more like playing fire.

@ralyodio
Copy link
Author

in my use case i have an api that uses this library, it allows people to pick from a list of models. Its possible I have models that aren't supported, so ideally it wouldn't take down my entire backend if someone picked an incompatible file.

you can't do try/catch around file loading?

@hlhr202
Copy link
Member

hlhr202 commented May 18, 2023

yea. basically this is very early stage library and not production ready. every release i v tagged with pre release. i admit this is essentially a toy app. and my upper stream llama.cpp/llm-rs even updating every few hours. how can i promise that everything just work in purpose?

@hlhr202
Copy link
Member

hlhr202 commented May 18, 2023

or maybe you can do something with it maybe find a way to fix. i wont suggest you use it in any production scenario or you have to keep the dangerous away from user input.

@hlhr202 hlhr202 added bug Something isn't working and removed invalid This doesn't seem right labels May 18, 2023
@hlhr202
Copy link
Member

hlhr202 commented May 18, 2023

i will leave this temporily as bug till i find a way to fix

@hlhr202 hlhr202 added the ffi bug confirmed the exception should be caught in foreign language label May 19, 2023
@hlhr202
Copy link
Member

hlhr202 commented May 19, 2023

double confirmed this error should be handled in llama.cpp

@NitayRabi
Copy link

Hey, @ralyodio don't know if you managed to work around this, but my solution was using "@llama-node/core" and passing modelType, with that I was able to use both a GPT-J model and a Llama model from GPT4All -

const { ModelType } = require("@llama-node/core");
const { LLM } = require("llama-node");
const { LLMRS } = require("llama-node/dist/llm/llm-rs.cjs");
const path = require("path");

const modelPath = process.argv[2]
const modelType = process.argv[3]
const prmpt = process.argv[4]

const llama = new LLM(LLMRS);

const toChatTemplate = (prompt: string) => `### Instruction:
${prompt}

### Response:`;

const run = async () => {
    const params = {
        prompt: toChatTemplate(prmpt),
        numPredict: 128,
        temperature: 0.8,
        topP: 1,
        topK: 40,
        repeatPenalty: 1,
        repeatLastN: 64,
        seed: 0,
        feedPrompt: true,
    };
    await llama.load({ modelPath, modelType });
    await llama.createCompletion(params, (response) => {
        process.stdout.write(response.token);
    });
};

run();

@linonetwo
Copy link

linonetwo commented Jul 4, 2023

This fatal error will crash the whole app even try-catch + worker_thread is used. Better if you can just throw a JS error (sub-class so we can switch-case the instanceof error) instead!

The error thrown on my case that the modelPath not exist.

linonetwo added a commit to tiddly-gittly/TidGi-Desktop that referenced this issue Jul 4, 2023
linonetwo added a commit to tiddly-gittly/TidGi-Desktop that referenced this issue Jul 8, 2023
@HolmesDomain
Copy link

I have a similar issue as well. Hope it gets fixed in llama.cpp or wherever.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working ffi bug confirmed the exception should be caught in foreign language
Projects
None yet
Development

No branches or pull requests

5 participants