class
UnsupportedRank
extends
NotImplementedErrorUnsupportedRank(op_name: str, shape: tuple[int, ...])A tensor exceeds the rank Core ML's program dialect allows.
Not something the writer can work around: the limit is the format's.
Window-attention models hit it — Swin partitions into
(B, H/w, w, W/w, w, C), which is rank six — and the honest answer
is to say which operation and which shape rather than to reshape
around it and hope the semantics survive.
Examples
>>> import shutil, tempfile
>>> import lucid, lucid.nn as nn, lucid.coreml as cml
>>> class Tall(nn.Module):
... def forward(self, x):
... return x.reshape(1, 4, 2, 4, 2, 3).sum(dim=5)
>>> room = tempfile.mkdtemp()
>>> try:
... cml.export(Tall().eval(), lucid.randn(1, 8, 8, 3), f"{room}/m.mlpackage")
... except cml.UnsupportedRank as refusal:
... print(refusal)
lucid.coreml: op 'reshape' produces a rank-6 tensor (1, 4, 2, 4, 2, 3), ...
>>> shutil.rmtree(room)