Repository navigation
Description
Summary
conv2d (and conv1d) are declared in the cxx bridge as returning UniquePtr<MlxArray>, not Result. When MLX throws inside them (for example a shape mismatch), cxx converts the uncaught C++ exception into std::terminate, which aborts the whole server process instead of failing the one request. This is the same crash class that #384 fixed for the audio-synthesis matmul path. This issue extends that fix to the convolution ops so a conv fault on the audio (or vision) path degrades to a recoverable per-request error.
Background
The Gemma 4 audio conv crash surfaced as:
libc++abi: terminating due to uncaught exception of type std::invalid_argument: [conv] Expect the input channels in the input and weight array to match but got shapes - input: (1,12,130,1) and weight: (128,3,1,3)
The shape mismatch itself is a weight-layout bug fixed separately (the conv-weight layout-detection issue). This issue is the defense-in-depth half: even with correct layouts, any future data-dependent conv shape fault should not be able to take down the server.
Mechanism
src/lib/mlxcel-core/src/lib.rs:953declaresfn conv2d(...) -> UniquePtr<MlxArray>in the cxx bridge (non-Result). The C++ side (src/lib/mlxcel-core/cpp/mlx_cxx_bridge.cpp:2375) callsmlx::core::conv2ddirectly.- Per the fix(mlxcel-core): make audio-path MLX ops fallible at the FFI boundary #384 commit (
09e5c3d) rationale: "An MLX C++ exception thrown from a non-Result cxx op aborts the process via std::terminate, which the catch_unwind backstop in the audio worker cannot intercept regardless of the release panic setting." So a throw fromconv2daborts the process; the audio worker'scatch_unwindcannot catch a C++std::terminate. - MLX validates conv shapes eagerly at op construction, so the throw happens at graph build, exactly where a
Result-returning cxx wrapper can catch it.
Scope
- Add
try_conv2d(andtry_conv1d) declared-> Result<...>in the cxx bridge, mirroringtry_matmulfrom fix(mlxcel-core): make audio-path MLX ops fallible at the FFI boundary #384, so cxx catches an MLX throw at the FFI boundary and returns a recoverableErr. - Route the audio encoder's conv calls through the fallible variants:
SSCPConvBlockconv2d (src/audio/encoder.rs:125) andConformerLightConv1ddepthwise conv1d (src/audio/encoder.rs:374), since their input shapes are data-dependent (derived from the runtime audio length). - Follow fix(mlxcel-core): make audio-path MLX ops fallible at the FFI boundary #384's scoping rationale: leave conv calls on hot paths with statically fixed shapes unchanged to avoid per-op overhead; convert the data-dependent audio-path calls. Vision-encoder conv calls can be evaluated for inclusion but are lower priority (their patch-embed shapes are fixed by config).
- Map a returned
Errto the existing audio worker error handling so the request fails cleanly with a message instead of aborting.
Tests
- FFI regression beside the bridge, mirroring fix(mlxcel-core): make audio-path MLX ops fallible at the FFI boundary #384's
try_matmultests:try_conv2don mismatched input/weight channels returnsErr(the graph-build throw is caught, the process is not aborted), and the happy path matchesconv2d.
Acceptance criteria
- A conv shape mismatch on the audio path produces a per-request
Err(surfaced as a request error), not a process abort. - An FFI test demonstrates
try_conv2dreturnsErron a channel mismatch rather than terminating. - No behavior change on the happy path; no measurable per-op overhead added to statically-shaped conv hot paths.
Related
Companion to the conv-weight layout-detection fix (which removes the specific Gemma 4 audio trigger). This issue ensures the broader conv path is crash-isolated. References #384 (09e5c3d), which established the try_* fallible-op pattern for the audio path.
Activity
inureyes commentedon Jun 24, 2026
Companion to #428, the layout-detection fix that removes the specific Gemma 4 audio trigger. This issue is the defense-in-depth half (crash isolation for the broader conv path).
test: add try_conv1d ok parity test and extend fallible-conv docs
fix: route nemotron omni audio-encoder convs through fallible FFI (#439)
fix: make conv2d/conv1d fallible at the FFI boundary so conv shape fa…
fix: make conv2d/conv1d fallible at the FFI boundary so conv shape fa…
fix: route nemotron omni audio-encoder convs through fallible FFI (la…