Transformers.js documentation

backends/onnx

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

backends/onnx

Handler file for choosing the correct version of ONNX Runtime, based on the environment. Ideally, we could import the onnxruntime-web and onnxruntime-node packages only when needed, but dynamic imports don’t seem to work with the current webpack version and/or configuration. This is possibly due to the experimental nature of top-level await statements. So, we just import both packages, and use the appropriate one based on the environment:

  • When running in node, we use onnxruntime-node.
  • When running in the browser, we use onnxruntime-web (onnxruntime-node is not bundled).

This module is not directly exported, but can be accessed through the environment variables:

import { env } from '@xenova/transformers';
console.log(env.backends.onnx);

backends/onnx.ONNX : <code> * </code>

The ONNX runtime module.

Kind: static property of backends/onnx


< > Update on GitHub