Skip to content

Conversation

@zasdfgbnm
Copy link
Collaborator

@zasdfgbnm zasdfgbnm commented Dec 17, 2025

So that we have the flexibility to do something with the error checking

@zasdfgbnm
Copy link
Collaborator Author

!test

@github-actions
Copy link

github-actions bot commented Dec 17, 2025

Review updated until commit 0ba42a3

Description

  • Update error regex pattern for topk function in opinfo_input_generators.py

  • Change from specific "selected index k out of range" to flexible "k .* range"

  • Makes error matching more robust across different PyTorch versions

  • Affects only the topk_error_generator function's error message validation

Changes walkthrough

Relevant files
Bug fix
opinfo_input_generators.py
Update topk error regex pattern                                                   

tests/python/opinfo/opinfo_input_generators.py

  • Modified error regex pattern in topk_error_generator function
  • Changed from "selected index k out of range" to "k .* range"
  • Makes error message matching more flexible and version-agnostic
  • Maintains same RuntimeError type but with broader pattern matching
  • +1/-3     

    PR Reviewer Guide

    Here are some key observations to aid the review process:

    🧪 PR contains tests
    ⚡ Recommended focus areas for review
    Error Message Regex Validation

    The PR updates the error message regex from "selected index k out of range" to "k .* range". This change should be validated to ensure it correctly matches the actual PyTorch error message for the topk operation when k is out of range (k=16 in this test case). The reviewer should verify that the new regex pattern is appropriate and matches the expected error format.

    yield SampleInput(a, 16, 1, True, False), RuntimeError, "k .* range"

    @zasdfgbnm
    Copy link
    Collaborator Author

    !test

    @zasdfgbnm zasdfgbnm marked this pull request as ready for review December 17, 2025 19:17
    @zasdfgbnm zasdfgbnm changed the title Update error regex in for topk in opinfo_input_generators.py Update error regex for topk in opinfo_input_generators.py Dec 17, 2025
    @zasdfgbnm
    Copy link
    Collaborator Author

    !test

    @greptile-apps
    Copy link
    Contributor

    greptile-apps bot commented Jan 6, 2026

    Greptile Summary

    Updated the error message pattern for topk operation from a literal string "selected index k out of range" to a regex pattern "k .* range" and reformatted the code to a single line.

    • Changed error message from exact match to flexible regex pattern that can match variations of the error message from PyTorch's aten fallback (e.g., "selected index k out of range", "k out of range", "k is out of range")
    • Improved test robustness against potential error message variations across PyTorch versions
    • Reformatted the test case from multi-line to single-line for better readability

    Confidence Score: 5/5

    • This PR is safe to merge with minimal risk
    • The change improves test robustness by using a regex pattern instead of an exact string match for error messages. The pattern "k .* range" correctly matches the expected error scenarios. The regex is simple and safe (using .* for any characters between "k" and "range"), and the code formatting change has no functional impact. This is a low-risk test maintenance change.
    • No files require special attention

    Important Files Changed

    Filename Overview
    tests/python/opinfo/opinfo_input_generators.py Updated error regex from literal string to regex pattern k .* range and reformatted to single line - safe change

    Sequence Diagram

    sequenceDiagram
        participant Test as Test Framework
        participant Generator as topk_error_generator
        participant Matcher as pytest.raises
        participant Regex as _regex_escape_parenthesis
        participant TopK as topk Operation
        
        Test->>Generator: Call error generator
        Generator->>Generator: Create test tensor (128, 7, 32)
        Generator->>Generator: Generate error case: topk(a, k=16, dim=1)
        Note over Generator: k=16 exceeds dimension size of 7
        Generator->>Test: Yield (SampleInput, RuntimeError, "k .* range")
        
        Test->>Matcher: Setup pytest.raises with error pattern
        Matcher->>Regex: Escape parentheses in pattern
        Regex->>Matcher: Return escaped pattern
        
        Test->>TopK: Execute topk operation with invalid k
        TopK->>TopK: Falls back to aten
        TopK->>Test: Raise RuntimeError with message matching "k .* range"
        
        Matcher->>Matcher: Match error message against regex
        Note over Matcher: Pattern "k .* range" matches variations like:<br/>"selected index k out of range"<br/>"k out of range"<br/>"k is out of range"
        Matcher->>Test: Test passes
    
    Loading

    @greptile-apps
    Copy link
    Contributor

    greptile-apps bot commented Jan 6, 2026

    Greptile's behavior is changing!

    From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section.

    This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

    @zasdfgbnm zasdfgbnm requested a review from jjsjann123 January 6, 2026 20:27
    @zasdfgbnm zasdfgbnm merged commit 039365b into main Jan 8, 2026
    62 checks passed
    @zasdfgbnm zasdfgbnm deleted the zasdfgbnm-patch-7 branch January 8, 2026 21:17
    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.

    3 participants