mirror of https://github.com/llvm/torch-mlir
Fix error when attempting to read elided onnx constants (#3398)
Co-authored-by: zjgarvey <zjgarvey@gmail.com>pull/3386/head
parent
a5d3b546f8
commit
23d2d66a59
|
@ -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>(
|
||||
|
|
Loading…
Reference in New Issue