microsoft / onnxruntime-inference-examples

Examples for using ONNX Runtime for machine learning inferencing.
MIT License
1.05k stars 311 forks source link

Chat with onnxruntime-web fails when i deployed on my machine #438

Open salimngit opened 1 month ago

salimngit commented 1 month ago

Chat with onnxruntime-web example deployed with

"onnxruntime-web": "1.19.0-dev.20240509-69cfcba38a" and associated wasm files from https://cdn.jsdelivr.net/npm/onnxruntime-web@1.19.0-dev.20240509-69cfcba38a/dist/

live demo https://guschmue.github.io/ort-webgpu/chat/index.html works just fine.

When i run locally, i receive the below error

Error: found infinitive in logits at LLM.argmax () at LLM.generate () at async Query ()
  | (anonymous) | @ | main.js:141 -- | -- | -- | --   | Promise.catch (async) |   |     | submitRequest | @ | main.js:140   | (anonymous) | @ | main.js:167
fosteman commented 1 week ago

@salimngit, it looks like you're encountering an error related to the presence of infinite values in the logits during the inference process with onnxruntime-web. This can happen due to various reasons, including model issues, input data anomalies, or bugs in the runtime.

Here are a few steps you can take to troubleshoot and resolve this issue:

  1. Check Input Data:

    • Ensure that the input data fed to the model is properly preprocessed and normalized. Incorrect input data can lead to invalid computations resulting in infinite values.
  2. Model Integrity:

    • Verify that the model file is not corrupted. Re-download the model if necessary and ensure that it is correctly loaded in your code.
  3. Runtime Version:

    • Make sure you are using the correct version of onnxruntime-web and associated WASM files. Since you mentioned using a specific development version, confirm that the paths to the WASM files are correct and they are accessible.
  4. Check for Known Issues:

    • Look for any known issues or bugs reported with the version you are using. Sometimes, development versions might have unresolved bugs that could be causing the problem.
  5. Error Handling:

    • Add additional error handling in your code to catch and log the specific values causing the issue. This can help pinpoint the exact cause of the infinite values.

Here is an example of how you might add error handling to check for infinite values in logits:

async function generateResponse(input) {
    try {
        const logits = await LLM.generate(input);

        // Check for infinite values in logits
        if (logits.some(value => !isFinite(value))) {
            throw new Error("Found infinite value in logits");
        }

        const response = LLM.argmax(logits);
        return response;
    } catch (error) {
        console.error("Error in generateResponse:", error);
        // Handle the error appropriately
    }
}

async function submitRequest(input) {
    try {
        const response = await generateResponse(input);
        // Process the response
    } catch (error) {
        console.error("Error in submitRequest:", error);
        // Handle the error appropriately
    }
}

Verify Local Setup:

Compare with Working Demo:

Debugging Tips:

By following these steps, you should be able to identify and resolve the issue with infinite values in the logits during model inference.