Skip to content

[Test] Add unit tests for managers/schedule_batch.py#24381

Open
yangyonggit wants to merge 4 commits intosgl-project:mainfrom
yangyonggit:unit-test/schedule-batch
Open

[Test] Add unit tests for managers/schedule_batch.py#24381
yangyonggit wants to merge 4 commits intosgl-project:mainfrom
yangyonggit:unit-test/schedule-batch

Conversation

@yangyonggit
Copy link
Copy Markdown

Summary

Closes #20865

Add 67 CPU-only unit tests for the Req class in srt/managers/schedule_batch.py, which had no dedicated unit test file.

  • Finish reasons (FINISH_MATCHED_TOKEN, FINISH_MATCHED_STR, FINISHED_MATCHED_REGEX, FINISH_LENGTH, FINISH_ABORT): to_json() shape and is_error flag
  • Req properties: seqlen, finished(), output_ids_through_stop
  • check_finished: already-finished noop, to_finish transfer, length limit, stop token ID, eos_token_ids, ignore_eos bypass, stop string in decoded_text, finished_len correctness
  • reset_for_retract: retraction counter, prefix_indices cleared, KV lengths/flags zeroed, output_ids cleared only when input_embeds is set
  • set_extend_input_len: extend_logprob_start_len for logprob_start_len = 0, positive, −1, and clamped cases
  • update_reasoning_tokens: think_end_id in middle/first/last/absent, noop after reasoning over, single-int input
  • _check_vocab_boundary_finish: valid tokens, token above vocab_size, negative token, stop_token_id/eos replacement, eos wins when both set, finished_len at correct offset
  • init_incremental_detokenize: first-call offset computation, short input (surr_offset=0), incremental extension, stability with no new tokens
  • check_match_stop_str_prefix: no stop strings, empty tail, full match, partial suffix overlap ("EN" vs "END"), single-char overlap, multiple stop strings

Test plan

  • All 67 tests pass on CPU with no GPU, no server, no model weights
  • Registered under stage-a-test-cpu (register_cpu_ci)
  • pre-commit run --files passes (isort, black, ruff, codespell)
$ python -m pytest test/registered/unit/managers/test_schedule_batch.py -q
67 passed, 3 warnings in 7.70s

🤖 Generated with Claude Code

Add 67 CPU-only unit tests covering the Req class in schedule_batch.py,
which had no dedicated unit test coverage.

Tests cover:
- Finish reason to_json() for all 5 reason types
- seqlen, finished(), output_ids_through_stop properties
- check_finished(): already-finished noop, to_finish transfer, length
  limit, stop token ID, eos_token_ids, ignore_eos bypass, stop string
  in decoded_text, finished_len correctness
- reset_for_retract(): retraction counter, prefix_indices, KV lengths,
  flags, output_ids cleared only when input_embeds is set
- set_extend_input_len(): basic set and extend_logprob_start_len
  computation for logprob_start_len = 0, positive, -1, and clamped
- update_reasoning_tokens(): think_end_id in middle/first/last/absent,
  noop after reasoning over, single-int input
- _check_vocab_boundary_finish(): valid tokens, token above vocab_size,
  negative token, stop_token_id/eos replacement, eos wins over stop,
  finished_len at correct offset, stops at first bad token
- init_incremental_detokenize(): first-call offset computation, short
  input (surr_offset=0), incremental extension, stability with no new tokens
- check_match_stop_str_prefix(): no stop_strs, empty tail, full match,
  partial suffix overlap ("EN" vs "END"), single-char overlap, no match,
  multiple stop strings

All tests run on CPU (stage-a-test-cpu) with no server or model weights.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive suite of unit tests for the schedule_batch.py manager, specifically focusing on the Req class and various finish reason objects. The tests cover request properties, finish condition logic (including token and string matches), state resets during retraction, reasoning token tracking, and incremental detokenization offsets. I have no feedback to provide.

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.

[Feature] Improve Unit Test Coverage

1 participant