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

feat: exposing onnx backend to JS land #436

Merged
merged 21 commits into from
Nov 12, 2024
Merged

Conversation

kallebysantos
Copy link
Contributor

What kind of change does this PR introduce?

Feature, Enhancement

What is the current behavior?

When using huggingface/transformers.js the model inference are wasm handled with onnxruntime-web library.

What is the new behavior?

This PR adds compatibility to exposed ORT feature. It allows to use transformers.js with the current native rust ORT and all its optimizations.

How to use it

The onnx backend is implicitly exposed to transformers.js v3 and the only code change needed from final users is to add device: 'auto'.

Currently there are an open PR to simplify it, but while it wasn't merged yet we need to follow the example bellow:

import { env, pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]';

// Ensure we do not use browser cache
env.useBrowserCache = false;
env.allowLocalModels = false;

const pipe = await pipeline('feature-extraction', 'supabase/gte-small', { device: 'auto' });

const output = await pipe("This embed will be generated from rust land", { pooling: 'mean', normalize: true });

Tested pipelines

NLP

  • feature-extraction
  • fill-mask
  • text-classification
  • token-classification
  • zero-shot-classification
  • text-generation
  • text2text-generation
  • translation
  • summarization
  • question-answering

Computer vision

  • image-feature-extraction
  • image-classification
  • zero-shot-image-classification

This pipelines was only manually tested:

  • object-detection *
  • depth-estimation *
  • image-segmentation *

@laktek
Copy link
Contributor

laktek commented Nov 5, 2024

@kallebysantos Looks like you'd need to rebase :)

kallebysantos and others added 21 commits November 11, 2024 20:31
Simple integration between `transformers.js` and rust ort backend by
exposing js owned API
- Implementing v8 traits to cast tensors `ToV8` and `FromV8`.
- Resolving `ort::Tensor` type based on Js tensor's.
- Since `serde_v8` allows zero-copy we use it to handle the model
inputs and send back the outputs
- Solved the "`GetMutableData` should not be a null pointer" error while
executing seq2seq models.
- Ref.: pykeio/ort#185
- Applying integration tests over all NLP pipelines with ort backend
- Applying integration tests over VISION pipelines with ort backend
Copy link
Contributor

@laktek laktek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! thanks for the contribution @kallebysantos 🎊

@laktek laktek merged commit 1052be2 into supabase:main Nov 12, 2024
3 checks passed
Copy link

🎉 This PR is included in version 1.62.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants