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

Fold slice+copy_ into index_put_ #1901

Merged
merged 1 commit into from
Mar 10, 2023
Merged

Conversation

gpetters94
Copy link
Collaborator

This folds patterns of fold and then copy_ into index_put_, since the initial pattern doesn't work with MaximizeValueSemantics.

@AmosLewis
Copy link
Collaborator

AmosLewis commented Feb 28, 2023

The t5small_torchscript_0227_transformers4.26.0.mlir : https://gist.github.com/AmosLewis/20895fa06e8b61ce83e9a2b9c2ee8ca6

➜  /tmp torch-mlir-opt -pass-pipeline='builtin.module(torchscript-module-to-torch-backend-pipeline{backend-legal-ops=torch.aten.flatten.using_ints,torch.aten.native_layer_norm,torch.aten.linear})' /tmp/t5small_torchscript_0227_transformers4.26.0.mlir 

LLVM ERROR: SmallVector unable to grow. Requested capacity (4294967296) is larger than maximum value for size type (4294967295)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt -pass-pipeline=builtin.module(torchscript-module-to-torch-backend-pipeline{backend-legal-ops=torch.aten.flatten.using_ints,torch.aten.native_layer_norm,torch.aten.linear}) /tmp/t5small_torchscript_0227_transformers4.26.0.mlir
 #0 0x000055ebe8cc8e2d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:567:11
 #1 0x000055ebe8cc92bb PrintStackTraceSignalHandler(void*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:641:1
 #2 0x000055ebe8cc7666 llvm::sys::RunSignalHandlers() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Signals.cpp:104:5
 #3 0x000055ebe8cc99a5 SignalHandler(int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:412:1
 #4 0x00007f397e242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007f397e296a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f397e296a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x00007f397e296a7c pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x00007f397e242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007f397e2287f3 abort ./stdlib/abort.c:81:7
#10 0x000055ebe8bc1f14 llvm::report_fatal_error(llvm::Twine const&, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/ErrorHandling.cpp:125:5
#11 0x000055ebe8c30fc3 /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/SmallVector.cpp:70:3
#12 0x000055ebe8c30e1a unsigned long getNewCapacity<unsigned int>(unsigned long, unsigned long, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/SmallVector.cpp:102:7
#13 0x000055ebe8c311f5 llvm::SmallVectorBase<unsigned int>::grow_pod(void*, unsigned long, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/SmallVector.cpp:140:24
#14 0x000055ebe3e5ac95 llvm::SmallVectorTemplateCommon<long, void>::grow_pod(unsigned long, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:142:3
#15 0x000055ebe3e5ac52 llvm::SmallVectorTemplateBase<long, true>::grow(unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:529:71
#16 0x000055ebe3e5abec long const* llvm::SmallVectorTemplateCommon<long, void>::reserveForParamAndGetAddressImpl<llvm::SmallVectorTemplateBase<long, true>>(llvm::SmallVectorTemplateBase<long, true>*, long const&, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:247:12
#17 0x000055ebe3e5ab75 llvm::SmallVectorTemplateBase<long, true>::reserveForParamAndGetAddress(long&, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:540:5
#18 0x000055ebe3e469a6 llvm::SmallVectorTemplateBase<long, true>::push_back(long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:566:23
#19 0x000055ebe3e38123 mlir::torch::Torch::AtenSliceTensorOp::getCanonicalizationPatterns(mlir::RewritePatternSet&, mlir::MLIRContext*)::$_44::operator()(mlir::torch::Torch::AtenSliceTensorOp, mlir::PatternRewriter&) const /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/IR/TorchOps.cpp:2189:38
#20 0x000055ebe3e37d0d mlir::torch::Torch::AtenSliceTensorOp::getCanonicalizationPatterns(mlir::RewritePatternSet&, mlir::MLIRContext*)::$_44::__invoke(mlir::torch::Torch::AtenSliceTensorOp, mlir::PatternRewriter&) /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/IR/TorchOps.cpp:2160:17
#21 0x000055ebe3e7620e mlir::RewritePatternSet& mlir::RewritePatternSet::add<mlir::torch::Torch::AtenSliceTensorOp>(mlir::LogicalResult (*)(mlir::torch::Torch::AtenSliceTensorOp, mlir::PatternRewriter&), mlir::PatternBenefit, llvm::ArrayRef<llvm::StringRef>)::FnPattern::matchAndRewrite(mlir::torch::Torch::AtenSliceTensorOp, mlir::PatternRewriter&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/IR/PatternMatch.h:1664:16
#22 0x000055ebe3e7616b mlir::detail::OpOrInterfaceRewritePatternBase<mlir::torch::Torch::AtenSliceTensorOp>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/IR/PatternMatch.h:330:12
#23 0x000055ebe88a7552 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:200:25
#24 0x000055ebe884c211 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:247:19
#25 0x000055ebe884a38d (anonymous namespace)::RegionPatternRewriteDriver::simplify() && /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:461:15
#26 0x000055ebe884a0af mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:490:47
#27 0x000055ebe41663b3 mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:112:15
#28 0x000055ebe87b43b5 (anonymous namespace)::Canonicalizer::runOnOperation() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Canonicalizer.cpp:61:9
#29 0x000055ebe88b210a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:471:21
#30 0x000055ebe88b26f4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:534:16
#31 0x000055ebe88b68d1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_6::operator()(mlir::OpPassManager&, mlir::Operation*) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:456:12
#32 0x000055ebe88b6645 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (mlir::OpPassManager&, mlir::Operation*)>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_6>(long, mlir::OpPassManager&, mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#33 0x000055ebe41ed609 llvm::function_ref<mlir::LogicalResult (mlir::OpPassManager&, mlir::Operation*)>::operator()(mlir::OpPassManager&, mlir::Operation*) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#34 0x000055ebe41ea615 mlir::Pass::runPipeline(mlir::OpPassManager&, mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/Pass/Pass.h:196:12
#35 0x000055ebe87c71ad (anonymous namespace)::InlinerPass::optimizeCallable(mlir::CallGraphNode*, llvm::StringMap<mlir::OpPassManager, llvm::MallocAllocator>&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:796:10
#36 0x000055ebe87c6f5c (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0::operator()(mlir::CallGraphNode*) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:773:28
#37 0x000055ebe87c6cda mlir::LogicalResult mlir::failableParallelForEach<mlir::CallGraphNode**, (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0>(mlir::MLIRContext*, mlir::CallGraphNode**, mlir::CallGraphNode**, (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0&&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/include/mlir/IR/Threading.h:46:18
#38 0x000055ebe87c6c36 mlir::LogicalResult mlir::failableParallelForEach<llvm::MutableArrayRef<mlir::CallGraphNode*>&, (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0>(mlir::MLIRContext*, llvm::MutableArrayRef<mlir::CallGraphNode*>&, (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0&&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/include/mlir/IR/Threading.h:92:10
#39 0x000055ebe87c6bd8 (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:762:10
#40 0x000055ebe87c5d21 (anonymous namespace)::InlinerPass::optimizeSCC(mlir::CallGraph&, (anonymous namespace)::CGUseList&, (anonymous namespace)::CallGraphSCC&, mlir::MLIRContext*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:729:14
#41 0x000055ebe87c5b1b (anonymous namespace)::InlinerPass::inlineSCC((anonymous namespace)::Inliner&, (anonymous namespace)::CGUseList&, (anonymous namespace)::CallGraphSCC&, mlir::MLIRContext*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:695:16
#42 0x000055ebe87c5abf (anonymous namespace)::InlinerPass::runOnOperation()::$_5::operator()((anonymous namespace)::CallGraphSCC&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:678:12
#43 0x000055ebe87c5a7d mlir::LogicalResult llvm::function_ref<mlir::LogicalResult ((anonymous namespace)::CallGraphSCC&)>::callback_fn<(anonymous namespace)::InlinerPass::runOnOperation()::$_5>(long, (anonymous namespace)::CallGraphSCC&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#44 0x000055ebe87c5a31 llvm::function_ref<mlir::LogicalResult ((anonymous namespace)::CallGraphSCC&)>::operator()((anonymous namespace)::CallGraphSCC&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#45 0x000055ebe87c34ea runTransformOnCGSCCs(mlir::CallGraph const&, llvm::function_ref<mlir::LogicalResult ((anonymous namespace)::CallGraphSCC&)>) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:303:16
#46 0x000055ebe87c2a66 (anonymous namespace)::InlinerPass::runOnOperation() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:677:26
#47 0x000055ebe88b210a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:471:21
#48 0x000055ebe88b26f4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:534:16
#49 0x000055ebe88b4069 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:843:10
#50 0x000055ebe88b3f95 mlir::PassManager::run(mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:823:60
#51 0x000055ebe39a97bf performActions(llvm::raw_ostream&, bool, bool, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:90:17
#52 0x000055ebe39a9457 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, bool, bool, bool, bool, bool, bool, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, llvm::ThreadPool*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:138:12
#53 0x000055ebe39a9222 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:180:12
#54 0x000055ebe39a9132 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#55 0x000055ebe8b6bfde llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#56 0x000055ebe8b6b5fd mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Support/ToolUtilities.cpp:28:12
#57 0x000055ebe39a818b mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:185:10
#58 0x000055ebe39a831f mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:208:10
#59 0x000055ebe39a8f59 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:305:14
#60 0x000055ebe395b6b7 main /home/chi/src/ubuntu20/shark/torch-mlir/tools/torch-mlir-opt/torch-mlir-opt.cpp:26:7
#61 0x00007f397e229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#62 0x00007f397e229e40 call_init ./csu/../csu/libc-start.c:128:20
#63 0x00007f397e229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#64 0x000055ebe395b575 _start (/home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt+0x2d57575)
[1]    42049 IOT instruction (core dumped)  /home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt  

lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
@gpetters94
Copy link
Collaborator Author

The t5small_torchscript_0227_transformers4.26.0.mlir : https://gist.github.com/AmosLewis/20895fa06e8b61ce83e9a2b9c2ee8ca6

➜  /tmp torch-mlir-opt -pass-pipeline='builtin.module(torchscript-module-to-torch-backend-pipeline{backend-legal-ops=torch.aten.flatten.using_ints,torch.aten.native_layer_norm,torch.aten.linear})' /tmp/t5small_torchscript_0227_transformers4.26.0.mlir 

LLVM ERROR: SmallVector unable to grow. Requested capacity (4294967296) is larger than maximum value for size type (4294967295)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt -pass-pipeline=builtin.module(torchscript-module-to-torch-backend-pipeline{backend-legal-ops=torch.aten.flatten.using_ints,torch.aten.native_layer_norm,torch.aten.linear}) /tmp/t5small_torchscript_0227_transformers4.26.0.mlir
 #0 0x000055ebe8cc8e2d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:567:11
 #1 0x000055ebe8cc92bb PrintStackTraceSignalHandler(void*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:641:1
 #2 0x000055ebe8cc7666 llvm::sys::RunSignalHandlers() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Signals.cpp:104:5
 #3 0x000055ebe8cc99a5 SignalHandler(int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:412:1
 #4 0x00007f397e242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007f397e296a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f397e296a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x00007f397e296a7c pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x00007f397e242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007f397e2287f3 abort ./stdlib/abort.c:81:7
#10 0x000055ebe8bc1f14 llvm::report_fatal_error(llvm::Twine const&, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/ErrorHandling.cpp:125:5
#11 0x000055ebe8c30fc3 /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/SmallVector.cpp:70:3
#12 0x000055ebe8c30e1a unsigned long getNewCapacity<unsigned int>(unsigned long, unsigned long, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/SmallVector.cpp:102:7
#13 0x000055ebe8c311f5 llvm::SmallVectorBase<unsigned int>::grow_pod(void*, unsigned long, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/SmallVector.cpp:140:24
#14 0x000055ebe3e5ac95 llvm::SmallVectorTemplateCommon<long, void>::grow_pod(unsigned long, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:142:3
#15 0x000055ebe3e5ac52 llvm::SmallVectorTemplateBase<long, true>::grow(unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:529:71
#16 0x000055ebe3e5abec long const* llvm::SmallVectorTemplateCommon<long, void>::reserveForParamAndGetAddressImpl<llvm::SmallVectorTemplateBase<long, true>>(llvm::SmallVectorTemplateBase<long, true>*, long const&, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:247:12
#17 0x000055ebe3e5ab75 llvm::SmallVectorTemplateBase<long, true>::reserveForParamAndGetAddress(long&, unsigned long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:540:5
#18 0x000055ebe3e469a6 llvm::SmallVectorTemplateBase<long, true>::push_back(long) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/SmallVector.h:566:23
#19 0x000055ebe3e38123 mlir::torch::Torch::AtenSliceTensorOp::getCanonicalizationPatterns(mlir::RewritePatternSet&, mlir::MLIRContext*)::$_44::operator()(mlir::torch::Torch::AtenSliceTensorOp, mlir::PatternRewriter&) const /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/IR/TorchOps.cpp:2189:38
#20 0x000055ebe3e37d0d mlir::torch::Torch::AtenSliceTensorOp::getCanonicalizationPatterns(mlir::RewritePatternSet&, mlir::MLIRContext*)::$_44::__invoke(mlir::torch::Torch::AtenSliceTensorOp, mlir::PatternRewriter&) /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/IR/TorchOps.cpp:2160:17
#21 0x000055ebe3e7620e mlir::RewritePatternSet& mlir::RewritePatternSet::add<mlir::torch::Torch::AtenSliceTensorOp>(mlir::LogicalResult (*)(mlir::torch::Torch::AtenSliceTensorOp, mlir::PatternRewriter&), mlir::PatternBenefit, llvm::ArrayRef<llvm::StringRef>)::FnPattern::matchAndRewrite(mlir::torch::Torch::AtenSliceTensorOp, mlir::PatternRewriter&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/IR/PatternMatch.h:1664:16
#22 0x000055ebe3e7616b mlir::detail::OpOrInterfaceRewritePatternBase<mlir::torch::Torch::AtenSliceTensorOp>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/IR/PatternMatch.h:330:12
#23 0x000055ebe88a7552 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:200:25
#24 0x000055ebe884c211 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:247:19
#25 0x000055ebe884a38d (anonymous namespace)::RegionPatternRewriteDriver::simplify() && /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:461:15
#26 0x000055ebe884a0af mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:490:47
#27 0x000055ebe41663b3 mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:112:15
#28 0x000055ebe87b43b5 (anonymous namespace)::Canonicalizer::runOnOperation() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Canonicalizer.cpp:61:9
#29 0x000055ebe88b210a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:471:21
#30 0x000055ebe88b26f4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:534:16
#31 0x000055ebe88b68d1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_6::operator()(mlir::OpPassManager&, mlir::Operation*) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:456:12
#32 0x000055ebe88b6645 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (mlir::OpPassManager&, mlir::Operation*)>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_6>(long, mlir::OpPassManager&, mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#33 0x000055ebe41ed609 llvm::function_ref<mlir::LogicalResult (mlir::OpPassManager&, mlir::Operation*)>::operator()(mlir::OpPassManager&, mlir::Operation*) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#34 0x000055ebe41ea615 mlir::Pass::runPipeline(mlir::OpPassManager&, mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/Pass/Pass.h:196:12
#35 0x000055ebe87c71ad (anonymous namespace)::InlinerPass::optimizeCallable(mlir::CallGraphNode*, llvm::StringMap<mlir::OpPassManager, llvm::MallocAllocator>&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:796:10
#36 0x000055ebe87c6f5c (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0::operator()(mlir::CallGraphNode*) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:773:28
#37 0x000055ebe87c6cda mlir::LogicalResult mlir::failableParallelForEach<mlir::CallGraphNode**, (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0>(mlir::MLIRContext*, mlir::CallGraphNode**, mlir::CallGraphNode**, (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0&&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/include/mlir/IR/Threading.h:46:18
#38 0x000055ebe87c6c36 mlir::LogicalResult mlir::failableParallelForEach<llvm::MutableArrayRef<mlir::CallGraphNode*>&, (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0>(mlir::MLIRContext*, llvm::MutableArrayRef<mlir::CallGraphNode*>&, (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*)::$_0&&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/include/mlir/IR/Threading.h:92:10
#39 0x000055ebe87c6bd8 (anonymous namespace)::InlinerPass::optimizeSCCAsync(llvm::MutableArrayRef<mlir::CallGraphNode*>, mlir::MLIRContext*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:762:10
#40 0x000055ebe87c5d21 (anonymous namespace)::InlinerPass::optimizeSCC(mlir::CallGraph&, (anonymous namespace)::CGUseList&, (anonymous namespace)::CallGraphSCC&, mlir::MLIRContext*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:729:14
#41 0x000055ebe87c5b1b (anonymous namespace)::InlinerPass::inlineSCC((anonymous namespace)::Inliner&, (anonymous namespace)::CGUseList&, (anonymous namespace)::CallGraphSCC&, mlir::MLIRContext*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:695:16
#42 0x000055ebe87c5abf (anonymous namespace)::InlinerPass::runOnOperation()::$_5::operator()((anonymous namespace)::CallGraphSCC&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:678:12
#43 0x000055ebe87c5a7d mlir::LogicalResult llvm::function_ref<mlir::LogicalResult ((anonymous namespace)::CallGraphSCC&)>::callback_fn<(anonymous namespace)::InlinerPass::runOnOperation()::$_5>(long, (anonymous namespace)::CallGraphSCC&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#44 0x000055ebe87c5a31 llvm::function_ref<mlir::LogicalResult ((anonymous namespace)::CallGraphSCC&)>::operator()((anonymous namespace)::CallGraphSCC&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#45 0x000055ebe87c34ea runTransformOnCGSCCs(mlir::CallGraph const&, llvm::function_ref<mlir::LogicalResult ((anonymous namespace)::CallGraphSCC&)>) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:303:16
#46 0x000055ebe87c2a66 (anonymous namespace)::InlinerPass::runOnOperation() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Inliner.cpp:677:26
#47 0x000055ebe88b210a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:471:21
#48 0x000055ebe88b26f4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:534:16
#49 0x000055ebe88b4069 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:843:10
#50 0x000055ebe88b3f95 mlir::PassManager::run(mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:823:60
#51 0x000055ebe39a97bf performActions(llvm::raw_ostream&, bool, bool, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:90:17
#52 0x000055ebe39a9457 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, bool, bool, bool, bool, bool, bool, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, llvm::ThreadPool*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:138:12
#53 0x000055ebe39a9222 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:180:12
#54 0x000055ebe39a9132 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#55 0x000055ebe8b6bfde llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#56 0x000055ebe8b6b5fd mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Support/ToolUtilities.cpp:28:12
#57 0x000055ebe39a818b mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:185:10
#58 0x000055ebe39a831f mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:208:10
#59 0x000055ebe39a8f59 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:305:14
#60 0x000055ebe395b6b7 main /home/chi/src/ubuntu20/shark/torch-mlir/tools/torch-mlir-opt/torch-mlir-opt.cpp:26:7
#61 0x00007f397e229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#62 0x00007f397e229e40 call_init ./csu/../csu/libc-start.c:128:20
#63 0x00007f397e229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#64 0x000055ebe395b575 _start (/home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt+0x2d57575)
[1]    42049 IOT instruction (core dumped)  /home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt  

