fix(mil): reject symbolic classifier probability shapes - #2767
DebadityaHait wants to merge 2 commits into
Conversation
| raise ValueError(msg) | ||
| size = np.prod(self.probabilities.shape) | ||
| if len(self.classes.val) != size: | ||
| msg = "In op 'classify', number of classes must match the size of the tensor corresponding to 'probabilities'." |
There was a problem hiding this comment.
Please add a similar unit test for this error case as well.
There was a problem hiding this comment.
Added the requested unit test in test_classify.py and pushed the update.
There was a problem hiding this comment.
This test should be similar to your other test. It should be an end to end test, i.e. it should call coremltools.convert.
There was a problem hiding this comment.
Removed the direct MIL-level test. The remaining regression is the PyTorch end-to-end test, which calls coremltools.convert with enumerated input shapes.
There was a problem hiding this comment.
That test is not testing the error case for this line. I want you to add another end to end test that test the error case on this line.
There was a problem hiding this comment.
Reworked this into a dedicated end-to-end regression that converts a traced PyTorch ReLU model whose selected classifier-probability tensor has symbolic shape (is0, 10) from enumerated batch inputs. The test asserts the exact symbolic-shape error at conversion time; under the previous type inference it proceeds past classify to backend export instead.
8f0e9c6 to
b75e2e8
Compare
Fixes #2764.
Reject symbolic classifier probability shapes during
classifytype inference, preventing conversion from producing an undeployable classifier artifact.Tests:
pytest coremltools/converters/mil/frontend/torch/test/test_torch_conversion_api.py::TestPyTorchConverterExamples::test_torch_classifier_rejects_symbolic_probabilities coremltools/converters/mil/frontend/torch/test/test_torch_conversion_api.py::TestPyTorchConverterExamples::test_torch_classifier -qruff check coremltools/converters/mil/mil/ops/defs/iOS15/classify.py