Transformers.js documentation
generation/parameters
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).
generation/parameters
Type Definitions
GenerationFunctionParametersBase
Properties
inputs(Tensor) optional β defaults tonullβ The sequence used as a prompt for generation or as model inputs to the encoder. Ifnull, the method initializes it withbos_token_idand a batch size of 1. For decoder-only modelsinputsshould be in the format ofinput_ids. For encoder-decoder models inputs can represent any ofinput_ids,input_values,input_features, orpixel_values.generation_config(GenerationConfig) optional β defaults tonullβ The generation configuration to use as the base parameters for the generation call.**kwargspassed to generate that match attributes ofgeneration_configwill override them. Ifgeneration_configis not provided, the default is used, with the following loading priority:- (1) from the
generation_config.jsonmodel file, if it exists; - (2) from the model configuration. Unspecified parameters inherit the default values documented by
GenerationConfig.
- (1) from the
logits_processor(LogitsProcessorList) optional β defaults tonullβ Custom logits processors that complement the default logits processors built from arguments and the generation config. If a logits processor duplicates one already created from the arguments or generation config, an error is thrown. This feature is intended for advanced users.stopping_criteria(StoppingCriteria|StoppingCriteria[] |StoppingCriteriaList) optional β defaults tonullβ Custom stopping criteria that complement the default stopping criteria built from arguments and the generation config. If a stopping criterion duplicates one already created from the arguments or generation config, an error is thrown. This feature is intended for advanced users.streamer(BaseStreamer) optional β defaults tonullβ Streamer object used to stream the generated sequences. Generated tokens are passed throughstreamer.put(token_ids)and the streamer is responsible for any further processing.decoder_input_ids(number[]|Tensor) optional β defaults tonullβ If the model is an encoder-decoder model, this argument is used to pass thedecoder_input_ids.past_key_values(DynamicCache|null) optional β defaults tonullβ A cache object that stores previously computed key/value states. When provided, the model will use these cached states to avoid recomputing them, significantly speeding up sequential generation.
GenerationFunctionParameters
Type: GenerationFunctionParametersBase & Partial<GenerationConfig> & { [key: string]: unknown }