Skip to content

Conversation

@xunyoyo
Copy link

@xunyoyo xunyoyo commented Nov 15, 2025

Motivation

NO.37 功能模块 fastdeploy/output/token_processor.py 单测补充

Modifications

add tests/output/test_token_processor.py

Usage or Command

tests/output/test_token_processor.py:

python -m coverage run -m unittest tests.output.test_token_processor \
&& python -m coverage report -m --include='fastdeploy/output/token_processor.py'

Accuracy Tests

tests/output/test_token_processor.py:

Stmts   Miss  Cover   Missing
--------------------------------------------------------------------
fastdeploy/output/token_processor.py     528     95    82%   238, 263, 312-331, 338-406, 472, 480-481, 488, 533, 537-538, 575-57
6, 583, 607-610, 616, 618-621, 675-676, 681, 721-723, 727, 753-754, 829, 836, 866-868, 871, 879, 881, 892-894, 900-902
--------------------------------------------------------------------
TOTAL                                    528     95    82%

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

Copilot AI review requested due to automatic review settings November 15, 2025 10:37
@paddle-bot
Copy link

paddle-bot bot commented Nov 15, 2025

Thanks for your contribution!

@paddle-bot paddle-bot bot added the contributor External developers label Nov 15, 2025
Copilot finished reviewing on behalf of xunyoyo November 15, 2025 10:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive unit tests for the fastdeploy/output/token_processor.py module as part of Hackathon 9th Sprint No.37, achieving 82% test coverage through extensive mocking and isolation testing.

Key Changes

  • New test file with 23 test methods covering token processing, speculative decoding, metrics tracking, and resource management
  • Custom stub modules to isolate token_processor.py from external dependencies (paddle, zmq, etc.)
  • Comprehensive test fixtures and helper classes for simulating various processing scenarios

pass


def _install_stub_modules():
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Add a docstring to explain what this function does and why module stubbing is necessary. For example:

def _install_stub_modules():
    """Install stub/mock modules to isolate the token_processor module for testing.
    
    This creates fake implementations of external dependencies (paddle, zmq, fastdeploy 
    submodules) to allow testing token_processor.py in isolation without requiring 
    actual hardware or the full dependency stack.
    
    Returns:
        tuple: (main_process_metrics, utils_module) for test inspection
    """
Suggested change
def _install_stub_modules():
def _install_stub_modules():
"""Install stub/mock modules to isolate the token_processor module for testing.
This creates fake implementations of external dependencies (paddle, zmq, fastdeploy
submodules) to allow testing token_processor.py in isolation without requiring
actual hardware or the full dependency stack.
Returns:
tuple: (main_process_metrics, utils_module) for test inspection
"""

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,740 @@
from __future__ import annotations
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Missing copyright header. All test files in this repository should include the standard Apache 2.0 copyright header. Please add the following at the beginning of the file:

"""
# Copyright (c) 2025  PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""

Copilot uses AI. Check for mistakes.
return _Request(**base)


class TokenProcessorTestCase(unittest.TestCase):
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Add a docstring to the test class to describe its purpose. For example:

class TokenProcessorTestCase(unittest.TestCase):
    """Test suite for TokenProcessor class functionality including output processing, 
    speculative decoding, metrics tracking, and resource management."""
Suggested change
class TokenProcessorTestCase(unittest.TestCase):
class TokenProcessorTestCase(unittest.TestCase):
"""Test suite for TokenProcessor class functionality including output processing,
speculative decoding, metrics tracking, and resource management."""

Copilot uses AI. Check for mistakes.
return []


class _Request(dict):
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

The class '_Request' does not override 'eq', but adds the new attribute dict.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants