Skip to content

Conversation

baize97
Copy link

@baize97 baize97 commented Oct 23, 2025

Summary by CodeRabbit

  • New Features
    • Added LongBenchV2 benchmark evaluation capability with support for multiple evaluation modes (standard, RAG, no-context, and Chain-of-Thought).
    • Supports filtering by difficulty level, content length, and domain.
    • Results are saved with comprehensive metrics breakdown by difficulty, length, and domain.

Description

This PR:

  • adds longbench v2 benchmark for long context accuracy evaluation
    • chooses sub dataset according to difficulties or lengths tag
    • selects a specific number of samples for evaluation
    • variable prompt length

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

Signed-off-by: mni <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

📝 Walkthrough

Walkthrough

Introduces LongBenchV2, a new evaluation benchmark module for TensorRT-LLM, by implementing a complete evaluator class and registering it as an importable module and CLI command.

Changes

Cohort / File(s) Change Summary
CLI and Module Registration
tensorrt_llm/commands/eval.py, tensorrt_llm/evaluate/__init__.py
Added LongBenchV2 to module imports and all exports; registered LongBenchV2.command as a CLI subcommand in the evaluation command group
LongBenchV2 Evaluator Implementation
tensorrt_llm/evaluate/longbench_v2.py
New module implementing LongBenchV2 evaluator class with dataset loading, template management, multi-mode prompt formatting (standard, RAG, no-context, CoT), answer extraction, token truncation, metric computation by difficulty/length/domain, result persistence, and Click CLI integration

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant LongBenchV2
    participant LLM
    participant Tokenizer
    participant FileSystem

    User->>CLI: invoke longbench_v2 command
    CLI->>LongBenchV2: evaluate(llm, sampling_params)
    
    LongBenchV2->>LongBenchV2: _load_templates(prompts_dir)
    LongBenchV2->>LongBenchV2: _load_and_filter_dataset()
    
    loop for each sample
        LongBenchV2->>LongBenchV2: _format_prompt(sample, template)
        LongBenchV2->>Tokenizer: encode(prompt)
        LongBenchV2->>LongBenchV2: _truncate_prompt(prompt, tokenizer)
        LongBenchV2->>LLM: generate(truncated_prompt)
        LLM-->>LongBenchV2: model_output
        LongBenchV2->>LongBenchV2: _post_process(output)
        LongBenchV2->>LongBenchV2: _extract_answer(processed_output)
    end
    
    LongBenchV2->>LongBenchV2: _calculate_metrics(results)
    LongBenchV2->>FileSystem: _save_results(longbench_v2_results.jsonl, predictions.jsonl, summary.json)
    LongBenchV2-->>User: evaluation complete with metrics
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "[None][test]: Add longbench v2 for long context evaluation" directly and specifically describes the main change in this pull request, which is the addition of a new LongBenchV2 evaluator for long context accuracy evaluation. The title is concise, clear, and avoids vague language. It accurately summarizes the primary change shown in the raw summary, which includes the new LongBenchV2 class implementation and its integration into the evaluation commands.
Description Check ✅ Passed The pull request description is mostly complete with a well-detailed "Description" section that clearly explains what is being added: longbench v2 benchmark support with the ability to select sub-datasets by difficulty/length tags, specify sample counts, and handle variable prompt lengths. However, the "Test Coverage" section is entirely empty with no information about relevant tests that safeguard these changes. The "PR Checklist" section is present but unchecked. Despite the missing test coverage details, the core description is specific and provides sufficient context about the changes.
Docstring Coverage ✅ Passed Docstring coverage is 93.33% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
tensorrt_llm/evaluate/longbench_v2.py (2)

51-52: Consider annotating class constants with ClassVar.

These mutable class attributes should be annotated with typing.ClassVar to indicate they are class-level constants, improving type safety.

Apply this diff:

+from typing import ClassVar
+
 class LongBenchV2(Evaluator):
     """Evaluator for LongBench v2 benchmark.
 
     This evaluator implements the LongBench v2 benchmark for evaluating long-context
     language models. It supports multiple evaluation modes and filtering options.
 
     Attributes:
         DIFFICULTIES: List of supported difficulty levels
         LENGTHS: List of supported context length categories
     """
 
-    DIFFICULTIES = ['easy', 'hard']
-    LENGTHS = ['short', 'medium', 'long']
+    DIFFICULTIES: ClassVar[List[str]] = ['easy', 'hard']
+    LENGTHS: ClassVar[List[str]] = ['short', 'medium', 'long']

127-138: Normalize quotation marks in template strings.

The template strings contain ambiguous right single quotation marks (') that should be replaced with standard grave accents (`) or apostrophes (') for consistency.

Apply this diff to lines 131 and 133:

             '0shot_cot':
-            '''Please read the following text and answer the questions below.\n\n<text>\n$DOC$\n</text>\n\nWhat is the correct answer to this question: $Q$\nChoices:\n(A) $C_A$\n(B) $C_B$\n(C) $C_C$\n(D) $C_D$\n\nLet's think step by step:''',
+            '''Please read the following text and answer the questions below.\n\n<text>\n$DOC$\n</text>\n\nWhat is the correct answer to this question: $Q$\nChoices:\n(A) $C_A$\n(B) $C_B$\n(C) $C_C$\n(D) $C_D$\n\nLet's think step by step:''',
             '0shot_cot_ans':
-            '''Please read the following text and answer the questions below.\n\nThe text is too long and omitted here.\n\nWhat is the correct answer to this question: $Q$\nChoices:\n(A) $C_A$\n(B) $C_B$\n(C) $C_C$\n(D) $C_D$\n\nLet's think step by step: $COT$\n\nBased on the above, what is the single, most likely answer choice? Format your response as follows: "The correct answer is (insert answer here)".''',
+            '''Please read the following text and answer the questions below.\n\nThe text is too long and omitted here.\n\nWhat is the correct answer to this question: $Q$\nChoices:\n(A) $C_A$\n(B) $C_B$\n(C) $C_C$\n(D) $C_D$\n\nLet's think step by step: $COT$\n\nBased on the above, what is the single, most likely answer choice? Format your response as follows: "The correct answer is (insert answer here)".''',
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2956978 and 778af0f.

📒 Files selected for processing (3)
  • tensorrt_llm/commands/eval.py (2 hunks)
  • tensorrt_llm/evaluate/__init__.py (1 hunks)
  • tensorrt_llm/evaluate/longbench_v2.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use only spaces, no tabs; indent with 4 spaces.

Files:

  • tensorrt_llm/commands/eval.py
  • tensorrt_llm/evaluate/__init__.py
  • tensorrt_llm/evaluate/longbench_v2.py
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.

Files:

  • tensorrt_llm/commands/eval.py
  • tensorrt_llm/evaluate/__init__.py
  • tensorrt_llm/evaluate/longbench_v2.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).

Files:

  • tensorrt_llm/commands/eval.py
  • tensorrt_llm/evaluate/__init__.py
  • tensorrt_llm/evaluate/longbench_v2.py
🧬 Code graph analysis (3)
tensorrt_llm/commands/eval.py (1)
tensorrt_llm/evaluate/longbench_v2.py (2)
  • LongBenchV2 (40-850)
  • command (818-850)
tensorrt_llm/evaluate/__init__.py (1)
tensorrt_llm/evaluate/longbench_v2.py (1)
  • LongBenchV2 (40-850)
tensorrt_llm/evaluate/longbench_v2.py (5)
examples/models/core/multimodal/eval.py (1)
  • load_dataset (90-113)
tensorrt_llm/llmapi/llm.py (2)
  • RequestOutput (50-90)
  • prompt (83-84)
tensorrt_llm/evaluate/interface.py (1)
  • Evaluator (31-118)
tensorrt_llm/llmapi/tokenizer.py (1)
  • name_or_path (48-49)
tensorrt_llm/executor/result.py (1)
  • prompt_token_ids (708-709)
