Transformers.js documentation
utils/hub
Get started
Tutorials
Building a Vanilla JS ApplicationBuilding a React ApplicationBuilding a Next.js ApplicationBuilding a Browser ExtensionBuilding an Electron ApplicationServer-side Inference in Node.jsBuilding a Next.js AI Chatbot with Vercel AI SDK
Developer Guides
Running models on WebGPUUsing quantized models (dtypes)Accessing Private/Gated ModelsServer-side Audio Processing
Integrations
API Reference
You are viewing main version, which requires installation from source. If you'd like
regular npm install, checkout the latest stable version (v3.8.1).
utils/hub
Utility functions to interact with the Hugging Face Hub (https://huggingface.co/models)
Type Definitions
ExternalData
Specifies whether to load the model using the external data format.
false: Do not use external data formattrue: Use external data format with 1 chunknumber: Use external data format with the specified number of chunks
Type: boolean | number
PretrainedOptions
Options for loading a pretrained model.
Properties
progress_callback(ProgressCallback) optional β defaults tonullβ If specified, this function is called during model construction with progress updates.config(PretrainedConfig) optional β defaults tonullβ Configuration to use for the model instead of an automatically loaded configuration. Configuration can be automatically loaded when:- The model is provided by the library and loaded with the model ID string of a pretrained model.
- The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir(string) optional β defaults tonullβ Path to a directory where downloaded model files should be cached if the standard cache should not be used.local_files_only(boolean) optional β defaults tofalseβ Whether to only look at local files (e.g., not try downloading the model).revision(string) optional β defaults to'main'β The model revision to use. This can be a branch name, tag name, or commit ID. Because the Hub uses Git-based storage,revisioncan be any identifier accepted by Git. Ignored for local requests.
ModelSpecificPretrainedOptions
Options for loading a pretrained model.
Properties
subfolder(string) optional β defaults to'onnx'β In case the relevant files are located inside a subfolder of the model repo on huggingface.co, you can specify the folder name here.model_file_name(string) optional β defaults tonullβ Override the base ONNX model file name, excluding dtype and.onnxsuffixes. This is most useful for single-session models.device(DeviceType|Record<string,DeviceType>) optional β defaults tonullβ The device to run the model on. If not specified, the device will be chosen from the environment settings.dtype(DataType|Record<string,DataType>) optional β defaults tonullβ The data type to use for the model. If not specified, the data type will be chosen from the environment settings.use_external_data_format(ExternalData|Record<string,ExternalData>) optional β defaults tonullβ Whether to load external data files.nulluses the model configuration;falsedisables external data;trueuses one chunk; a number selects the chunk count.session_options(InferenceSession.SessionOptions) optional β defaults to{}β User-specified ONNX Runtime session options. Suitable defaults are filled in when omitted.
PretrainedModelOptions
Options for loading a pretrained model.
Type: PretrainedOptions & ModelSpecificPretrainedOptions