Skip to content

test(sampling_params): repair broken test collection and add verify() coverage#1350

Open
SuperMarioYL wants to merge 1 commit into
ModelTC:mainfrom
SuperMarioYL:test/repair-sampling-params-add-verify-coverage
Open

test(sampling_params): repair broken test collection and add verify() coverage#1350
SuperMarioYL wants to merge 1 commit into
ModelTC:mainfrom
SuperMarioYL:test/repair-sampling-params-add-verify-coverage

Conversation

@SuperMarioYL

Copy link
Copy Markdown
Contributor

What

unit_tests/server/core/objs/test_sampling_params.py currently fails at collection:

ImportError: cannot import name 'DecodeNode' from
'lightllm.server.core.objs.sampling_params'

DecodeNode (and the move_kv_to_decode_node sampling field) were removed together with the nccl PD mode, so the module-level import on line 8 raises ImportError and pytest cannot collect any test in the file.

This PR:

  1. Removes the dead DecodeNode import and test_decode_node_initialization, and drops the stale move_kv_to_decode_node kwarg from test_sampling_params_initialization, so the module collects again.
  2. Adds coverage for SamplingParams.verify(), which previously had none even though it is the per-request input-validation gate. The new tests cover:
    • the n == best_of constraint and best_of / n range limits (MAX_BEST_OF);
    • presence_penalty / frequency_penalty / repetition_penalty bounds;
    • temperature, top_p, top_k bounds (and valid top_k values);
    • max_new_tokens / min_new_tokens bounds and their ordering;
    • mutual exclusion of regular_constraint and allowed_token_ids.

A small _make_params() helper builds a valid configuration and applies per-test overrides. It sets do_sample=True so the sampling fields are validated as provided (greedy decoding resets them inside init).

Why

The broken import silently disabled the entire sampling-params test module, and verify() had no direct tests. Restoring collection and adding these cases guards the request-validation rules against regressions.

Test

pytest unit_tests/server/core/objs/test_sampling_params.py
# 32 passed

Formatting verified with the project's pre-commit hooks (black --line-length=120, flake8).

The test module failed to collect because it imported and tested DecodeNode,
which no longer exists after the nccl pd-mode removal. Drop the dead import and
its test, remove the stale move_kv_to_decode_node kwarg, and add coverage for
SamplingParams.verify(), which previously had none: the n == best_of constraint,
best_of/n range limits, penalty and temperature/top_p/top_k bounds,
min/max_new_tokens, and constraint mutual-exclusion.

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

Copy link
Copy Markdown
Contributor

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 removes the DecodeNode test and its associated fields, and introduces a comprehensive suite of unit tests for verifying SamplingParams configurations using a new helper function _make_params. The review feedback correctly points out that since _make_params internally triggers verification during initialization, calling .verify() in tests that expect a ValueError is redundant and should be removed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

def test_verify_rejects_n_not_equal_best_of():
# The engine currently only supports n == best_of; a mismatch must be rejected.
with pytest.raises(ValueError):
_make_params(best_of=2, n=1).verify()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since _make_params internally calls params.init(), which automatically runs self.verify(), any invalid parameter configuration will raise a ValueError during initialization. Consequently, the trailing .verify() call is never reached and is dead code. Removing .verify() makes the test cleaner and accurately reflects where the exception is raised.

Suggested change
_make_params(best_of=2, n=1).verify()
_make_params(best_of=2, n=1)

@pytest.mark.parametrize("best_of", [0, -1, MAX_BEST_OF + 1])
def test_verify_rejects_best_of_out_of_range(best_of):
with pytest.raises(ValueError):
_make_params(best_of=best_of, n=best_of).verify()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since _make_params internally calls params.init(), which automatically runs self.verify(), any invalid parameter configuration will raise a ValueError during initialization. Consequently, the trailing .verify() call is never reached and is dead code. Removing .verify() makes the test cleaner and accurately reflects where the exception is raised.

Suggested change
_make_params(best_of=best_of, n=best_of).verify()
_make_params(best_of=best_of, n=best_of)

)
def test_verify_rejects_invalid_sampling_fields(field, value):
with pytest.raises(ValueError):
_make_params(**{field: value}).verify()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since _make_params internally calls params.init(), which automatically runs self.verify(), any invalid parameter configuration will raise a ValueError during initialization. Consequently, the trailing .verify() call is never reached and is dead code. Removing .verify() makes the test cleaner and accurately reflects where the exception is raised.

Suggested change
_make_params(**{field: value}).verify()
_make_params(**{field: value})


def test_verify_rejects_min_new_tokens_greater_than_max():
with pytest.raises(ValueError):
_make_params(min_new_tokens=8, max_new_tokens=4).verify()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since _make_params internally calls params.init(), which automatically runs self.verify(), any invalid parameter configuration will raise a ValueError during initialization. Consequently, the trailing .verify() call is never reached and is dead code. Removing .verify() makes the test cleaner and accurately reflects where the exception is raised.

Suggested change
_make_params(min_new_tokens=8, max_new_tokens=4).verify()
_make_params(min_new_tokens=8, max_new_tokens=4)

def test_verify_rejects_regular_constraint_with_allowed_token_ids():
# regular_constraint and allowed_token_ids are mutually exclusive.
with pytest.raises(ValueError):
_make_params(regular_constraint="[a-z]+", allowed_token_ids=[1, 2, 3]).verify()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since _make_params internally calls params.init(), which automatically runs self.verify(), any invalid parameter configuration will raise a ValueError during initialization. Consequently, the trailing .verify() call is never reached and is dead code. Removing .verify() makes the test cleaner and accurately reflects where the exception is raised.

Suggested change
_make_params(regular_constraint="[a-z]+", allowed_token_ids=[1, 2, 3]).verify()
_make_params(regular_constraint="[a-z]+", allowed_token_ids=[1, 2, 3])

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.

1 participant