I think it's failing because this implementation doesn't support negative values in the indices for slice. I'm going to make a separate PR with that so that this one doesn't get too big.

@gpetters94 gpetters94 force-pushed the index_put branch 7 times, most recently from 28f796b to 73b7720 Compare March 3, 2023 16:43
@gpetters94
Copy link
Collaborator Author

gpetters94 commented Mar 3, 2023

@ramiro050 It's failing on TOSA despite this test not being in the TOSA_PASS_SET. Is this a known bug?

I see it failing on LTC. Should be a matter of adding it to that list

@gpetters94 gpetters94 force-pushed the index_put branch 2 times, most recently from c656a34 to db56192 Compare March 3, 2023 21:38
@gpetters94 gpetters94 requested a review from ramiro050 March 3, 2023 22:39
@AmosLewis
Copy link
Collaborator

Negative indices fix #1917

@gpetters94
Copy link
Collaborator Author

Okay, this should be good to merge now @ramiro050

@gpetters94 gpetters94 force-pushed the index_put branch 2 times, most recently from b2ae471 to acdfeb5 Compare March 7, 2023 19:19
@AmosLewis
Copy link
Collaborator

Ramiro Two thoughts:

  1. I think instead of doing canonicalization for copy_ we should have a new pass called RecomposeComplexOps where we can add patterns such as the slice+copy_ transformation to combine ops that have been decomposed into a recomposed version. This allows us to have full control of when the pattern gets applied instead of relying on the canonicalizations which are not guaranteed to happen.
  2. We should perform the transformation of the slice arguments inside the copy_ pattern, since this is (at least right now) only needed for the copy_ pattern. In addition, I think we should be able to do this without needing shape information. I think we can just do getTensorSizes, and create IR that uses those values to calculate the value for the -1 case. The tensor sizes should eventually simplify to constants if there is enough information later on.

@gpetters94 gpetters94 force-pushed the index_put branch 2 times, most recently from fffe445 to 1217d15 Compare March 8, 2023 20:48
Copy link
Collaborator

@ramiro050 ramiro050 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! A few comments

lib/Dialect/Torch/Transforms/Passes.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/Transforms/RecomposeComplexOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/Transforms/RecomposeComplexOps.cpp Outdated Show resolved Hide resolved
lib/Dialect/Torch/Transforms/RecomposeComplexOps.cpp Outdated Show resolved Hide resolved
@AmosLewis
Copy link
Collaborator

t5_small_torchscript_test2.mlir

