From b12d1961de0a80a03484f430f7705fedb027b8de Mon Sep 17 00:00:00 2001 From: suraj-self Date: Sat, 21 Feb 2026 12:51:07 +0530 Subject: [PATCH] fix: clamp few-shot sample size to available data length --- nanochat/core_eval.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nanochat/core_eval.py b/nanochat/core_eval.py index f3c9a9f..cb71b41 100644 --- a/nanochat/core_eval.py +++ b/nanochat/core_eval.py @@ -177,7 +177,7 @@ def evaluate_example(idx, model, tokenizer, data, device, task_meta): if num_fewshot > 0: rng = random.Random(1234 + idx) available_indices = [i for i in range(len(data)) if i != idx] - fewshot_indices = rng.sample(available_indices, num_fewshot) + fewshot_indices = rng.sample(available_indices, min(num_fewshot, len(available_indices))) fewshot_examples = [data[i] for i in fewshot_indices] # Render prompts and batch sequences based on task type