{"record":{"id":"d2596f6804122ce9","repo":"facebookresearch/detectron2","slug":"unsupported-onnx-export-of-repeat-interleave-for-d2596f","errorCode":null,"errorMessage":"Unsupported: ONNX export of repeat_interleave for unknown repeats size.","messagePattern":"Unsupported: ONNX export of repeat_interleave for unknown repeats size\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"detectron2/utils/testing.py","lineNumber":392,"sourceCode":"\n    input = self\n    # if dim is None flatten\n    # By default, use the flattened input array, and return a flat output array\n    if sym_help._is_none(dim):\n        input = sym_help._reshape_helper(g, self, g.op(\"Constant\", value_t=torch.tensor([-1])))\n        dim = 0\n    else:\n        dim = sym_help._maybe_get_scalar(dim)\n\n    repeats_dim = sym_help._get_tensor_rank(repeats)\n    repeats_sizes = sym_help._get_tensor_sizes(repeats)\n    input_sizes = sym_help._get_tensor_sizes(input)\n    if repeats_dim is None:\n        raise RuntimeError(\n            \"Unsupported: ONNX export of repeat_interleave for unknown \" \"repeats rank.\"\n        )\n    if repeats_sizes is None:\n        raise RuntimeError(\n            \"Unsupported: ONNX export of repeat_interleave for unknown \" \"repeats size.\"\n        )\n    if input_sizes is None:\n        raise RuntimeError(\n            \"Unsupported: ONNX export of repeat_interleave for unknown \" \"input size.\"\n        )\n\n    input_sizes_temp = input_sizes.copy()\n    for idx, input_size in enumerate(input_sizes):\n        if input_size is None:\n            input_sizes[idx], input_sizes_temp[idx] = 0, -1\n\n    # Cases where repeats is an int or single value tensor\n    if repeats_dim == 0 or (repeats_dim == 1 and repeats_sizes[0] == 1):\n        if not sym_help._is_tensor(repeats):\n            repeats = g.op(\"Constant\", value_t=torch.LongTensor(repeats))\n        if input_sizes[dim] == 0:\n            return sym_help._onnx_opset_unsupported_detailed(","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/facebookresearch/detectron2/blob/a2f4a8771ab77e8411c26b27f24f9489a28a2453/detectron2/utils/testing.py#L374-L410","documentation":"Raised during ONNX export when torch.onnx.export encounters a repeat_interleave op whose `repeats` tensor has unknown (dynamic/None) shape in the traced graph. The detectron2 testing module monkey-patches PyTorch 1.11's opset9 symbolic for repeat_interleave, and it refuses to build ONNX nodes without concrete repeats sizes.","triggerScenarios":"Exporting a model to ONNX (torch.onnx.export / TrainerExport hooks) where repeat_interleave is called with a repeats tensor whose shape cannot be statically inferred (e.g. repeats computed from data-dependent ops, or dynamic batch axis dims).","commonSituations":"Exporting RetinaNet/mask heads or models using repeat_interleave with dynamic shapes; using dynamic_axes in torch.onnx.export so shape info is dropped; PyTorch version mismatch where sym_help._get_tensor_sizes returns None.","solutions":["Make the repeats tensor a constant with known shape (e.g. torch.as_tensor(repeats) with concrete values) before export","Avoid repeat_interleave in the exported graph: replace with expand + reshape or torch.repeat with static factors","Export with a fixed input shape (no dynamic_axes) so all sizes are known","Pin PyTorch to a version whose ONNX symbolic supports the pattern (this shim targets 1.11 opset9)"],"exampleFix":"// before\ny = x.repeat_interleave(repeats, dim=0)  # repeats shape unknown\n// after\nrepeats = torch.tensor([2, 2, 2])  # constant, statically known\ny = x.repeat_interleave(repeats, dim=0)","handlingStrategy":"validation","validationCode":"sizes = torch._C._jit_pass_onnx? None\n# practical check before export:\ndef repeats_shape_known(repeats):\n    return repeats is not None and isinstance(repeats, torch.Tensor) and repeats.dim() <= 1 and repeats.shape[0] is not None","typeGuard":"def is_exportable_repeats(r) -> bool:\n    return isinstance(r, torch.Tensor) and r.dim() <= 1 and all(s is not None for s in r.shape)","tryCatchPattern":"try:\n    torch.onnx.export(model, dummy, out)\nexcept RuntimeError as e:\n    if 'repeat_interleave' in str(e):\n        # replace with static repeat or fixed-shape export\n        ...","preventionTips":["Use constant 1-D repeats tensors in models destined for ONNX","Export with fixed input shapes (no dynamic_axes) when the graph contains repeat_interleave","Smoke-test export in CI for every model change"],"tags":["onnx","export","pytorch","repeat-interleave","dynamic-shape"],"backgroundTag":"onnx-export-unsupported-op","analyzedSha":"a2f4a8771ab77e8411c26b27f24f9489a28a2453","analyzedAt":"2026-08-27T12:08:21.260Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}