➜  t5small git:(indexput) ✗ torch-mlir-opt -pass-pipeline='builtin.module(torchscript-module-to-torch-backend-pipeline{backend-legal-ops=torch.aten.flatten.using_ints,torch.aten.native_layer_norm,torch.aten.linear})' ./t5_small_torchscript_test2.mlir  -mlir-print-ir-after-failure -mlir-disable-threading
<unknown>:0: error: invalid size -9223372036854775808 for !torch.tensor type
torch-mlir-opt: /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/IR/StorageUniquerSupport.h:174: static ConcreteT mlir::detail::StorageUserBase<mlir::torch::Torch::ValueTensorType, mlir::torch::Torch::BaseTensorType, mlir::torch::Torch::detail::ValueTensorTypeStorage, mlir::detail::TypeUniquer>::get(mlir::MLIRContext *, Args...) [ConcreteT = mlir::torch::Torch::ValueTensorType, BaseT = mlir::torch::Torch::BaseTensorType, StorageT = mlir::torch::Torch::detail::ValueTensorTypeStorage, UniquerT = mlir::detail::TypeUniquer, Traits = <>, Args = <std::optional<llvm::ArrayRef<long>>, mlir::Type>]: Assertion `succeeded(ConcreteT::verify(getDefaultDiagnosticEmitFn(ctx), args...))' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt -pass-pipeline=builtin.module(torchscript-module-to-torch-backend-pipeline{backend-legal-ops=torch.aten.flatten.using_ints,torch.aten.native_layer_norm,torch.aten.linear}) ./test_torchscript.mlir -mlir-print-ir-after-failure -mlir-disable-threading
 #0 0x000056299c60ce0d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:11
 #1 0x000056299c60d29b PrintStackTraceSignalHandler(void*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:639:1
 #2 0x000056299c60b566 llvm::sys::RunSignalHandlers() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Signals.cpp:104:5
 #3 0x000056299c60da55 SignalHandler(int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/lib/Support/Unix/Signals.inc:410:1
 #4 0x00007fcb98042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007fcb98096a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007fcb98096a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x00007fcb98096a7c pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x00007fcb98042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007fcb980287f3 abort ./stdlib/abort.c:81:7
#10 0x00007fcb9802871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007fcb98039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#12 0x00005629970122ba mlir::torch::Torch::ValueTensorType mlir::detail::StorageUserBase<mlir::torch::Torch::ValueTensorType, mlir::torch::Torch::BaseTensorType, mlir::torch::Torch::detail::ValueTensorTypeStorage, mlir::detail::TypeUniquer>::get<std::optional<llvm::ArrayRef<long>>, mlir::Type>(mlir::MLIRContext*, std::optional<llvm::ArrayRef<long>>, mlir::Type) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/IR/StorageUniquerSupport.h:173:5
#13 0x0000562996f69ffd mlir::torch::Torch::ValueTensorType::get(mlir::MLIRContext*, std::optional<llvm::ArrayRef<long>>, mlir::Type) /home/chi/src/ubuntu20/shark/torch-mlir/build/tools/torch-mlir/include/torch-mlir/Dialect/Torch/IR/TorchTypes.cpp.inc:662:10
#14 0x00005629976816b6 mlir::torch::Torch::BaseTensorType::getWithSizesAndDtype(std::optional<llvm::ArrayRef<long>>, mlir::Type) const /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/IR/TorchTypes.cpp:192:12
#15 0x0000562997806952 refineShapeCalculateResult(mlir::torch::Torch::ShapeCalculateOp, int, mlir::PatternRewriter&) /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/Transforms/SimplifyShapeCalculations.cpp:338:12
#16 0x0000562997806480 (anonymous namespace)::RefineShapeCalculateOp::matchAndRewrite(mlir::torch::Torch::ShapeCalculateOp, mlir::PatternRewriter&) const /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/Transforms/SimplifyShapeCalculations.cpp:356:21
#17 0x000056299780deeb mlir::detail::OpOrInterfaceRewritePatternBase<mlir::torch::Torch::ShapeCalculateOp>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/IR/PatternMatch.h:330:12
#18 0x000056299c21e142 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:200:25
#19 0x000056299c1c2cba (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:229:19
#20 0x000056299c1c0c6d (anonymous namespace)::RegionPatternRewriteDriver::simplify() && /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:456:15
#21 0x000056299c1c097f mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:485:47
#22 0x00005629977299d9 mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:115:15
#23 0x00005629977fe17c (anonymous namespace)::SimplifyShapeCalculationsPass::runOnOperation() /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/Transforms/SimplifyShapeCalculations.cpp:387:16
#24 0x000056299c228c3a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:471:21
#25 0x000056299c229224 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:534:16
#26 0x000056299c22a00e mlir::detail::OpToOpPassAdaptor::runOnOperationImpl(bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:675:20
#27 0x000056299c228eed mlir::detail::OpToOpPassAdaptor::runOnOperation(bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:658:1
#28 0x000056299c228c2b mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:468:5
#29 0x000056299c229224 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:534:16
#30 0x000056299c22d401 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_6::operator()(mlir::OpPassManager&, mlir::Operation*) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:456:12
#31 0x000056299c22d175 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (mlir::OpPassManager&, mlir::Operation*)>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_6>(long, mlir::OpPassManager&, mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#32 0x00005629977b4739 llvm::function_ref<mlir::LogicalResult (mlir::OpPassManager&, mlir::Operation*)>::operator()(mlir::OpPassManager&, mlir::Operation*) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#33 0x00005629977b1665 mlir::Pass::runPipeline(mlir::OpPassManager&, mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/../mlir/include/mlir/Pass/Pass.h:196:12
#34 0x00005629977ae454 (anonymous namespace)::LowerToBackendContractPass::runOnOperation() /home/chi/src/ubuntu20/shark/torch-mlir/lib/Dialect/Torch/Transforms/LowerToBackendContract.cpp:277:18
#35 0x000056299c228c3a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:471:21
#36 0x000056299c229224 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:534:16
#37 0x000056299c22ab99 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:843:10
#38 0x000056299c22aac5 mlir::PassManager::run(mlir::Operation*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Pass/Pass.cpp:823:60
#39 0x0000562996f56841 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:109:17
#40 0x0000562996f56570 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:155:12
#41 0x0000562996f563c8 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_1::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:190:12
#42 0x0000562996f56362 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_1>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#43 0x000056299c4eb45e llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#44 0x000056299c4eaa7d mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Support/ToolUtilities.cpp:28:12
#45 0x0000562996f54c4e mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:193:10
#46 0x0000562996f55bbf mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) /home/chi/src/ubuntu20/shark/torch-mlir/externals/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:339:14
#47 0x0000562996f07ca0 main /home/chi/src/ubuntu20/shark/torch-mlir/tools/torch-mlir-opt/torch-mlir-opt.cpp:33:7
#48 0x00007fcb98029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#49 0x00007fcb98029e40 call_init ./csu/../csu/libc-start.c:128:20
#50 0x00007fcb98029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#51 0x0000562996f07b55 _start (/home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt+0x302db55)
[4]    548186 IOT instruction (core dumped)  /home/chi/src/ubuntu20/shark/torch-mlir/build/bin/torch-mlir-opt  

@gpetters94
Copy link
Collaborator Author

@AmosLewis @ramiro050 Since this is green on the tests, can we land this and move the 9223372036854775807 thing to a separate issue?

Copy link
Collaborator

@ramiro050 ramiro050 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a small change request and a question

lib/Dialect/Torch/IR/TorchOps.cpp Outdated Show resolved Hide resolved
@gpetters94 gpetters94 merged commit 66b1045 into llvm:main Mar 10, 2023
@AmosLewis
Copy link
Collaborator

@AmosLewis @ramiro050 Since this is green on the tests, can we land this and move the 9223372036854775807 thing to a separate issue?

@ramiro050 @gpetters94 Here is the small python script to repeat this INTMAX bug. It looks like a make_fx error https://gist.github.com/AmosLewis/b53dfecbe4918618031cac01c8a88fb9#file-test_intmax-py-L41

@AmosLewis
Copy link
Collaborator

@gpetters94 @ramiro050 I think the implementation of the indices for the indexput is wrong. Here is the Python code I just used to test.

import torch
a = torch.tensor([[0, 1, 2, 3]])
a[..., 1:] = torch.tensor([4, 5, 6])
# = a[..., 1:4] = torch.tensor([4, 5, 6])
# = a[[0, 0, 0], [1, 2, 3]] = torch.tensor([4, 5, 6]) # tensor([[0, 4, 5, 6]])
# = torch.ops.aten.index_put(torch.tensor([[0, 1, 2, 3]]), # input
#                            (torch.tensor([0, 0, 0]), torch.tensor([1, 2, 3])), # indicies
#                            torch.tensor([4, 5, 6])) # value

# wrong1 george's recompose https://github.com/llvm/torch-mlir/pull/1901/files
torch.ops.aten.index_put(torch.tensor([[0, 1, 2, 3]]),
                         (torch.tensor([1, 2, 3])),
                         torch.tensor([[4, 5, 6]]))
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
#   File "/home/chi/src/ubuntu20/shark/SHARK/shark.venv/lib/python3.10/site-packages/torch/_ops.py", line 646, in __call__
#     return self._op(*args, **kwargs or {})
# IndexError: too many indices for tensor of dimension 2 (got 3)

# module attributes {torch.debug_module_name = "_lambda"} {
#   func.func @forward(%arg0: !torch.vtensor<[1,15],si64>, %arg1: !torch.vtensor<[1,4],si64>) -> !torch.vtensor<[1,4],si64> {
#     %int4 = torch.constant.int 4
#     %none = torch.constant.none
#     %false = torch.constant.bool false
#     %int-1 = torch.constant.int -1
#     %int1 = torch.constant.int 1
#     %int0 = torch.constant.int 0
#     %int9223372036854775807 = torch.constant.int 9223372036854775807
#     %cpu = torch.constant.device "cpu"
#     %0 = torch.prim.ListConstruct %int1, %int4 : (!torch.int, !torch.int) -> !torch.list<int>
#     %1 = torch.aten.zeros %0, %int4, %int0, %cpu, %false : !torch.list<int>, !torch.int, !torch.int, !torch.Device, !torch.bool -> !torch.vtensor<[1,4],si64>
#     %2 = torch.aten.slice.Tensor %arg1, %int1, %int0, %int-1, %int1 : !torch.vtensor<[1,4],si64>, !torch.int, !torch.int, !torch.int, !torch.int -> !torch.vtensor<[1,3],si64>
#     %3 = torch.aten.clone %2, %none : !torch.vtensor<[1,3],si64>, !torch.none -> !torch.vtensor<[1,3],si64>
#     %4 = torch.aten.slice.Tensor %1, %int1, %int1, %int9223372036854775807, %int1 : !torch.vtensor<[1,4],si64>, !torch.int, !torch.int, !torch.int, !torch.int -> !torch.vtensor<[1,3],si64>
#     %5 = torch.aten.arange.start_step %int1, %int4, %int1, %none, %none, %none, %none : !torch.int, !torch.int, !torch.int, !torch.none, !torch.none, !torch.none, !torch.none -> !torch.vtensor<[3],si64>
#     %6 = torch.prim.ListConstruct %5 : (!torch.vtensor<[3],si64>) -> !torch.list<optional<vtensor>>
#     %7 = torch.aten._index_put_impl %1, %6, %3, %false, %false : !torch.vtensor<[1,4],si64>, !torch.list<optional<vtensor>>, !torch.vtensor<[1,3],si64>, !torch.bool, !torch.bool -> !torch.vtensor<[1,4],si64>
#     return %7 : !torch.vtensor<[1,4],si64>
#   }
# }

@ramiro050
Copy link
Collaborator

IndexError: too many indices for tensor of dimension 2 (got 3)

I think this is a Python error

@AmosLewis
Copy link
Collaborator

AmosLewis commented Apr 18, 2023

IndexError: too many indices for tensor of dimension 2 (got 3)

I think this is a Python error

This Python error is manually created from what recompose pass generates.
After the recompose, the torchbackend indices for Aten_IndexPutImpl_Op is %6 = torch.prim.ListConstruct %5 : (!torch.vtensor<[3],si64>) -> !torch.list<optional<vtensor>>
Based on this, I manually create the same python indices which is (torch.tensor([1, 2, 3]))as python torch.ops.aten.index_put indices input.

I find this bug is because I trying to lower the Aten_IndexPutImpl_Op to tosa scatter, and the indices doesnot make sense to me.

@ramiro050
Copy link
Collaborator

What is the original slice+copy_ you're using?

@AmosLewis
Copy link
Collaborator

What is the original slice+copy_ you're using?

https://gist.github.com/AmosLewis/c6007c2154fedd51081faaee903a1b2c

/*pin_memory=*/noneVal);

SmallVector<Value> indicesVector;
for (auto i = 0; i < dim - 1; i++)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be i < dim not i < dim - 1

Copy link
Collaborator

@AmosLewis AmosLewis Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct indices should be (torch.tensor([0, 0, 0]), torch.tensor([1, 2, 3])), the first for dim0, the second for dim1, not the (torch.tensor([1, 2, 3])). In python code is a[[0, 0, 0], [1, 2, 3]]. I don't think the convert the dim-1 to dim would fix this issue.

Copy link
Collaborator

@AmosLewis AmosLewis Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After convert the dim-1 to the dim, get the indices like this
%6 = torch.prim.ListConstruct %none, %5 : (!torch.none, !torch.vtensor<[3],si64>) -> !torch.list<optional<vtensor>>
compare to the preiveous dim-1
%6 = torch.prim.ListConstruct %5 : (!torch.vtensor<[3],si64>) -> !torch.list<optional<vtensor>>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In [1]: import torch

In [2]: torch.ops.aten.index_put(torch.tensor([[0, 1, 2, 3]]),
   ...:                          (None, torch.tensor([1, 2, 3]),),
   ...:                          torch.tensor([[4, 5, 6]]))
Out[2]: tensor([[0, 4, 5, 6]])

That should work as expected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it correct.

@AmosLewis
Copy link
Collaborator

AmosLewis commented Apr 18, 2023

What is the original slice+copy_ you're using?

And as you can see in the previous comment. This is the slice1: and copy=.
if a = torch.tensor([[0, 1, 2, 3]])
a[..., 1:] = torch.tensor([4, 5, 6])
and it equal to
a[..., 1:4] = torch.tensor([4, 5, 6])
which is also equal to
a[[0, 0, 0], [1, 2, 3]] = torch.tensor([4, 5, 6])
which is also equal to

torch.ops.aten.index_put(torch.tensor([[0, 1, 2, 3]]), # input
                            (torch.tensor([0, 0, 0]), torch.tensor([1, 2, 3])), # indicies
                            torch.tensor([4, 5, 6])) # value

which is also equal to

torch.ops.aten.index_put(torch.tensor([[0, 1, 2, 3]]), # input
                            (None, torch.tensor([1, 2, 3])), # indicies
                            torch.tensor([4, 5, 6])) # value

gpetters94 added a commit to gpetters94/mlir-npcomp that referenced this pull request May 10, 2023
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

Successfully merging this pull request may close these issues.

4 participants