ml-explore / mlx-swift-examples

Examples using MLX Swift
MIT License
1.03k stars 110 forks source link

llm-tool: crash during sync generation #7

Closed rudro closed 7 months ago

rudro commented 9 months ago

I know there is an issue with async generation but the sync version is also now crashing in debug. This is with the current state of the repo, and no command-line args (so all defaults). Get's a EXC_BAD_ACCESS right on launch. Switching to release delays this, but we still get the same crash after a while.

This is with Xcode 15.0 on and M3.

#0  0x0000000100684428 in pthread_mutex_lock ()
#1  0x0000000183524300 in std::__1::mutex::lock() ()
#2  0x00000001050dba58 in std::__1::unique_lock<std::__1::mutex>::unique_lock[abi:v160006](std::__1::mutex&) at /Applications/Xcode.15.0.0.15A240d.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__mutex_base:123
#3  0x00000001050db994 in std::__1::unique_lock<std::__1::mutex>::unique_lock[abi:v160006](std::__1::mutex&) at /Applications/Xcode.15.0.0.15A240d.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__mutex_base:123
#4  0x0000000105c7f088 in void mlx::core::scheduler::StreamThread::enqueue<mlx::core::eval(std::__1::vector<mlx::core::array, std::__1::allocator<mlx::core::array>> const&)::$_4>(mlx::core::eval(std::__1::vector<mlx::core::array, std::__1::allocator<mlx::core::array>> const&)::$_4&&) at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/mlx-swift/Source/Cmlx/mlx/mlx/scheduler.h:67
#5  0x0000000105c7f058 in void mlx::core::scheduler::Scheduler::enqueue<mlx::core::eval(std::__1::vector<mlx::core::array, std::__1::allocator<mlx::core::array>> const&)::$_4>(mlx::core::Stream const&, mlx::core::eval(std::__1::vector<mlx::core::array, std::__1::allocator<mlx::core::array>> const&)::$_4&&) at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/mlx-swift/Source/Cmlx/mlx/mlx/scheduler.h:156
#6  0x0000000105c6e110 in void mlx::core::scheduler::enqueue<mlx::core::eval(std::__1::vector<mlx::core::array, std::__1::allocator<mlx::core::array>> const&)::$_4>(mlx::core::Stream const&, mlx::core::eval(std::__1::vector<mlx::core::array, std::__1::allocator<mlx::core::array>> const&)::$_4&&) at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/mlx-swift/Source/Cmlx/mlx/mlx/scheduler.h:163
#7  0x0000000105c6d874 in mlx::core::eval(std::__1::vector<mlx::core::array, std::__1::allocator<mlx::core::array>> const&) at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/mlx-swift/Source/Cmlx/mlx/mlx/transforms.cpp:174
#8  0x00000001050dd6d4 in mlx::core::array::eval() at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/mlx-swift/Source/Cmlx/mlx/mlx/array.cpp:118
#9  0x0000000105086944 in long long mlx::core::array::item<long long>() at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/mlx-swift/Source/Cmlx/mlx/mlx/array.h:459
#10 0x00000001050868b4 in ::mlx_array_item_int64(mlx_array) at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/mlx-swift/Source/Cmlx/include/mlx/c/array.cpp:217
#11 0x0000000105d074a0 in MLXArray.item<τ_0_0>(_:) at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/mlx-swift/Source/MLX/MLXArray.swift:148
#12 0x0000000100004ab0 in SyncGenerator.run() at /Users/rudro/Downloads/mlx-swift-examples/Tools/llm-tool/LLMTool.swift:66
#13 0x00000001000078dc in protocol witness for AsyncParsableCommand.run() in conformance SyncGenerator ()
#14 0x0000000100042510 in static AsyncParsableCommand.main() at /Users/rudro/Library/Developer/Xcode/DerivedData/mlx-swift-examples-fjjhyybavhevkrermxyzsqgkqhwy/SourcePackages/checkouts/swift-argument-parser/Sources/ArgumentParser/Parsable Types/AsyncParsableCommand.swift:37
#15 0x0000000100001f30 in static LLMTool.$main() ()
#16 0x000000010000cf18 in async_MainTQ0_ ()
#17 0x000000010000d060 in thunk for @escaping @convention(thin) @async () -> () ()
#18 0x000000010000d188 in partial apply for thunk for @escaping @convention(thin) @async () -> () ()
davidkoski commented 9 months ago

This looks like the main thread (calling eval and waiting for the result). One of the other threads is actually crashing -- can you post that? If (as I suspect) it is very very deep, just a snippet would be fine.

davidkoski commented 7 months ago

If this is due to deep recursion (likely) then this is fixed as of https://github.com/ml-explore/mlx-swift/pull/67