🪛 Ruff (0.14.1)
tensorrt_llm/evaluate/longbench_v2.py

51-51: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


52-52: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


131-131: String contains ambiguous (RIGHT SINGLE QUOTATION MARK). Did you mean ``` (GRAVE ACCENT)?

(RUF001)


133-133: String contains ambiguous (RIGHT SINGLE QUOTATION MARK). Did you mean ``` (GRAVE ACCENT)?

(RUF001)


334-334: Do not catch blind exception: Exception

(BLE001)


383-383: Do not catch blind exception: Exception

(BLE001)


392-392: Do not catch blind exception: Exception

(BLE001)


491-492: zip() without an explicit strict= parameter

Add explicit value for parameter strict=

(B905)


531-531: Do not catch blind exception: Exception

(BLE001)


711-711: Loop control variable result not used within loop body

(B007)

🔇 Additional comments (15)
tensorrt_llm/evaluate/__init__.py (1)

19-19: LGTM!

The import and export of LongBenchV2 follow the established pattern for other evaluators in this module.

Also applies to: 24-24

tensorrt_llm/commands/eval.py (1)

24-24: LGTM!

The CLI command registration follows the established pattern for other evaluation commands.

Also applies to: 162-162

tensorrt_llm/evaluate/longbench_v2.py (13)

1-38: LGTM!

The copyright header, imports, and module docstring are well-structured and follow the coding guidelines.


54-113: LGTM!

The constructor is well-documented with a Google-style docstring, properly initializes all instance attributes, and follows the coding guidelines.


162-213: LGTM!

The dataset loading and filtering logic is well-structured with informative logging at each step.


215-251: LGTM!

The prompt formatting logic correctly handles standard, RAG, and no-context modes with clear placeholder replacements.


253-304: LGTM!

The answer extraction uses multiple fallback patterns, and post-processing correctly handles template-specific cleanup for different chat formats.


306-338: LGTM!

The truncation logic implements a reasonable needle-in-haystack strategy with appropriate error handling and fallback to the original prompt.


340-394: LGTM!

Template detection and extra token ID extraction have appropriate error handling with safe defaults and logging.


396-438: LGTM!

The evaluate method correctly initializes tokenizer state, manages extra end tokens, and delegates to the parent implementation.


440-474: LGTM!

Sample generation correctly selects templates based on evaluation mode and yields properly formatted tuples.


476-631: LGTM!

The scoring logic comprehensively handles standard and CoT modes, builds detailed per-sample results, and provides extensive logging of breakdowns by difficulty, length, and domain.


633-686: LGTM!

Metrics calculation properly computes overall accuracy and detailed breakdowns by multiple dimensions.


715-745: LGTM!

The predictions and summary file generation is correctly implemented with proper per-sample iteration and comprehensive metadata.


817-850: LGTM!

The CLI command implementation correctly builds sampling parameters, instantiates the evaluator with all options, and handles the evaluation lifecycle.

Signed-off-by: mni <[email protected]>
Copy link
Collaborator

@syuoni syuoni left a comment

Choose a reason for hiding this comment

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

Thanks @baize97 for the new eval task. Do you plan to add a test in the accuracy test suite?

Copy link
Collaborator

@syuoni syuoni left a comment

Choose a reason for hiding this comment

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

LGTM

@baize97
Copy link
Author

baize97 commented Oct 23, 2025

/bot run

1 similar comment
@kaiyux
Copy link
Member

kaiyux commented Oct 23, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22250 [ run ] triggered by Bot. Commit: 963c011

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22250 [ run ] completed with state SUCCESS. Commit: 963c011
/LLM/main/L0_MergeRequest_PR pipeline #16774 completed with status: 'FAILURE'

@kaiyux
Copy link
Member

kaiyux commented Oct 23, 2025

/bot run --disable-fail-fast

1 similar comment
@kaiyux
Copy link
Member

kaiyux commented Oct 23, 2025

/bot run --disable-fail-fast

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.

4 participants