Skip to main content

model.generate()

Generate text completions from image/video inputs and text prompts.

Parameters

dict
required
Model inputs dictionary containing tokenized text and preprocessed images/videos.Typically obtained from processor.apply_chat_template() and moved to model device:
int
default:"128"
Maximum number of new tokens to generate.
float
default:"0.7"
Sampling temperature. Higher values increase randomness.
  • 0.1-0.5: More focused, deterministic outputs
  • 0.7: Balanced creativity (default for Instruct models)
  • 0.6: Recommended for Thinking models
  • 1.0+: More creative, diverse outputs
float
default:"0.8"
Nucleus sampling threshold. Only tokens with cumulative probability up to top_p are considered.
  • Instruct models: 0.8 (default)
  • Thinking models: 0.95 (recommended)
int
default:"20"
Top-k sampling. Only the top k most likely tokens are considered.
  • 20: Recommended value
  • -1: Disabled (consider all tokens)
float
default:"1.0"
Penalty for repeating tokens. Values > 1.0 discourage repetition.
  • 1.0: No penalty (default)
  • 1.1-1.5: Light to moderate penalty
float
default:"1.5"
Penalty for token presence regardless of frequency.
  • Instruct models: 1.5 (recommended)
  • Thinking models: 0.0 (recommended)
bool
default:"True"
Whether to use sampling. If False, uses greedy decoding.
int
Random seed for reproducible generation.
  • Instruct models: 3407 (official eval)
  • Thinking models: 1234 (official eval)

Returns

torch.Tensor
Tensor of token IDs including both input and generated tokens.Shape: (batch_size, total_sequence_length)To extract only the newly generated tokens:

Decoding Output

Convert generated token IDs to text using the processor:

Complete Example

Instruct Models

Thinking Models

Notes

For batch generation, always set processor.tokenizer.padding_side = 'left' and include padding=True in apply_chat_template().
The recommended hyperparameters above are used for official benchmark evaluations and provide optimal results for most use cases.