Table of Contents

👉 Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/local-inference/sampling-controls/sampler_comparison_lab

Sampler Comparison Lab for C# .NET Applications


🎯 Purpose of the Demo

An interactive console app that runs the same prompt under four standard sampling strategies side-by-side (GreedyDecoding, low-temperature RandomSampling, high-temperature RandomSampling, Mirostat2Sampling), with a custom-parameters mode for quick experimentation.

All inference runs on-device.


👥 Industry Target Audience

  • App developers picking a sampler for a new task (extraction vs chat vs long-form writing).
  • Prompt engineers exploring temperature/top-p trade-offs.
  • Quality teams validating that determinism settings actually produce identical output.
  • Educators demonstrating sampling concepts on a real model.

🚀 Problem Solved

Wrong sampler for the task is a silent quality killer. Greedy is great for extraction; high-temperature random looks creative but breaks JSON. Mirostat v2 keeps a target entropy across long output instead of drifting. The lab gives you side-by-side outputs from the same model on the same prompt so the right pick is obvious.


💻 Application Overview

Interactive menu (no command-line arguments) with six modes:

Mode What it does
Compare Run one prompt under all 4 standard samplers; print outputs + token counts + tok/s.
Greedy Deterministic decoding only.
LowTemp RandomSampling with Temp=0.3, TopP=0.85, MinP=0.05, TopK=40.
HighTemp RandomSampling with Temp=0.95, TopP=0.98, MinP=0.02, TopK=100.
Mirostat Mirostat v2 with TargetEntropy=5.0, LearningRate=0.1.
Custom RandomSampling with user-typed Temp/TopP/MinP/TopK.
Quit Exit.

Each pass applies the same RepetitionPenalty so the only variable is the sampler.

✨ Key Features

  • GreedyDecoding for deterministic output.
  • RandomSampling { Temperature, TopP, MinP, TopK }.
  • Mirostat2Sampling { Temperature, TargetEntropy, LearningRate }.
  • RepetitionPenalty: TokenCount, RepeatPenalty, FrequencyPenalty, PresencePenalty.
  • Per-pass metrics: GeneratedTokens.Count, TokenGenerationRate, TerminationReason.

🧠 Model

  • qwen3.5:4b (current Qwen 3.5 dense).

🛠️ Getting Started

📋 Prerequisites

  • .NET 8.0 or later

▶️ Running the Application

git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/local-inference/sampling-controls/sampler_comparison_lab
dotnet run

Pick a mode from the menu.

Share