Skip to content

test(pytorch): cover QuantizedTensor view NotImplementedError - #3257

Merged
ptrendx merged 3 commits into
NVIDIA:mainfrom
andrewwhitecdw:test-quantized-tensor-view-error
Jul 28, 2026
Merged

test(pytorch): cover QuantizedTensor view NotImplementedError#3257
ptrendx merged 3 commits into
NVIDIA:mainfrom
andrewwhitecdw:test-quantized-tensor-view-error

Conversation

@andrewwhitecdw

Copy link
Copy Markdown
Contributor

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) to TestQuantizedTensor that covers the previously untested error path in QuantizedTensor.__torch_dispatch__ when .view() is called on the base class. It depends on PR #3256 adding the f-prefix to the NotImplementedError message; that fix is already present on main (line 711 of quantized_tensor.py), so the match pattern will resolve correctly.

  • Instantiates the base QuantizedTensor((128, 128), torch.bfloat16) directly and asserts that qt.view(-1) raises NotImplementedError with the interpolated class name in the message.
  • No device is passed to the constructor, so torch.cuda.current_device() is used — consistent with all other tests in TestQuantizedTensor, which also assume a CUDA-capable environment.

Confidence Score: 5/5

Test-only change that adds coverage for a single, well-scoped error path; no production code is modified.

The new test correctly instantiates the base QuantizedTensor, calls .view(-1), and asserts the NotImplementedError is raised with the f-string-interpolated message that is already present in quantized_tensor.py line 711. The logic, pattern match, and class name interpolation all align. No regressions are possible from a test-only addition.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
tests/pytorch/test_quantized_tensor.py Adds test_view_not_implemented to TestQuantizedTensor, verifying that calling .view() on the base QuantizedTensor raises NotImplementedError with the correct interpolated message.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["qt = QuantizedTensor((128, 128), torch.bfloat16)"] --> B["qt.view(-1)"]
    B --> C["PyTorch dispatches aten.view.default"]
    C --> D["QuantizedTensor.__torch_dispatch__"]
    D --> E{{"func == aten.view.default?"}}
    E -- Yes --> F["raise NotImplementedError\nf'{cls.__name__} class does not support tensor views'"]
    E -- No --> G["Handle other ops..."]
    F --> H["pytest.raises catches NotImplementedError\nmatch='QuantizedTensor class does not support tensor views'"]
    H --> I["Test PASSES ✓"]
Loading

Reviews (3): Last reviewed commit: "Merge branch 'main' into test-quantized-..." | 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.

@andrewwhitecdw

Copy link
Copy Markdown
Contributor Author

Acknowledged the code review finding about the match pattern dependency.

Status: PR #3256 (which adds the missing f prefix to the error message) is already merged as of 2026-07-27. Verified that transformer_engine/pytorch/quantized_tensor.py:711 now reads:

raise NotImplementedError(f"{cls.__name__} class does not support tensor views")

With the f-string in place, the pytest.raises(match="QuantizedTensor class does not support tensor views") pattern correctly matches the interpolated exception message. This test is valid and ready for review.

@ptrendx

ptrendx commented Jul 28, 2026

Copy link
Copy Markdown
Member

/te-ci pytorch

@ptrendx
ptrendx merged commit 37d03ba into NVIDIA:main Jul 28, 2026
21 of 26 checks passed
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.

2 participants