Skip to content

[CPU][DT] Failed to compile toy_llama.mlir using data-tiling fusion #21197

Closed

Description

@hanhanW

Download the model: https://gist.github.com/hanhanW/2db5e6a8b949493335c948101632b8ad

To repro:

iree-compile \
  --iree-hal-target-device=local \
  --iree-hal-local-target-device-backends=llvm-cpu \
  --iree-llvmcpu-target-cpu=znver4 \
  ~/toy_llama.mlir -o /tmp/z.vmfb \
  --iree-opt-data-tiling=false \
  --iree-dispatch-creation-experimental-data-tiling=true

Error:

.../toy_llama.mlir:557:14: error: 'tensor.expand_shape' op expected number of static shape dims to be equal to the output rank (4) but found 0 inputs instead
    %190:2 = torch.operator "torch.aten._scaled_dot_product_flash_attention_for_cpu"(%187, %188, %189, %float0.000000e00, %true_195, %none_196, %none_197) : (!torch.vtensor<[1,8,?,32],f16>, !torch.vtensor<[1,8,?,32],f16>, !torch.vtensor<[1,8,?,32],f16>, !torch.float, !torch.bool, !torch.none, !torch.none) -> (!torch.vtensor<[1,8,?,32],f16>, !torch.vtensor<[1,8,?],f32>)
             ^
.../toy_llama.mlir:557:14: note: see current operation: %77 = "tensor.expand_shape"(%75) <{reassociation = [[0, 1, 2, 3]], static_output_shape = array<i64>}> : (tensor<?xf16>) -> tensor<4x2x?x?xf16>

Activity

  1. self-assigned this
    on Jun 26, 2025
  2. added
    codegen
    on Jun 26, 2025
  3. hanhanW commented on Jun 26, 2025

    @hanhanW
    ContributorAuthor

    It seems to be a bug in one of the canonicalization patterns:

    IR dump after CollapseDimension pass: https://gist.github.com/hanhanW/9d6bb7f168f2ef7b2fa51e34d098f203

    To repro: iree-opt --canonicalize ~/z2.mlir

    Error:

    .../z2.mlir:635:19: error: 'tensor.expand_shape' op expected number of static shape dims to be equal to the output rank (4) but found 0 inputs instead
      %collapsed_12 = tensor.collapse_shape %expanded_9 [[0], [1], [2], [3, 4]] : tensor<4x2x?x?x32xf16> into tensor<4x2x?x?xf16>
                      ^
    .../z2.mlir:635:19: note: see current operation: %90 = "tensor.expand_shape"(%88) <{reassociation = [[0, 1, 2, 3]], static_output_shape = array<i64>}> : (tensor<?xf16>) -> tensor<4x2x?x?xf16>
  4. hanhanW commented on Jun 26, 2025

    @hanhanW
    ContributorAuthor

    There may be other issues in the later phase, the issue is for tracking the compilation issue for toy_llama on CPU data-tiling fusion path.

  5. changed the title [-][CPU][DT] Failed to compile toy_llama.mlir in CPU data-tiling fusion path[/-] [+][CPU][DT] Failed to compile toy_llama.mlir using data-tiling fusion[/+] on Jun 26, 2025
  6. hanhanW commented on Jun 26, 2025

    @hanhanW
    ContributorAuthor

    Smaller repro:

    func.func @foo(%arg0: tensor<?xf16>, %arg1: index, %arg2: index) -> tensor<4x2x?x?xf16> {
      %expanded = tensor.expand_shape %arg0 [[0, 1, 2, 3, 4]] output_shape [4, 2, %arg1, %arg2, 32] : tensor<?xf16> into tensor<4x2x?x?x32xf16>
      %collapsed = tensor.collapse_shape %expanded [[0], [1], [2], [3, 4]] : tensor<4x2x?x?x32xf16> into tensor<4x2x?x?xf16>
      return %collapsed : tensor<4x2x?x?xf16>
    }
  7. hanhanW commented on Jun 27, 2025

    @hanhanW
    ContributorAuthor

    llvm/llvm-project#145995 fixes the expand_shape issue, I'll try to prefetch if there are other new issues or not.

  8. hanhanW commented on Jun 27, 2025

    @hanhanW
    ContributorAuthor

    Here are all the dispatches: https://gist.github.com/hanhanW/f1fa1d98d5b6827460a8d5907ae33d0c

    Some of them are not compilable, e.g., configured_module_prefill_bs1$async_dispatch_17.mlir. For this case, it may be related to #20786, where the generic op consumer is not fused. So it creates a large temp buffer to hold the data and pass it to the generic op.

    To repro: iree-compile --compile-from=executable-sources --compile-to=executable-targets configured_module_prefill_bs1$async_dispatch_17.mlir.mlir

  9. hanhanW commented on Jul 9, 2025

    @hanhanW
    ContributorAuthor

    Confirmed that it is fixed by #21275 + #21298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

codegen

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions