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

Putting pipeline into a function or loop breaks output. #1134

Open
1 of 5 tasks
ziggycross opened this issue Jan 3, 2025 · 3 comments
Open
1 of 5 tasks

Putting pipeline into a function or loop breaks output. #1134

ziggycross opened this issue Jan 3, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@ziggycross
Copy link

ziggycross commented Jan 3, 2025

System Info

macOS Sequoia 15.2
@huggingface/[email protected]
No framework, bundling with Webpack, and opening in Chrome

Environment/Platform

  • Website/web-app
  • Browser extension
  • Server-side (e.g., Node.js, Deno, Bun)
  • Desktop app (e.g., Electron)
  • Other (e.g., VSCode extension)

Description

I am building a sentiment analyser using pipeline.

I have a classifier pipeline that appears to be working, however it always returns the same result whenever I put it in a function, a loop, or pass an array.

I can call it again outside of this scope and it returns to work as expected.

I have tried this with Xenova/distilbert-base-uncased-finetuned-sst-2-english and Xenova/toxic-bert and got the same results.

No errors are being raised yet it is giving incorrect results.

Reproduction

import { pipeline } from "@huggingface/transformers";

const classifier = await pipeline("sentiment-analysis", 'Xenova/distilbert-base-uncased-finetuned-sst-2-english', {
    dtype: "fp16",
    device: "webgpu",
});

// Works fine here
console.log(await classifier("Hello world")); // label: POSITIVE (0.99)
console.log(await classifier("Oh no!")); // label: NEGATIVE (0.56)

// Broken with helper function
const classify = async (text) => {
    const result = await classifier(text);
    return result;
}
console.log(await classify("Hello world!")); // label: NEGATIVE (0.56)
console.log(await classify("Oh no!")); // label: NEGATIVE (0.56)

// Broken with iterator
const texts = ["Hello world!", "Oh no!"];
for (const text of texts) {
    const result = await classifier(text);
    console.log(result); // label: [NEGATIVE (0.56), NEGATIVE (0.56)]
}

// Broken with batching
console.log(await classifier(["Hello world!", "Oh no!"])); // label: [NEGATIVE (0.56), NEGATIVE (0.56)]

// Still works fine
console.log(await classifier("Hello world")); // label: POSITIVE (0.99)
console.log(await classifier("Oh no!")); // label: NEGATIVE (0.56)
@ziggycross ziggycross added the bug Something isn't working label Jan 3, 2025
@DanielYakubov
Copy link

bumping for interest, let me know when it gets solved

@xenova
Copy link
Collaborator

xenova commented Jan 4, 2025

Thanks for the report. Could you confirm whether this also occurs with WASM (and fp32 on WebGPU)? Might be related to microsoft/onnxruntime#23183 (comment). cc @guschmue

@ziggycross
Copy link
Author

Can confirm it doesn't happen on fp32 or WASM, and does still happen on q8 with WebGPU. That would point to the ONNX thing, right?

Let me know if there's anything I can do to help :)

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

3 participants