Skip to content

Conversation

@ezylopx5
Copy link
Contributor

@ezylopx5 ezylopx5 commented Jan 6, 2026

Summary

Fixes #3452 - Performance decreasing when passing from 0 to few shots

Root Cause

In build_qa_turn(), the condition if a and not gen_prefix incorrectly treated a=0 (a valid answer index) as falsy, causing the target_delimiter to be skipped for few-shot examples where the answer was the first choice.

The Bug

When a few-shot example has answer=0:

  • Before: Answer:A (no space - wrong)
  • After: Answer: A (with space - correct)

This inconsistency confused models because few-shot examples showed a different format than what the model was asked to predict.

The Fix

Changed truthiness check to explicit None/empty check:

# Before (buggy)
if a and not gen_prefix

# After (fixed) 
has_answer = a is not None and a != ""
if has_answer and not gen_prefix 

Testing

Added 2 regression tests for answer index 0 and non-zero cases
All 48 fewshot context tests pass

Fixes EleutherAI#3452

When answer is an integer index into choices, a=0 should be treated as
a valid answer, not as falsy. Previously, the condition 'if a and not
gen_prefix' incorrectly treated a=0 as falsy, causing the target_delimiter
to be skipped for few-shot examples where the answer was the first choice.

This caused inconsistent formatting:
- Few-shot examples: 'Answer:A' (no space)
- Model predictions: ' A' (with leading space from target_delimiter)

The fix explicitly checks 'a is not None and a != ""' instead of
relying on truthiness.

Added regression tests for answer index 0 and non-zero cases.
@ezylopx5 ezylopx5 requested a review from baberabb as a code owner January 6, 2026 20:53
@CLAassistant
Copy link

CLAassistant commented Jan 6, 2026

CLA assistant check
All committers have signed the CLA.

@baberabb
Copy link
Contributor

baberabb commented Jan 7, 2026

Great catch! This was a sneaky one. Thanks for the fix!

@baberabb baberabb merged commit 05b5abc into EleutherAI:main Jan 7, 2026
6 checks passed
@ezylopx5 ezylopx5 deleted the fix/fewshot-answer-index-zero branch January 7, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance decreasing when passing from 0 to few shots?

3 participants