Skip to content

[Issue]: Model compilation fails with more than one dynamic dimension specified #4844

@mferencevic

Description

@mferencevic

Problem description

MIGraphX fails to compile even simple models when more than one dynamic dimension is specified.

The compilation usually fails with this error message:

RuntimeError: src/shape.cpp:391: lens: SHAPE: lens() called on a dynamic shape

Also, the MIGRAPHX_ENABLE_FULL_DYNAMIC environment variable doesn't help whether or not it's set to 1.

Steps to reproduce

import math
import migraphx
import torch

EMBEDDING_COUNT = 32
EMBEDDING_DIM = 16
BATCH_SIZE = 4

torch.inference_mode(True)
torch.cuda.set_device("cuda:0")

model = torch.nn.Embedding(EMBEDDING_COUNT, EMBEDDING_DIM)
model.eval()
input_batch = torch.arange(math.ceil(EMBEDDING_COUNT / 2)).repeat(BATCH_SIZE, 1).contiguous()

torch.onnx.export(
    model,
    (input_batch,),
    "model.onnx",
    external_data=False,
    dynamo=True,
    dynamic_shapes=[
        {0: torch.export.Dim.DYNAMIC, 1: torch.export.Dim.DYNAMIC},
    ],
)

migraphx_model = migraphx.parse_onnx("model.onnx", map_dyn_input_dims={
    "input": [
        migraphx.shape.dynamic_dimension(1, BATCH_SIZE, {BATCH_SIZE}),
        migraphx.shape.dynamic_dimension(1, 64, {1}),
    ],
})
migraphx_model.compile(migraphx.get_target("gpu"), offload_copy=False)

We want to note that we've observed the same issue with larger models, but we've created this reproducer script with a single node for simpler analysis.

Environment

OS: Debian GNU/Linux 12 (bookworm)
CPU: AMD Ryzen 9 9950X
GPU: AMD Radeon AI PRO R9700
ROCm version: 7.2.1
MIGraphX version: 2.16.0.dev+20250912-17-406-gb91f1c0c0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions