Skip to content

Fix issue 3355 assertion error - #3356

Merged
baberabb merged 8 commits into
EleutherAI:mainfrom
marksverdhei:fix-issue-3355-assertion-error
Nov 9, 2025
Merged

Fix issue 3355 assertion error#3356
baberabb merged 8 commits into
EleutherAI:mainfrom
marksverdhei:fix-issue-3355-assertion-error

Conversation

@marksverdhei

@marksverdhei marksverdhei commented Oct 20, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR fixes issue #3355, which caused an AssertionError when running evaluations with OpenAI-compatible endpoints when API responses have "content": null. This happens with vllm if using a reasoning model (GPT-OSS-20b) and running out of tokens before the non-think response is generated. It is solved by treating the response as an empty string while logging a warning.

Reproducing the error

# start a local vllm instance of gpt-oss-20b
vllm serve openai/gpt-oss-20b --port 7000
# Example run, not a real eval. Breaks before PR, works after
lm_eval --model local-chat-completions --tasks nortruthfulqa_gen_nob_p0 --model_args base_url=http://localhost:7000/v1/chat/completions,num_concurrent=1,max_retries=3,tokenized_requests=False,model="openai/gpt-oss-20b" --apply_chat_template --limit 0.001

Details

The issue occurred in lm_eval/models/utils.py:541 in the Collator.get_original() method:

assert all(cov)  # AssertionError here

The problem: When parse_generations() returned None values (from API responses with "content": null), the original code would skip these values:

# OLD CODE - BUGGY
if generated_text is not None:
    res.append(generated_text)  # Only appends non-None values

This caused a mismatch:

  • The Collator tracked that it had N requests to process (_size = N)
  • But the result list res only had M items (where M < N, skipping the None values)
  • When get_original() tried to restore the original order, not all positions were filled
  • The assertion assert all(cov) failed because some positions remained uncovered

Based on real API logs from the issue, this happens when vllm OpenAI-compatible endpoint return:

{
  "choices": [{
    "index": 0,
    "message": {
      "content": null,                    // ← NULL content!
      "reasoning_content": "The user..."  // ← Actual text here
    }
  }]
}

Note that caching still only happens for successful results (None values not cached)

Resolves #3355

*this PR was created with the assistance of AI tools

…rse_logprobs

Fixes the AssertionError in Collator.get_original() that occurred when
API responses contain None values. The issue was that the code skipped
None values when building the result list, causing a mismatch between
the expected number of items and actual items, triggering the assertion.

Changes:
- generate_until: Always append results, converting None to empty string
- _loglikelihood_tokens: Always append results, converting None to (-inf, False)
- Applied fix to both sequential and concurrent code paths

The fix ensures:
1. Result lists always have the correct number of items for reordering
2. None values are converted to sensible defaults instead of being skipped
3. Progress bars update correctly for all requests
4. Only successful results are cached

Resolves EleutherAI#3355
Only fix generate_until, which has confirmed evidence of the bug from
issue EleutherAI#3355. The loglikelihood methods have no evidence of this issue:
- No failures reported in issue EleutherAI#3355
- Different code structure in parse_logprobs (no gap creation)
- Stack traces only show generate_until failures

Keep the fix minimal and evidence-based.
Log concise warnings when parse_generations returns None to help
users diagnose issues with API responses that have 'content': null.

Warning message suggests checking:
- reasoning_content field (for reasoning models)
- generation limits (max_tokens, length)

Includes first 50 chars of context in sequential path for debugging.
@marksverdhei

Copy link
Copy Markdown
Contributor Author

The PR has been out for two weeks now without any response, I hope this can be resolved soon 🙏

@marksverdhei

Copy link
Copy Markdown
Contributor Author

@baberabb please let me know if there's anything I can do to make the process / reviewing easier or faster.

@baberabb

baberabb commented Nov 9, 2025

Copy link
Copy Markdown
Collaborator

@baberabb please let me know if there's anything I can do to make the process / reviewing easier or faster.

Sorry for the delay. LGTM!

@baberabb
baberabb merged commit a270a98 into EleutherAI:main Nov 9, 2025
6 checks passed
Ismail-Hossain-1 pushed a commit to Ismail-Hossain-1/lm-evaluation-harness that referenced this pull request Dec 9, 2025
* update tests

* Add test to reproduce issue EleutherAI#3355 AssertionError

* update tests

* Fix issue EleutherAI#3355: Handle None values in parse_generations/parse_logprobs

Fixes the AssertionError in Collator.get_original() that occurred when
API responses contain None values. The issue was that the code skipped
None values when building the result list, causing a mismatch between
the expected number of items and actual items, triggering the assertion.

Changes:
- generate_until: Always append results, converting None to empty string
- _loglikelihood_tokens: Always append results, converting None to (-inf, False)
- Applied fix to both sequential and concurrent code paths

The fix ensures:
1. Result lists always have the correct number of items for reordering
2. None values are converted to sensible defaults instead of being skipped
3. Progress bars update correctly for all requests
4. Only successful results are cached

Resolves EleutherAI#3355

* remove irrelevant test

* Remove speculative loglikelihood fixes

Only fix generate_until, which has confirmed evidence of the bug from
issue EleutherAI#3355. The loglikelihood methods have no evidence of this issue:
- No failures reported in issue EleutherAI#3355
- Different code structure in parse_logprobs (no gap creation)
- Stack traces only show generate_until failures

