class
ShapeNotFlexible
extends
NotImplementedErrorShapeNotFlexible(op_name: str, detail: str)An operation's configuration was derived from the input's size.
Named rather than generic because the alternative is a package that accepts several shapes and is only correct at one of them. An adaptive pool is the usual cause: the tracer records it as an average pool whose kernel came from the input, so the same model traced at two resolutions produces two different kernels.
Examples
A range of resolutions, since that is what an adaptive pool's kernel
is taken from — a range of batch sizes leaves it alone:
>>> import shutil, tempfile
>>> import lucid, lucid.nn as nn, lucid.coreml as cml
>>> model = nn.Sequential(
... nn.Conv2d(3, 8, 3, padding=1), nn.AdaptiveAvgPool2d(1), nn.Flatten()
... ).eval()
>>> room = tempfile.mkdtemp()
>>> try:
... cml.export(model, lucid.randn(1, 3, 16, 16), f"{room}/m.mlpackage",
... shape_range={2: (16, 32), 3: (16, 32)})
... except cml.ShapeNotFlexible as refusal:
... print(refusal)
lucid.coreml: operation 'avg_pool2d' cannot take a flexible shape ...
>>> shutil.rmtree(room)