Skip to content

test(pytorch): cover QuantizedTensor view NotImplementedError#3257

Open
andrewwhitecdw wants to merge 2 commits into
NVIDIA:mainfrom
andrewwhitecdw:test-quantized-tensor-view-error
Open

test(pytorch): cover QuantizedTensor view NotImplementedError#3257
andrewwhitecdw wants to merge 2 commits into
NVIDIA:mainfrom
andrewwhitecdw:test-quantized-tensor-view-error

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

Add a unit test for the previously uncovered error path in QuantizedTensor.torch_dispatch when .view() is called on the base QuantizedTensor class.

This complements the fix in #3256 by ensuring the NotImplementedError is raised with the correct, interpolated message.

Signed-off-by: Andrew White <andrewh@cdw.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Jul 25, 2026
@greptile-apps

greptile-apps Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a single unit test (test_view_not_implemented) that exercises the NotImplementedError path in QuantizedTensor.__torch_dispatch__ when .view() is called on the base class. The test is explicitly written as a companion to PR #3256, which fixes the missing f prefix on the error message.

  • The match pattern ("QuantizedTensor class does not support tensor views") targets the correctly interpolated message, but the current main branch still has the plain (un-interpolated) string "{cls.__name__} class does not support tensor views" — meaning the pytest.raises match check will fail on the current codebase and the test cannot pass until fix(pytorch): add missing f-string prefixes to error messages #3256 is merged.
  • The test itself is otherwise well-structured: it directly instantiates the abstract base class, triggers the dispatch path with qt.view(-1), and asserts both the exception type and message.

Confidence Score: 3/5

The test will fail as-is on the current main branch because the companion f-string fix in #3256 has not yet landed.

The match pattern checks for the interpolated class name in the error message, but quantized_tensor.py line 711 is missing the f prefix, so the actual message is the literal {cls.__name__} class does not support tensor views. The regex won't match and the test will fail. Merging this before or without #3256 would introduce a failing test into main.

Files Needing Attention: tests/pytorch/test_quantized_tensor.py — the match string in test_view_not_implemented depends on the f-string fix from #3256 being present first.

Important Files Changed

Filename Overview
tests/pytorch/test_quantized_tensor.py Adds test_view_not_implemented to cover the QuantizedTensor.view error path, but the match pattern targets the interpolated message (QuantizedTensor class does not support tensor views) that only exists after the companion f-string fix in #3256; on the current main the match will fail.

Sequence Diagram

sequenceDiagram
    participant Test as test_view_not_implemented
    participant QT as QuantizedTensor
    participant Dispatch as __torch_dispatch__

    Test->>QT: QuantizedTensor((128,128), bfloat16)
    QT-->>Test: qt (base instance)
    Test->>QT: qt.view(-1)
    QT->>Dispatch: "func=aten.view.default"
    Dispatch-->>Test: raise NotImplementedError("...")
    Note over Test,Dispatch: match expects interpolated "QuantizedTensor class..."<br/>but current code raises literal "{cls.__name__} class..." (no f-prefix)
Loading

Reviews (2): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile

Comment on lines +719 to +721
with pytest.raises(
NotImplementedError, match="QuantizedTensor class does not support tensor views"
):

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.

P1 match pattern won't match current error message

quantized_tensor.py line 711 raises NotImplementedError("{cls.__name__} class does not support tensor views") — a plain string, not an f-string — so the actual exception message is the literal {cls.__name__} class does not support tensor views, not QuantizedTensor class does not support tensor views. The pytest.raises(match=...) call uses re.search, so it will fail to match and the test will fail on the current main branch. This test is only valid once PR #3256 (which adds the f prefix) is merged; the PR description acknowledges this dependency but it is worth ensuring #3256 lands before or together with this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant