llvm / llvm/torch-mlir

`aten.view` fold crashes on element type mismatch instead of verifying

Open
#4,479 0 comments 0 reactions 1 assignee View on GitHub

@rkayaith is already working on this.

Since Mar 2, 2026.

Dominant language
C++
Stars
1.9k
Forks
736
Avg merge
5d 22h
Merged PRs (30d)
15

Description

aten.view accepts IR where the input and output element types differ (e.g., f32 input → bf16 output). This is semantically invalid — aten.view maps to the shape overload of Tensor.view (aten::view(Tensor, SymInt[])) which always preserves dtype. Dtype reinterpretation is a separate op (aten::view.dtype(Tensor, ScalarType)).

There's no verifier to catch the mismatch, so invalid IR reaches genericViewLikeFold which crashes with an assertion failure when trying to constant-fold it. Adding a verifier to reject element type mismatches would catch this class of bug at the point the invalid op is created, rather than crashing later during folding.

Reproducer
// view_type_mismatch.mlir
func.func @main() -> !torch.vtensor<[1,64,1,1],bf16> {
  %0 = torch.vtensor.literal(dense<1.0> : tensor<64xf32>) : !torch.vtensor<[64],f32>
  %1 = torch.constant.int 1
  %2 = torch.constant.int 64
  %3 = torch.prim.ListConstruct %1, %2, %1, %1 : (!torch.int, !torch.int, !torch.int, !torch.int) -> !torch.list<int>
  %4 = torch.aten.view %0, %3 : !torch.vtensor<[64],f32>, !torch.list<int> -> !torch.vtensor<[1,64,1,1],bf16>
  return %4 : !torch.vtensor<[1,64,1,1],bf16>
}

Expected: verification error on the aten.view op.

Actual:

$ torch-mlir-opt view_type_mismatch.mlir --canonicalize
torch-mlir-opt: .../mlir/lib/IR/BuiltinAttributes.cpp:973:
  Assertion `floatAttr.getType() == eltType && "expected float attribute type to equal element type"' failed.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.