## Executive Summary

In this dynamic and demo-driven session, **Bruno Capuano** demonstrates how .NET developers can tap into the power of **Small Language Models (SLMs) and task-specialized local AI models**. While the industry often defaults to massive cloud-hosted LLMs, small local models running on consumer hardware (CPU, GPU, or NPU) deliver immense benefits: **zero per-token inference costs, zero network latency, complete data privacy, and predictable execution**.

Bruno showcases local AI execution across **Windows, macOS, and Linux** using two primary local platforms: **Foundry Local** and **Ollama**, bridged into .NET applications via modern C# and `Microsoft.Extensions.AI`.

Key highlights include:
1. **Local Speech-to-Text (STT) Streaming:** Real-time audio transcription using NVIDIA's **Nemotron Speech** model running on CPU via Foundry Local, processing audio chunks with low memory and CPU overhead.
2. **Live Microphone Ingestion:** Processing live microphone buffers using decoupled asynchronous background tasks to stream transcriptions word-by-word.
3. **Spoken Text Normalization (Prompt Cleaning):** Using specialized cleaner models like **S1-mini** (converted to quantized `int4` ONNX and custom Foundry Local models) to strip filler words ("um", "ah"), stuttering, and verbal reversals ("No, wait, make that Thursday at 3:30"), saving downstream LLM prompt tokens.
4. **Decision Models (Classification Without Generative Token Overhead):** Leveraging non-generative decision models like **Nimble** (10 GB GPU model) and **Tav** (<1 GB lightweight model) via Ollama. Instead of generating conversational text, decision models evaluate context against discrete choices, emitting exact probability distributions and confidence scores instantly.
5. **Real-Time Autonomous Agent Gaming:** Putting it all together by letting a local decision model autonomously pilot a .NET 2D retro space shooter game in real time.

---

## Local AI Pipeline Architecture

The complete local processing chain transforms noisy, multi-modal human input into deterministic programmatic actions without sending a single byte to the public cloud:

```mermaid
flowchart LR
    subgraph AudioInput ["Audio Capture"]
        Mic["Microphone Input"]
        WAV["WAV Audio File"]
    end

    subgraph STT ["Speech-to-Text Engine"]
        Nemotron["NVIDIA Nemotron Speech<br/>(Foundry Local / CPU)"]
        StreamChunk["Streaming Audio Chunks"]
    end

    subgraph Cleaning ["Prompt Normalization"]
        RawText["Raw Transcript<br/><i>'Um, send report Friday... wait, Thursday'</i>"]
        S1Mini["S1-Mini Cleaner Model<br/>(ONNX Runtime int4 / 400 MB)"]
        CleanText["Cleaned Prompt<br/><i>'Send report Thursday at 3:30 PM'</i>"]
    end

    subgraph Routing ["Decision & Classification"]
        OllamaEngine["Ollama Runtime"]
        DecModel{"Decision Model<br/>(Nimble 10GB / Tav <1GB)"}
        Scores["Confidence Scores<br/>(Billing: 99.7%, Support: 0.3%)"]
    end

    subgraph Actions ["Application Execution"]
        Dispatch["Workflow Dispatcher"]
        GameEngine["2D Space Shooter Loop<br/>(Go Up / Go Down / Shoot)"]
    end

    Mic --> StreamChunk
    WAV --> StreamChunk
    StreamChunk --> Nemotron --> RawText
    RawText --> S1Mini --> CleanText
    CleanText --> OllamaEngine --> DecModel --> Scores
    Scores --> Dispatch
    Scores --> GameEngine
```

---

## Key Technical Pillars & Live Demonstrations

### 1. Foundry Local & Local Model Catalogs

Foundry Local acts as an automated local model manager. It handles downloading weights from Hugging Face or registries, hardware device targeting (CPU, CUDA GPU, DirectML, NPU), model caching, and API hosting behind a clean CLI and SDK.

- **Available Model Classes:** Standard chat (Qwen, DeepSeek, Phi), multimodal (vision/audio), specialized speech-to-text, and embeddings.
- **Hardware Agnostic:** Automatically selects CPU or GPU paths, caching model layers locally in user directories.

![Session Introduction](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/01-session-intro.webp)
*Bruno Capuano kicks off 'Small Models, Big .NET Energy' at .NET Conf 2026.*

![Foundry Local Overview](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/02-foundry-local-overview.webp)
*Foundry Local documentation and local model installation options.*

![Foundry Local Model Catalog](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/03-foundry-local-catalog.webp)
*Inspecting supported local models across CPU, GPU, and NPU execution providers.*

---

### 2. Local Speech-to-Text Streaming (NVIDIA Nemotron)

Running speech-to-text locally requires zero cloud services. Using NVIDIA's **Nemotron Speech** loaded via Foundry Local:
- In ~10 lines of C#, developers initialize the `FoundryLocalManager`, resolve the cached model, open an audio session, and stream audio chunks.
- As audio buffers are streamed into the model, transcribed text streams back word-by-word with negligible CPU footprint.

```csharp
var manager = new FoundryLocalManager();
var model = await manager.GetOrDownloadModelAsync("nemotron-speech");
using var session = await model.CreateAudioSessionAsync();

await foreach (var chunk in audioStream.ReadChunksAsync(chunkSize))
{
    var textDelta = await session.TranscribeChunkAsync(chunk);
    Console.Write(textDelta);
}
```

![Nemotron Speech-to-Text Code](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/04-nemotron-speech-to-text-code.webp)
*C# implementation streaming audio buffers to NVIDIA Nemotron Speech.*

![Streaming Speech Transcript](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/05-streaming-speech-transcript.webp)
*Console output displaying real-time word-by-word transcription from WAV audio.*

---

### 3. Live Microphone Streaming

Extending the STT pipeline to capture live ambient speech:
- Uses an asynchronous producer/consumer architecture: one task records microphone audio buffers into an in-memory queue, while a consumer task feeds audio chunks directly into the local speech model.
- Runs smoothly in the background while keeping machine temperature, fan noise, and CPU utilization relaxed.

![Live Microphone Transcription](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/06-live-microphone-transcription.webp)
*Live microphone speech transcribed directly in terminal in real time.*

---

### 4. Spoken Text Normalization (Prompt Cleaning)

Spoken speech is full of hesitations, filler sounds ("um", "uh"), verbal corrections ("Please send it Friday... no wait, make that Thursday at 3:30"), and rambling sentence fragments. Sending raw spoken text to a cloud LLM wastes context tokens and degrades model reasoning.

#### The S1-Mini Normalizer Model
Bruno demonstrates **S1-mini** (from SuperWhisper):
- **Custom ONNX Quantization:** Converted the open-weights model to `int4` ONNX (~400 MB model weight + 11 MB tokenizer).
- **C# Normalizer Library:** Created a lightweight .NET library wrapping ONNX Runtime (`Microsoft.ML.OnnxRuntime`) exposing `NormalizeAsync(rawText, options)`.
- **Foundry Local Custom Integration:** Converted the model to run directly inside Foundry Local, allowing speech transcription and prompt cleaning in a unified local pipeline.

| Input (Raw Audio Transcription) | Output (Normalized Prompt) |
|---|---|
| *"um I need to send the report by Friday. No, wait. Make that Thursday at 3:30 p.m. Please update the project notes before the meeting."* | *"I need to send the report by Thursday at 3:30 PM. Please update the project notes before the meeting."* |

![Text Normalization Concept](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/07-normalization-concept.webp)
*The normalization pipeline: stripping conversational noise to optimize LLM prompts.*

![S1-Mini ONNX Model Artifacts](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/08-s1-mini-onnx-model.webp)
*Quantized int4 ONNX model files: 400 MB model weight and 11 MB tokenizer JSON.*

![S1-Mini Cleaner Execution](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/09-s1-mini-cleaner-run.webp)
*Console comparison showing raw transcribed text transformed into concise prompt instructions.*

![Foundry Local Custom Model](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/10-foundry-local-custom-model.webp)
*Running speech-to-text and text cleanup end-to-end within Foundry Local.*

---

### 5. Decision Models: Classification Without Token Generation

Most developers use generative LLMs for classification tasks (e.g. "Classify this email as Billing or Technical Support"). However, generative LLMs are computationally wasteful: they generate tokens sequentially, consume GPU VRAM, and can hallucinate invalid choices.

**Decision Models** evaluate input against predefined choices and criteria, outputting pure probability scores:
- **Zero Generative Token Overhead:** Extreme inference speed (often <5 ms).
- **Exact Probabilities:** Returns a numerical confidence score for each option (e.g., Billing: 99.7%, Support: 0.3%).
- **Models Used:**
  - **Nimble:** High-precision 10 GB decision model running in GPU VRAM via Ollama.
  - **Tav:** Ultralight decision model under 1 GB footprint suitable for edge devices.

```csharp
var decisionClient = new OllamaDecisionClient("http://localhost:11434", "nimble:latest");
var result = await decisionClient.DecideAsync(new DecisionRequest
{
    Instructions = "Which team should handle this request?",
    Choices = new[]
    {
        new Choice { Id = "billing", Criteria = "Invoices, charges, payment errors" },
        new Choice { Id = "support", Criteria = "App crashes, bugs, broken pages" }
    },
    Input = "Please correct my invoice because it was charged twice."
});

// Output: result.Choice == "billing" (Confidence: 99.7%)
```

![Decision Models Concept](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/11-decision-models-concept.webp)
*How decision models evaluate choices and criteria to emit probability distributions.*

![Ollama Decision Models Structure](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/12-ollama-decision-models.webp)
*Inspecting Ollama decision model structure: choices, instructions, and states.*

![Ollama Real-time Logs and Routing](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/13-ollama-realtime-logs.webp)
*Live execution routing customer support tickets with 99% confidence.*

![Ollama GPU Memory Management](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/14-ollama-gpu-memory-tav.webp)
*Ollama VRAM management: running 10 GB Nimble vs <1 GB Tav models with automatic eviction.*

---

### 6. Autonomous Real-Time Gaming with Local Decision Models

To prove the sub-millisecond responsiveness of local decision models, Bruno connects a local model to an interactive 2D arcade space shooter built in .NET 11:
- The game loop passes the player ship position, incoming asteroid coordinates, and bug enemy positions into the local model.
- The decision model evaluates choices (`Go Up`, `Go Down`, `Hold Position`) in real time, steering the spaceship to dodge enemies and clear levels autonomously.
- Optional voice override enables the player to give spoken tactical instructions that are transcribed and normalized on the fly.

![Autonomous Arcade Space Game](/dotnetconf2026/archive/33-small-models-big-dotnet-energy/screenshots/15-space-game-autonomous.webp)
*.NET 2D retro arcade game steered autonomously in real time by a local decision model.*

---

## Conclusion & Actionable Advice

Bruno concludes with practical principles for modern .NET AI development:
1. **Right-size the Model:** Don't default to a 400B parameter frontier cloud model when a 400MB specialized local model can perform speech-to-text, prompt cleaning, or classification faster, cheaper, and privately.
2. **Embrace Foundry Local & Ollama:** These tools abstract away driver installation, quantization, and CUDA bindings, allowing .NET developers to consume models with clean C# APIs.
3. **Save Cloud Tokens via Local Pre-Processing:** Use local speech models and normalizers (like S1-mini) to clean spoken audio into dense prompts before invoking paid cloud reasoning models.
4. **Use Decision Models for Deterministic Routing:** Replace fragile prompt-engineered JSON output parsing with high-speed decision models that output pure probability distributions.
