Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch.constant.int with large negative values causes error #3621

Open
zjgarvey opened this issue Aug 9, 2024 · 2 comments
Open

torch.constant.int with large negative values causes error #3621

zjgarvey opened this issue Aug 9, 2024 · 2 comments

Comments

@zjgarvey
Copy link
Collaborator

zjgarvey commented Aug 9, 2024

Reproduction instructions:

Save this reproducer to repro.mlir:

module {
    func.func @intfail() -> !torch.int {
        %0 = torch.vtensor.literal(dense<-9223372036854775807> : tensor<1xsi64>) : !torch.vtensor<[1],si64>
        %1 = torch.aten.item %0 : !torch.vtensor<[1],si64> -> !torch.int
        return %1 : !torch.int
    }
}

run

torch-mlir-opt repro.mlir --canonicalize -o repro2.mlir

repro2.mlir should contain

module {
  func.func @intfail() -> !torch.int {
    %int-9223372036854775807 = torch.constant.int -9223372036854775807
    return %int-9223372036854775807 : !torch.int
  }
}

If you try

torch-mlir-opt repro2.mlir --convert-torch-to-arith

It returns

repro2.mlir:3:51: error: custom op 'torch.constant.int' integer value too large
    %int-9223372036854775807 = torch.constant.int -9223372036854775807

However, running from the original repro.mlir:

torch-mlir-opt repro.mlir --canonicalize --convert-torch-to-arith

generates valid IR:

module {
  func.func @intfail() -> !torch.int {
    %c-9223372036854775807_i64 = arith.constant -9223372036854775807 : i64
    %0 = torch_c.from_i64 %c-9223372036854775807_i64
    return %0 : !torch.int
  }
}

It seems like an error with parsing the constant int op? I'm not sure what is going on here.

@dan-garvey
Copy link
Collaborator

if you --print-ir-after-all do you get repro2 as an intermediate?

@zjgarvey
Copy link
Collaborator Author

if you --print-ir-after-all do you get repro2 as an intermediate?

Yeah:

// -----// IR Dump Before Canonicalizer (canonicalize) //----- //
module {
  func.func @intfail() -> !torch.int {
    %0 = torch.vtensor.literal(dense<-9223372036854775807> : tensor<1xsi64>) : !torch.vtensor<[1],si64>
    %1 = torch.aten.item %0 : !torch.vtensor<[1],si64> -> !torch.int
    return %1 : !torch.int
  }
}


// -----// IR Dump Before ConvertTorchToArith (convert-torch-to-arith) //----- //
func.func @intfail() -> !torch.int {
  %int-9223372036854775807 = torch.constant.int -9223372036854775807
  return %int-9223372036854775807 : !torch.int
}

module {
  func.func @intfail() -> !torch.int {
    %c-9223372036854775807_i64 = arith.constant -9223372036854775807 : i64
    %0 = torch_c.from_i64 %c-9223372036854775807_i64
    return %0 : !torch.int
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants