test(pytorch): cover QuantizedTensor view NotImplementedError - #3257
Conversation
Signed-off-by: Andrew White <andrewh@cdw.com>
for more information, see https://pre-commit.ci
Greptile SummaryThis PR adds a single unit test (
Confidence Score: 5/5Test-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
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 ✓"]
Reviews (3): Last reviewed commit: "Merge branch 'main' into test-quantized-..." | Re-trigger Greptile |
| with pytest.raises( | ||
| NotImplementedError, match="QuantizedTensor class does not support tensor views" | ||
| ): |
There was a problem hiding this comment.
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.
|
Acknowledged the code review finding about the Status: PR #3256 (which adds the missing raise NotImplementedError(f"{cls.__name__} class does not support tensor views")With the f-string in place, the |
|
/te-ci pytorch |
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.