ROCm / ROCm/AMDMIGraphX

[Issue]: Compilation of swin_transformer fails when MIGRAPHX_MLIR_USE_SPECIFIC_OPS=attention is set,

Open
#4,908 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
333
Forks
150
Avg merge
4d 19h
Merged PRs (30d)
54

Description

Problem Description

Compilation of swin_transformer fails when MIGRAPHX_MLIR_USE_SPECIFIC_OPS=attention is set, but succeeds when the flag is not set.

[O] PYTHONPATH=/opt/rocm/lib:$PYTHONPATH python test.py
[X] PYTHONPATH=/opt/rocm/lib:$PYTHONPATH MIGRAPHX_MLIR_USE_SPECIFIC_OPS=attention python test.py

The error message is as follows: run_high_level_pipeline: Invalid MLIR created: Error: Cannot trace first gemm index for linalg.generic op
Image

Tested with the following system configuration on MI250:

Operating System

Ubuntu 24.04.3 LTS

CPU

AMD EPYC 7763 64-Core Processor

GPU

AMD Instinct MI250

Other

No response

ROCm Version

ROCm 6.0.0

Steps to Reproduce

The test code:

import argparse
import torch
import torchvision

def compile_mgx(model):
    import torch_migraphx
    return torch.compile(model, backend="migraphx", options={"deallocate": True, "fp16": True}, dynamic=False)

if __name__ == "__main__":
    weights = torchvision.models.Swin_T_Weights.DEFAULT
    model = torchvision.models.swin_t(weights=weights)
    model.to("cuda").eval()
    model = compile_mgx(model)

    # Inference
    with torch.no_grad():
        tensor = torch.rand(1, 3, 224, 224).to("cuda")  # fake input
        output = model(tensor)

    print("finish")

Run following command:

# [O] MIGraphX compile pass
PYTHONPATH=/opt/rocm/lib:$PYTHONPATH python test.py

# [X] MIGraphX compile fail
MIGRAPHX_MLIR_USE_SPECIFIC_OPS=attention  PYTHONPATH=/opt/rocm/lib:$PYTHONPATH python test.py
(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided test.py reproduction using torchvision's swin_t model, first without the environment variable and then with MIGRAPHX_MLIR_USE_SPECIFIC_OPS=attention. Compare the compilation failure and the reported linalg.generic tracing error; done means the Swin Transformer compiles and completes inference with the flag enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python, pytorch
Domain
backend, compilers, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.