Skip to content

Avoid mutating input shapes when creating EnumeratedShapes - #2873

Open
dipeshbabu wants to merge 2 commits into
apple:mainfrom
dipeshbabu:fix/enumerated-shapes-input-mutation
Open

dipeshbabu wants to merge 2 commits into
apple:mainfrom
dipeshbabu:fix/enumerated-shapes-input-mutation

Conversation

@dipeshbabu

Copy link
Copy Markdown

EnumeratedShapes aliases the first input shape's dimension list and replaces entries while computing its common symbolic shape. Constructing EnumeratedShapes([shape, (1, 4)]) with shape = Shape((1, 2)) therefore turns the caller's fixed shape into a symbolic one. Reusing that shape in another enumeration also changes the first enumeration, and TensorType can stop rejecting incompatible optional defaults.

Copy the dimension list before combining shapes. A shallow copy preserves symbol identity and takes space proportional to tensor rank; tensor data and input Shape objects are not copied.

Validation:

  • Added 12 regression cases covering Shape/list/tuple inputs, explicit and implicit defaults, repeated and shared shapes, existing symbols, RangeDim inputs in either order, and fixed-shape optional-default validation.
  • All 12 cases failed before the fix.
  • Python 3.10.12 / NumPy 1.26.4 / pytest 7.1.2: 35 tests passed across the regression module, existing input-type tests, and MIL type tests.
  • Regression tests live in coremltools.converters.mil.mil.tests, which the configured GitLab MIL job discovers.
  • git diff --check passed.
  • Full macOS GitLab build/test/documentation CI remains unverified; local validation ran on Windows.

Local test command (pytest file logging/cache disabled because sandbox writes were denied):

python -m pytest coremltools/converters/mil/test/test_input_types.py coremltools/converters/mil/mil/tests/test_enumerated_shapes.py coremltools/converters/mil/mil/tests/test_types.py -o addopts= --tb=short -p no:logging -p no:cacheprovider

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

1 participant