feat(embeddings): expose Transformers.js runtime options - #17
Merged
harlan-zw merged 2 commits intoAug 12, 2026
Merged
Conversation
The transformers.js provider pinned `dtype: 'fp32'`, never passed a `device`, and threw for any model outside the dimension registry. Three changes, all backward compatible: Expose `device` and `dtype`. Transformers.js defaults `device` to `cpu` under Node, leaving the accelerated backends that onnxruntime-node already bundles unreachable. `device` is only forwarded when set, and `dtype` keeps its `fp32` default, so device resolution is unchanged when both are omitted. Probe dimensions when the registry has no entry, instead of throwing "Unknown dimensions for model X". The Ollama provider already did this; without it any Hugging Face repo outside the registry was unusable even though the pipeline loaded fine. Registry hits and an explicit `dimensions` option skip the probe. Repoint the `bge-large-en-v1.5` preset from `onnx-community/bge-large-en-v1.5`, whose weights return 401, to `Xenova/bge-large-en-v1.5`, which carries the same weights plus quantized and fp16 variants. `resolveModelForPreset` and `getModelDimensions` both succeeded for the broken preset, so nothing surfaced it until the model failed to load. Benchmarked on an Apple M5 Max, 120 documents, best of 3 after warm-up (docs/sec): model cpu coreml webgpu bge-small-en-v1.5 664 198 1713 bge-base-en-v1.5 198 68 580 Xenova/bge-large-en-v1.5 71 9 201 webgpu is 2.6-2.9x faster than cpu at every size; coreml is 3-8x slower because it falls back to CPU for unsupported ops, and coreml+fp16 fails to load on this onnxruntime build. The ranking is hardware-specific, which is why this is a caller choice rather than a new default. The README documents the measurements so `device` does not get cargo-culted.
mrrobertkent
force-pushed
the
feat/transformers-device-dtype
branch
from
August 11, 2026 20:43
08b70a6 to
9c7f27d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
❓ Type of change
📚 Description
Expose Transformers.js device and data type settings, including per-file maps, without changing default device selection. Unknown models now probe dimensions, and the bge-large-en-v1.5 preset resolves to published weights. Supersedes #18.