Keep the fix minimal and evidence-based.

* Add warning logs when API returns null content

Log concise warnings when parse_generations returns None to help
users diagnose issues with API responses that have 'content': null.

Warning message suggests checking:
- reasoning_content field (for reasoning models)
- generation limits (max_tokens, length)

Includes first 50 chars of context in sequential path for debugging.

* remove context log
JessicaOjo pushed a commit to JessicaOjo/lm-evaluation-harness that referenced this pull request Dec 10, 2025
* update tests

* Add test to reproduce issue EleutherAI#3355 AssertionError

* update tests

* Fix issue EleutherAI#3355: Handle None values in parse_generations/parse_logprobs

Fixes the AssertionError in Collator.get_original() that occurred when
API responses contain None values. The issue was that the code skipped
None values when building the result list, causing a mismatch between
the expected number of items and actual items, triggering the assertion.

Changes:
- generate_until: Always append results, converting None to empty string
- _loglikelihood_tokens: Always append results, converting None to (-inf, False)
- Applied fix to both sequential and concurrent code paths

The fix ensures:
1. Result lists always have the correct number of items for reordering
2. None values are converted to sensible defaults instead of being skipped
3. Progress bars update correctly for all requests
4. Only successful results are cached

Resolves EleutherAI#3355

* remove irrelevant test

* Remove speculative loglikelihood fixes

Only fix generate_until, which has confirmed evidence of the bug from
issue EleutherAI#3355. The loglikelihood methods have no evidence of this issue:
- No failures reported in issue EleutherAI#3355
- Different code structure in parse_logprobs (no gap creation)
- Stack traces only show generate_until failures

Keep the fix minimal and evidence-based.

* Add warning logs when API returns null content

Log concise warnings when parse_generations returns None to help
users diagnose issues with API responses that have 'content': null.

Warning message suggests checking:
- reasoning_content field (for reasoning models)
- generation limits (max_tokens, length)

Includes first 50 chars of context in sequential path for debugging.

* remove context log
JessicaOjo pushed a commit to JessicaOjo/lm-evaluation-harness that referenced this pull request Dec 10, 2025
* update tests

* Add test to reproduce issue EleutherAI#3355 AssertionError

* update tests

* Fix issue EleutherAI#3355: Handle None values in parse_generations/parse_logprobs

Fixes the AssertionError in Collator.get_original() that occurred when
API responses contain None values. The issue was that the code skipped
None values when building the result list, causing a mismatch between
the expected number of items and actual items, triggering the assertion.

Changes:
- generate_until: Always append results, converting None to empty string
- _loglikelihood_tokens: Always append results, converting None to (-inf, False)
- Applied fix to both sequential and concurrent code paths

The fix ensures:
1. Result lists always have the correct number of items for reordering
2. None values are converted to sensible defaults instead of being skipped
3. Progress bars update correctly for all requests
4. Only successful results are cached

Resolves EleutherAI#3355

* remove irrelevant test

* Remove speculative loglikelihood fixes

Only fix generate_until, which has confirmed evidence of the bug from
issue EleutherAI#3355. The loglikelihood methods have no evidence of this issue:
- No failures reported in issue EleutherAI#3355
- Different code structure in parse_logprobs (no gap creation)
- Stack traces only show generate_until failures

Keep the fix minimal and evidence-based.

* Add warning logs when API returns null content

Log concise warnings when parse_generations returns None to help
users diagnose issues with API responses that have 'content': null.

Warning message suggests checking:
- reasoning_content field (for reasoning models)
- generation limits (max_tokens, length)

Includes first 50 chars of context in sequential path for debugging.

* remove context log
alexliap pushed a commit to alexliap/lm-evaluation-harness that referenced this pull request Jul 12, 2026
* update tests

* Add test to reproduce issue EleutherAI#3355 AssertionError

* update tests

* Fix issue EleutherAI#3355: Handle None values in parse_generations/parse_logprobs

Fixes the AssertionError in Collator.get_original() that occurred when
API responses contain None values. The issue was that the code skipped
None values when building the result list, causing a mismatch between
the expected number of items and actual items, triggering the assertion.

Changes:
- generate_until: Always append results, converting None to empty string
- _loglikelihood_tokens: Always append results, converting None to (-inf, False)
- Applied fix to both sequential and concurrent code paths

The fix ensures:
1. Result lists always have the correct number of items for reordering
2. None values are converted to sensible defaults instead of being skipped
3. Progress bars update correctly for all requests
4. Only successful results are cached

Resolves EleutherAI#3355

* remove irrelevant test

* Remove speculative loglikelihood fixes

Only fix generate_until, which has confirmed evidence of the bug from
issue EleutherAI#3355. The loglikelihood methods have no evidence of this issue:
- No failures reported in issue EleutherAI#3355
- Different code structure in parse_logprobs (no gap creation)
- Stack traces only show generate_until failures

Keep the fix minimal and evidence-based.

* Add warning logs when API returns null content

Log concise warnings when parse_generations returns None to help
users diagnose issues with API responses that have 'content': null.

Warning message suggests checking:
- reasoning_content field (for reasoning models)
- generation limits (max_tokens, length)

Includes first 50 chars of context in sequential path for debugging.

* remove context log
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.

Eval breaking on openai-compatible model run - AssertionError.

2 participants