Fix error when attempting to read elided onnx constants (#3398)

Co-authored-by: zjgarvey <zjgarvey@gmail.com>
pull/3386/head
Xida Ren (Cedar) 2024-05-29 16:56:23 -07:00 committed by GitHub
parent a5d3b546f8
commit 23d2d66a59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 3 deletions

View File

@ -909,16 +909,25 @@ void mlir::torch::onnx_c::populateDefaultDomainAtoF(
auto ty = cast<ShapedType>(attr.getType());
ElementsAttr denseAttr;
auto ptr = attr.getRawHandle().getBlob()->getData();
auto ptr = attr.getRawHandle().getBlob();
if (!ptr) {
denseAttr = DenseResourceElementsAttr::get(
ty, "__onnx_constant_not_found_possibly_due_to_being_elided__",
AsmResourceBlob());
rewriter.replaceOpWithNewOp<Torch::ValueTensorLiteralOp>(
binder.op, resultType, denseAttr);
return success();
}
auto data = ptr->getData();
if (cast<ShapedType>(attr.getType()).getElementType().isInteger(1)) {
llvm::SmallVector<APInt> newContents;
for (auto val : ptr) {
for (auto val : data) {
APInt apval(1, val);
newContents.push_back(apval);
}
denseAttr = DenseElementsAttr::get(ty, newContents);
} else {
denseAttr = DenseElementsAttr::getFromRawBuffer(ty, ptr);
denseAttr = DenseElementsAttr::getFromRawBuffer(ty, data);
}
rewriter.replaceOpWithNewOp<Torch::ValueTensorLiteralOp>(