fix: clamp few-shot sample size to available data length

This commit is contained in:
suraj-self 2026-02-21 12:51:07 +05:30
parent c7ba252142
commit b12d1961de

View File

@ -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