{
    "componentChunkName": "component---src-templates-note-note-js",
    "path": "/notes/running-models-in-your-browser",
    "result": {"data":{"mdx":{"body":"var _excluded = [\"components\"];\nfunction _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n/* @jsxRuntime classic */\n/* @jsx mdx */\n\nvar _frontmatter = {};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n    props = _objectWithoutProperties(_ref, _excluded);\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"p\", null, \"If you're looking for alternatives to ONNX for running machine learning models directly in the browser, several robust options exist, each with its own strengths and ecosystem. Here are the primary alternatives:\"), mdx(\"h2\", null, \"TensorFlow.js\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"TensorFlow.js\"), \" is a mature and widely used library that allows you to run pre-trained TensorFlow models or even train models directly in the browser or in Node.js.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"It supports both CPU and GPU (via WebGL) execution, and has a rich collection of pre-trained models for tasks like image recognition, pose detection, and NLP.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Models must be converted to the TensorFlow.js format for browser use, which can be done with the \", mdx(\"inlineCode\", {\n    parentName: \"li\"\n  }, \"tensorflowjs_converter\"), \" tool\", \"[1][2]\", \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Best for: Web-based applications requiring flexible deployment and access to a large ecosystem of models\", \"[1][2]\", \".\")), mdx(\"h2\", null, \"WebDNN\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"WebDNN\"), \" is developed by the University of Tokyo and focuses on optimizing deep neural network models for browser execution.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"It supports multiple backends: WebGPU, WebGL, WebAssembly, and a pure JavaScript fallback, enabling efficient execution across browsers.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"WebDNN is known for compressing models and accelerating execution for zero-overhead inference\", \"[1]\", \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Best for: High-performance in-browser inference, especially for models trained in frameworks like Keras, Chainer, or PyTorch (with conversion)\", \"[1]\", \".\")), mdx(\"h2\", null, \"Transformers.js\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Transformers.js\"), \" is a JavaScript library that brings Hugging Face-style transformer models (like BERT, GPT-2, etc.) to the browser, leveraging WebAssembly for performance.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"It supports a variety of NLP and vision tasks and can load pre-trained models directly, running them fully client-side\", \"[2][6]\", \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Models are typically smaller due to browser constraints, but it is ideal for privacy-sensitive or offline applications.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Best for: Running popular NLP models in-browser with no backend dependencies\", \"[2][6]\", \".\")), mdx(\"h2\", null, \"Wasm (WebAssembly) + Custom Runtimes\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"WebAssembly (Wasm)\"), \" allows you to compile and run lightweight models in the browser, often used as a backend for other libraries (like ONNX.js, Transformers.js, or even custom C/C++ inference engines).\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Libraries like \", mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"ggml.js\"), \" and TVM compiled to Wasm provide alternatives for running models entirely client-side, supporting efficient inference for smaller models\", \"[2][5]\", \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Best for: Lightweight models and applications where maximum portability and client-side execution are required\", \"[2][5]\", \".\")), mdx(\"h2\", null, \"TVM (Tensor Virtual Machine)\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"TVM\"), \" is an open-source machine learning compiler stack that can lower models to WebAssembly for browser execution.\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"It is focused on producing highly optimized binaries for inference, leveraging SIMD and other performance features available in modern browsers\", \"[5]\", \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"Best for: Performance-intensive workloads where low-level optimization is important\", \"[5]\", \".\")), mdx(\"h2\", null, \"Comparison Table\"), mdx(\"table\", null, mdx(\"thead\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"thead\"\n  }, mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Library/Framework\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Supported Models\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Browser Backends\"), mdx(\"th\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Notable Strengths\"))), mdx(\"tbody\", {\n    parentName: \"table\"\n  }, mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"TensorFlow.js\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"TensorFlow, Keras\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"WebGL, WASM, CPU\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Large ecosystem, flexible deployment\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"WebDNN\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Keras, Chainer, etc.\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"WebGPU, WebGL, WASM\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"High performance, model compression\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Transformers.js\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Transformers (NLP/CV)\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"WASM\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Hugging Face models, easy to use\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Wasm + Custom\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"C/C++ models, TVM\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"WASM\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Custom/optimized inference engines\")), mdx(\"tr\", {\n    parentName: \"tbody\"\n  }, mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"TVM\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Many (via lowering)\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"WASM\"), mdx(\"td\", {\n    parentName: \"tr\",\n    \"align\": null\n  }, \"Near-native performance, SIMD support\")))), mdx(\"h2\", null, \"Summary\"), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"TensorFlow.js\"), \" and \", mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"WebDNN\"), \" are the most mature general-purpose alternatives to ONNX for browser-based model inference\", \"[1][2]\", \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Transformers.js\"), \" is ideal for running transformer-based models in-browser, especially for NLP tasks\", \"[2][6]\", \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"strong\", {\n    parentName: \"li\"\n  }, \"Wasm-based custom runtimes\"), \" (like ggml.js or TVM) provide flexibility and performance for specialized needs\", \"[5]\", \".\"), mdx(\"li\", {\n    parentName: \"ul\"\n  }, \"The choice depends on your model type, performance requirements, and preferred frameworks.\")), mdx(\"p\", null, \"If you have specific models or tasks in mind (e.g., speech-to-text, vision, NLP), the best alternative may vary. Let me know if you need recommendations tailored to a particular use case!\"), mdx(\"p\", null, \"Citations:\\n\", \"[1]\", \" \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://shreyansh26.github.io/post/2021-01-25_deep_learning_in_the_browser/\"\n  }, \"https://shreyansh26.github.io/post/2021-01-25_deep_learning_in_the_browser/\"), \"\\n\", \"[2]\", \" \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://dev.to/kenangain/the-future-of-local-llm-execution-running-language-models-locally-with-ollama-onnx-and-more-4f97\"\n  }, \"https://dev.to/kenangain/the-future-of-local-llm-execution-running-language-models-locally-with-ollama-onnx-and-more-4f97\"), \"\\n\", \"[3]\", \" \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/microsoft/onnxjs\"\n  }, \"https://github.com/microsoft/onnxjs\"), \"\\n\", \"[4]\", \" \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://dev.to/hexshift/run-ai-models-entirely-in-the-browser-using-webassembly-onnx-runtime-no-backend-required-4lag\"\n  }, \"https://dev.to/hexshift/run-ai-models-entirely-in-the-browser-using-webassembly-onnx-runtime-no-backend-required-4lag\"), \"\\n\", \"[5]\", \" \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://www.reddit.com/r/MachineLearning/comments/179uwbq/d_tensorflowjs_and_state_of_the_ecosystem_for/\"\n  }, \"https://www.reddit.com/r/MachineLearning/comments/179uwbq/d_tensorflowjs_and_state_of_the_ecosystem_for/\"), \"\\n\", \"[6]\", \" \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://techcommunity.microsoft.com/blog/educatordeveloperblog/use-webgpu--onnx-runtime-web--transformer-js-to-build-rag-applications-by-phi-3-/4190968\"\n  }, \"https://techcommunity.microsoft.com/blog/educatordeveloperblog/use-webgpu--onnx-runtime-web--transformer-js-to-build-rag-applications-by-phi-3-/4190968\"), \"\\n\", \"[7]\", \" \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://github.com/lutzroeder/netron\"\n  }, \"https://github.com/lutzroeder/netron\"), \"\\n\", \"[8]\", \" \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"https://onnxruntime.ai/docs/tutorials/web/\"\n  }, \"https://onnxruntime.ai/docs/tutorials/web/\")));\n}\n;\nMDXContent.isMDXComponent = true;","inboundReferences":[]}},"pageContext":{"slug":"running-models-in-your-browser","node":{"childMdx":{"slug":"running-models-in-your-browser"}}}},
    "staticQueryHashes": []}