Skip to main content
This example demonstrates basic text generation using ONNX Runtime GenAI, including batch processing and streaming output.

Overview

The generation example shows how to:
  • Load and configure models
  • Encode input prompts
  • Generate tokens in a loop
  • Decode and display output
  • Measure generation performance

Complete Example

Key Concepts

Model Loading

Load the model with configuration:

Batch Encoding

Encode multiple prompts at once:

Generation Loop

Generate tokens until completion:

Decoding Sequences

Retrieve and decode generated sequences:

Usage Examples

Performance Monitoring

The example automatically tracks and reports:
  • Total tokens generated
  • Generation time
  • Tokens per second (throughput)

Command-Line Arguments

Next Steps