Skip to content

fix(mil): reject symbolic classifier probability shapes - #2767

Open
DebadityaHait wants to merge 2 commits into
apple:mainfrom
DebadityaHait:fix/classifier-symbolic-probability-shape
Open

DebadityaHait wants to merge 2 commits into
apple:mainfrom
DebadityaHait:fix/classifier-symbolic-probability-shape

Conversation

@DebadityaHait

@DebadityaHait DebadityaHait commented Aug 1, 2026 •

Copy link
Copy Markdown

Fixes #2764.

Reject symbolic classifier probability shapes during classify type 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 -q
  • ruff check coremltools/converters/mil/mil/ops/defs/iOS15/classify.py

Comment thread coremltools/converters/mil/mil/ops/tests/iOS15/test_classify.py Outdated
@TobyRoseman

Copy link
Copy Markdown
Collaborator

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'."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a similar unit test for this error case as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the requested unit test in test_classify.py and pushed the update.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should be similar to your other test. It should be an end to end test, i.e. it should call coremltools.convert.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the direct MIL-level test. The remaining regression is the PyTorch end-to-end test, which calls coremltools.convert with enumerated input shapes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DebadityaHait
DebadityaHait force-pushed the fix/classifier-symbolic-probability-shape branch from 8f0e9c6 to b75e2e8 Compare August 6, 2026 03:52

This branch has not been deployed

No deployments
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.

EnumeratedShapes converts with ClassifierConfig

2 participants