torch-mlir
torch-mlir copied to clipboard
can we support float16(half) datatype?
my model is float16 model which failed to transform in torch-mlir https://github.com/llvm/torch-mlir/blob/32159c4e545359d4ad9e3b492c07e07528f5b47e/python/torch_mlir/dialects/torch/importer/jit_ir/csrc/torch_to_mlir_utils.cpp#L327
case ScalarType::Int: case ScalarType::Long: case ScalarType::Float: case ScalarType::Double: case ScalarType::Bool: case ScalarType::QInt8: case ScalarType::BFloat16: default: throwUnsupportedTensorError(); }
can we support fp16?
This is probably easy given the Half is a native APFloat type in LLVM. You probably want to look at @ashay 's commit adding BF16 here: https://github.com/llvm/torch-mlir/pull/761
maybe not.
below are interface exposed from MLIR, as you can see, it doesnot support Half :( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBoolGet( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt8Get( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt8Get( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt16Get( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt16Get( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt32Get( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt32Get( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt64Get( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt64Get( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrFloatGet( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrDoubleGet( MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBFloat16Get(
@FullZing Yeah, we were in a similar situation for BFloat16, so I added the mlirDenseElementsAttrBFloat16Get()
to the MLIR C API in https://reviews.llvm.org/D123981. Perhaps you could add a similar function upstream for Half.
+1, this should be quite easy to add by repeating https://reviews.llvm.org/D123981 + https://github.com/llvm/torch-mlir/pull/761 but for float16
@FullZing -- can you do that?
@ashay @silvasean I have added a patch: https://reviews.llvm.org/D130069; please review for me.
@fortianyou That patch looks good to me, but could you add "ashay-github" as a reviewer? I botched the signup process on Phabricator, which is why it says that the email address for the account "ashay" was not verified. Sorry about the hassle!
We added support for this in #1169