SRM Day 3 Hub | Prev Session | Next Session

LLM Scaling (MoE, Reasoning, Context) & Evaluation Metrics

Smarter Compute via Mixture of Experts, Chain-of-Thought Reasoning, Million-Token Context Windows & Evaluation Benchmarking

MoE Router Gating Reasoning & CoT Perplexity & BLEU

Beyond Raw Scale: Scaling Smarter, Not Just Larger

Simply increasing parameter count in dense models raises exponential compute & power costs. Modern LLMs scale smarter through 3 key architectural pillars:

1. Mixture of Experts (MoE)

Routes each token dynamically to a fraction of specialized sub-networks ($Top-k$ active compute).

DeepSeek V3, Mistral 8x7B

2. Reasoning Models

Allocates adaptive thinking time via Chain-of-Thought (CoT) & self-verification before outputting final answers.

DeepSeek-R1, OpenAI o3

3. Million-Token Context

Processes entire books, codebases, or hours of audio using RoPE extrapolation & FlashAttention.

Gemini 1.5, LLaMA 3.3

Mixture of Experts (MoE) Architecture

1. Specialized Experts

Replaces dense Feed-Forward Networks (FFN) with multiple parallel expert sub-networks ($E_1, E_2, \dots, E_N$).

Experts specialize in distinct sub-domains (e.g. math, code, logic, multi-lingual syntax).

2. The Router Gating Traffic Controller

Computes softmax affinity scores $G(x)$ for each token and routes to top $k$ experts (e.g. $k=2$):

$$y = \sum_{i=1}^{k} G(x)_i \cdot E_i(x)$$

Compute Magic: Total parameter capacity can be 236B+, but per-token inference compute runs at the cost of only 21B active parameters!

MoE Load Balancing & Gating Strategies

The Routing Collapse Danger

Naive routers tend to over-route tokens to a few popular "catch-all" experts, leaving other experts untrained and starved.

Expert Starvation Bottleneck

Modern Balancing Solutions

  • Auxiliary Loss: Penalizes uneven token distribution across experts during training.
  • Auxiliary-Loss-Free Gating: DeepSeek V3 dynamically adjusts expert bias terms without polluting loss gradients!

Reasoning Models & Thinking Time (DeepSeek-R1)

Standard LLMs predict answers instantly. Reasoning models generate internal Chain-of-Thought (CoT) tokens before returning the final answer.

Thinking Mechanism

  • Chain-of-Thought: Decomposes complex logic into step-by-step sub-problems.
  • Self-Verification: Checks initial assumptions & backtracks on mistakes.
  • Adaptive Thinking Tokens: Spends more compute on harder math/code problems.

Pure RL Training Emergence

DeepSeek-R1 proved that reasoning behavior can emerge naturally through pure Reinforcement Learning (RL) rewards for accuracy, without requiring human-labeled SFT traces!

Scaling Context Windows to Millions of Tokens

RoPE & ALiBi Extrapolation

Modifies positional encoding frequencies to generalize to context lengths $10\times$ longer than pretraining.

Sliding Window Attention

Maintains overlapping attention windows, allowing distant token information to flow without quadratic $O(N^2)$ memory cost.

FlashAttention (IO Aware)

Reorders GPU SRAM memory access to compute exact self-attention $O(N)$ memory overhead without materializing large $N \times N$ matrices!

Evaluating LLMs: Intrinsic vs. Extrinsic Metrics

Intrinsic Evaluation

Measures how well the model predicts language on its core pretraining task.

  • Perplexity (PP): Language model surprise meter.
  • BLEU & ROUGE: n-gram precision & recall.
  • FID: Generative feature distribution distance.

Extrinsic Evaluation

Measures real-world performance on specialized downstream applications.

  • Exact Match (EM) & F1: Question Answering accuracy.
  • Word Error Rate (WER): Speech transcription.
  • FactScore: Verified factual claim scoring.

Intrinsic Metric 1: Perplexity (PP)

Perplexity measures how surprised a language model is by a test sequence of words. Lower perplexity = higher confidence & better model!

$$\text{Perplexity}(W) = \exp\left(-\frac{1}{N} \sum_{i=1}^{N} \log P(w_i \mid w_1, \dots, w_{i-1})\right)$$

High Perplexity (PP > 100)

Model assigns low probability to actual text words. High uncertainty and frequent errors in predictions.

Low Perplexity (PP < 15)

Model is highly confident in predicting true word distributions. Indicates strong language comprehension.

Intrinsic Metric 2: BLEU & ROUGE

BLEU (Bilingual Evaluation Understudy)

Calculates modified n-gram precision between generated candidate and human reference text with a Brevity Penalty (BP):

$$\text{BLEU} = \text{BP} \cdot \exp\left(\sum_{n=1}^{4} w_n \log p_n\right)$$

Prevents short translations from cheating precision!

ROUGE (Recall-Oriented Understudy)

Measures n-gram recall (how much of reference text is captured by candidate output).

$$\text{ROUGE-L} = \text{LCS}(Reference, Candidate) / |Reference|$$

Standard for text summarization tasks!

Intrinsic Metric 3: Fréchet Inception Distance (FID)

Used to evaluate generative synthesis models (images/audio/text) by measuring feature distribution distance:

$$\text{FID} = \|\mu_r - \mu_g\|^2 + \text{Tr}\left(\Sigma_r + \Sigma_g - 2(\Sigma_r \Sigma_g)^{1/2}\right)$$

Feature Extraction

Extracts deep hidden features ($\mu, \Sigma$) of real vs generated samples using pretrained classifiers.

Lower FID = Higher Realism

Lower distance indicates generated sample distribution is practically indistinguishable from real data!

Extrinsic Evaluation Metrics Breakdown

Application Domain Standard Metric Measurement Objective
Question Answering Exact Match (EM) & F1 Score String identity & word overlap against true answer
Speech-to-Text Word Error Rate (WER) Percentage of substituted, inserted & deleted words
Factual Accuracy FactScore & QA-Verification Percentage of atomic facts verified against reliable knowledge sources
Embedding Bias WEAT (Word Embedding Association) Quantifies gender, racial & societal bias in vector space

Key Challenges in LLM Evaluation

1. Data Contamination

Benchmark test sets leaked into web-scraped pretraining datasets, artificially inflating scores.

2. Benchmark Saturation

LLMs quickly hit 95%+ on benchmarks (GLUE, MMLU), forcing creation of harder reasoning benchmarks (GSM8K, MATH, SWE-bench).

3. LLM-as-a-Judge Bias

Using GPT-4 to grade other LLMs introduces self-preference bias, verbosity bias, and positional bias.

Live Code: Perplexity Math & Top-2 MoE Gating

import numpy as np

# 1. Compute Perplexity for Target Token Probabilities
probabilities = np.array([0.85, 0.92, 0.78, 0.88, 0.95])
log_probs = np.log(probabilities)
perplexity = np.exp(-np.mean(log_probs))

# 2. Simulate MoE Top-2 Router Gating (8 Experts)
np.random.seed(42)
token_embedding = np.random.randn(1, 16)
router_weights = np.random.randn(16, 8)

# Compute Router Affinity Scores & Top-2 Selection
gating_logits = np.dot(token_embedding, router_weights)[0]
top2_indices = np.argsort(gating_logits)[-2:][::-1]
top2_scores = gating_logits[top2_indices]

print("Model Perplexity (Surprise Meter):", round(perplexity, 3))
print("MoE Router Gating Logits:", np.round(gating_logits, 2))
print("Selected Top-2 Active Experts:", top2_indices)
print("Active Expert Affinity Scores:", np.round(top2_scores, 2))

Code Explanation

1. Calculates Perplexity $\text{PP} = \exp(-\frac{1}{N}\sum \log P)$ for predicted tokens.

2. Projects token embedding through Router Gating Matrix ($16 \to 8$ experts).

3. Selects Top-2 Experts dynamically, bypassing 6 inactive experts to save inference compute!

LLM Scaling & Evaluation Summary Matrix

Technique / Metric Category Core Mechanism Primary Benefit
Mixture of Experts (MoE) Scaling Architecture Router gating to Top-$k$ active experts 10x parameter scale at 1x active inference compute
Reasoning (CoT) Thinking Paradigm Adaptive step-by-step thinking tokens + RL Unlocks complex multi-step math, code & logic accuracy
Perplexity (PP) Intrinsic Evaluation Exponential cross-entropy loss $\exp(\mathcal{L}_{CE})$ Measures language model prediction confidence
BLEU / ROUGE Intrinsic Evaluation n-gram precision/recall with brevity penalty Standard translation & summarization quality scoring

The Complete 10-Session Generative AI Journey

Foundations (Sessions 1 - 5)

  • Session 1: Layers of Intelligence (AI, ML, DL, GenAI)
  • Session 2: Deep Learning & Backpropagation Math
  • Session 3: NLP Foundations & Tokenization
  • Session 4: Word Embeddings & Vector Math
  • Session 5: Sequential Memory (RNN vs LSTM Gating)

Modern GenAI & Scale (Sessions 6 - 10)

  • Session 6: The Transformer Evolution & Self-Attention
  • Session 7: Emergence of GenAI, VAEs, GANs, BERT & GPT
  • Session 8: Foundation Models & Pretraining Paradigms
  • Session 9: PEFT LoRA, QLoRA & RLHF Alignment
  • Session 10: MoE, Reasoning, Context & LLM Evaluation
Session 10 Summary

Scaling Smarter & Measuring Success

1. Conditional Compute

MoE routing unlocks trillion-parameter expressiveness at low active inference cost.

2. Reasoning Engine

Chain-of-Thought thinking tokens allow models to solve complex multi-step logic.

3. Holistic Evaluation

Combining Perplexity, BLEU, and Task F1 ensures accurate, unbiased LLMs.

Return to SRM PDP Talk Hub
SRMIST PDP Day 3 Conclusion

Thank You!

Evolution of Generative AI Foundation Models on Cloud Platform

Dr. B. Tamil Arasan · Principal Research Engineer, Saama Technologies
Department of Networking and Communications, SRMIST Kattankulathur

Explore All 10 Sessions Conference Talks
1 / 17