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

[Bug] RangeError: offset is out of bounds for text2text generation #370

Closed
do-me opened this issue Oct 26, 2023 · 2 comments
Closed

[Bug] RangeError: offset is out of bounds for text2text generation #370

do-me opened this issue Oct 26, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@do-me
Copy link
Contributor

do-me commented Oct 26, 2023

I am using Xenova/LaMini-Flan-T5-783M for a simple RAG pipeline in SemanticFinder and it works like a charm on the first call. Whenever I want to run a second query, i.e. running the same model again I get the following error "out of bounds/range".

For reproduction, simply click Find in SemanticFinder, then Chat, wait for the output to appear and then a second time Chat.

Chrome:

image

Firefox:

image

I'm using transformers.js 2.6.2.

The worker.js here is pretty standard:

let tokenizer;

let chatModel = 'Xenova/LaMini-Flan-T5-783M';

async function token_to_text(beams){
    let chatTokenizer = await AutoTokenizer.from_pretrained(chatModel);
    let decoded_text =  chatTokenizer.decode(beams[0].output_token_ids, {
        skip_special_tokens: true
    });
    console.log(decoded_text);
    return decoded_text
}

// other code 

   case 'chat':
            text = message.text.trim()
            let max_new_tokens = message.max_new_tokens
            console.log(max_new_tokens, chatModel, text)

            let chatGenerator = await pipeline('text2text-generation', chatModel,
                {
                    progress_callback: data => {
                        self.postMessage({
                            type: 'chat_download',
                            data
                        });
                    }
                });

            let thisChat = await chatGenerator(text, {
                max_new_tokens: max_new_tokens,
                return_prompt: false,
                callback_function: async function (beams) {
                    //console.log(beams);
                    const decodedText = token_to_text(beams)
                    console.log(decodedText);
                }
            });

            self.postMessage({
                type: 'chat',
                chat: thisChat
            });

            break;

I was hesitant to create an issue here because I thought it was related to my code but it's weird that it's actually creating the first token of the answer and then fails. Also, I tested with e.g. Xenova/t5-small for text2text and didn't encounter the problem.

Is it possible that there is some kind of memory issue here?

@do-me do-me added the bug Something isn't working label Oct 26, 2023
@felladrin
Copy link
Contributor

felladrin commented Oct 26, 2023

Hi! It seems to be the same case from #8 (comment); the solution, as Xenova mentions, is to call await pipeline() only once during the execution of the app.

And you probably didn't encounter the problem with Xenova/t5-small because it's small, and you haven't instantiated it enough times to fill up the memory.

PS: SemanticFinder looks great! 💯

@do-me
Copy link
Contributor Author

do-me commented Oct 26, 2023

Argh, that totally makes sense, thank you! I should have better searched through the closed issues too 🤦
So I had the same issue all along in the summary function too, only that the model is small enough to be instantiated several times...
Thanks for the nice words! :)

@do-me do-me closed this as completed Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants