Skip to content

Reject a classifier whose probabilities have a symbolic shape - #2793

Open
LeSingh1 wants to merge 1 commit into
apple:mainfrom
LeSingh1:classifier-symbolic-probabilities
Open

Reject a classifier whose probabilities have a symbolic shape#2793
LeSingh1 wants to merge 1 commit into
apple:mainfrom
LeSingh1:classifier-symbolic-probabilities

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

classify's type inference only checks that the number of class labels matches the size of probabilities when that shape is fully known. With a flexible input shape the check is skipped, so conversion succeeds and returns a model the Core ML runtime cannot compile:

Error: Unable to parse ML Program: in operation classify_1:
Classifier probabilities must have a fully known shape.

This fails for every input shape, including the ones where the symbol resolves to a size that matches the labels, so there is no shape at which the returned model works. A fixed non-matching batch already raises at conversion time; this makes the flexible case fail there too instead of at prediction.

Repro on main (converts, then every predict fails):

@mb.program(input_specs=[mb.TensorSpec(shape=(get_new_symbol(), 4))])
def prog(x):
    return mb.softmax(x=x, axis=1)

ct.convert(
    prog, source="milinternal", convert_to="mlprogram",
    inputs=[ct.TensorType(name="x", shape=ct.EnumeratedShapes([(1, 4), (4, 4)]))],
    classifier_config=ct.ClassifierConfig(["a", "b", "c", "d"]),
    minimum_deployment_target=ct.target.iOS16,
)

Added a parametrized test over enumerated and range-dimension shapes; both fail on main.

Refs #2764

The Core ML runtime requires a classifier's probabilities to have a fully
known shape. With a flexible input shape the size check in classify's type
inference is skipped, so conversion returns a model that fails to compile
for every input shape, including the ones where the symbol resolves to a
size matching the class labels.
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.

1 participant