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

Missing UInt support fo getScalarTypeForType #3720

Open
renxida opened this issue Sep 20, 2024 · 0 comments
Open

Missing UInt support fo getScalarTypeForType #3720

renxida opened this issue Sep 20, 2024 · 0 comments

Comments

@renxida
Copy link
Collaborator

renxida commented Sep 20, 2024

torch_upstream::ScalarType Torch::getScalarTypeForType(Type type) {
if (isa<Float32Type>(type))
return torch_upstream::ScalarType::Float;
if (isa<Float64Type>(type))
return torch_upstream::ScalarType::Double;
if (type.isSignedInteger(64))
return torch_upstream::ScalarType::Long;
if (type.isSignedInteger(32))
return torch_upstream::ScalarType::Int;
if (type.isSignedInteger(16))
return torch_upstream::ScalarType::Short;
if (type.isSignlessInteger(1))
return torch_upstream::ScalarType::Bool;
if (type.isBF16())
return torch_upstream::ScalarType::BFloat16;
if (type.isF16())
return torch_upstream::ScalarType::Half;
if (type.isUnsignedInteger(8))
return torch_upstream::ScalarType::Byte;
if (type.isSignedInteger(8))
return torch_upstream::ScalarType::Char;
if (isa<QUInt8Type>(type))
return torch_upstream::ScalarType::QUInt8;
if (isa<QInt8Type>(type))
return torch_upstream::ScalarType::QInt8;
if (isa<QInt16Type>(type))
return torch_upstream::ScalarType::QInt16;
if (isa<QInt32Type>(type))
return torch_upstream::ScalarType::QInt32;
if (isa<ComplexType>(type)) {
mlir::Type complexElemType = cast<ComplexType>(type).getElementType();
if (complexElemType.isF16())
return torch_upstream::ScalarType::ComplexHalf;
if (complexElemType.isF32())
return torch_upstream::ScalarType::ComplexFloat;
if (complexElemType.isF64())
return torch_upstream::ScalarType::ComplexDouble;
}
if (isa<Float8E5M2Type>(type))
return torch_upstream::ScalarType::Float8_e5m2;
if (isa<Float8E4M3FNType>(type))
return torch_upstream::ScalarType::Float8_e4m3fn;
if (isa<Float8E5M2FNUZType>(type))
return torch_upstream::ScalarType::Float8_e5m2fnuz;
if (isa<Float8E4M3FNUZType>(type))
return torch_upstream::ScalarType::Float8_e4m3fnuz;
llvm::report_fatal_error("unhandled type for getScalarTypeForType");
}
Type Torch::getTypeForTorchType(
MLIRContext *context, Type type,
mlir::IntegerType::SignednessSemantics signedness) {
if (isa<Torch::IntType>(type))
return IntegerType::get(context, 64, signedness);
if (isa<Torch::FloatType>(type))

As seen here, we don't have support for getScalarTypeForType. Also, the error message not very informative: it just says unhandled type for getScalarTypeForType without specifying what the unsupported type is.

Implementing this also requires modifying this ScalarType enum in TorchUpstream.h:

#define AT_FORALL_SCALAR_TYPES_WITH_COMPLEX_AND_QINTS(_) \
_(uint8_t, Byte) /* 0 */ \
_(int8_t, Char) /* 1 */ \
_(int16_t, Short) /* 2 */ \
_(int, Int) /* 3 */ \
_(int64_t, Long) /* 4 */ \
_(at::Half, Half) /* 5 */ \
_(float, Float) /* 6 */ \
_(double, Double) /* 7 */ \
_(c10::complex<c10::Half>, ComplexHalf) /* 8 */ \
_(c10::complex<float>, ComplexFloat) /* 9 */ \

which is not up to date compared to the ScalarType.h in the pytorch/pytorch repo:
https://github.com/pytorch/pytorch/blob/main/c10/core/ScalarType.h#L84-L93

Related issue where this prevents supporting certain onnx dtypes: #3255

renxida added a commit that referenced this issue Sep 25, 2024
Instead of 
`Unhandled type in getScalarTypeForType`

You now get

Unhandled type in getScalarTypeForType: (type name)
Type properties:
  Is integer: yes
  Bit width: 
...


The root cause is #3720, at
least for unsigned integer issues.
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

1 participant