Skip to content

dsv41 metal mv_mma: guard f32 pipeline with errdefer in loadSource - #5015

Merged
ashhart merged 2 commits into
ashhart:mainfrom
cwschroeder:pr/dsv41-mv-mma-errdefer
Nov 25, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
cwschroeder:pr/dsv41-mv-mma-errdefer

Conversation

@cwschroeder

Copy link
Copy Markdown
Contributor

Splits out the pipeline leak fix noted in #4784 directly onto main, independent of the held Inkling Metal stack.

In zig/src/families/deepseek_v41/metal/mv_mma.zig, Pipelines.loadSource previously initialized both f32 and bf16 pipelines inside the return literal, leaking the f32 pipeline if bf16 initialization failed. This binds f32_pipe locally with errdefer f32_pipe.deinit() before creating bf16_pipe.

Verified locally with zig fmt --check build.zig zig, zig build compile-inkling2-native-host -Dfixed-cpu -j2, and python3 tools/pr_check.py --base origin/main (0 errors).

@AIFlowML

Copy link
Copy Markdown
Contributor

Thanks for splitting this out. I tested 1f6dfdcdeb in a clean trial merge into b6ab6dbfd7. The one-file change also merges cleanly into current main 777f3bb762.

The contract executable built, and ./zig-out/bin/tf-kernel-contract --only 'dsv41 mv mma' on M5 Max passed both output formats, caught all four planted controls and found zero launch-limit problems. The broader test-dsv41-metal run hit the existing early_test.zig:122 reference to the removed Target.argmax; that fixture and its target implementation are unchanged by this PR. I checked the ownership guard in source and the normal device path. I did not inject a pipeline-creation failure.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks, @cwschroeder. The guard now protects the acquired F32 pipeline before BF16 creation can fail, while leaving successful loading and dispatch unchanged. The reported two-format checks and four caught controls are useful. The separate early-test compile issue is unchanged by this fix. This narrow cleanup change looks ready.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I verified the failure path on M5 Max with 1f6dfdcdeb trial-merged into 47a605aa12. A scratch test renamed only the BF16 entry point in the real Metal source, acquired the F32 pipeline and watched it with an Objective-C weak reference. The second lookup returned NoFunction, as expected.

With the cleanup removed, the F32 object stayed alive after the loader returned and its autorelease pool drained. Restoring this PR's one-line guard made the object deallocate and the focused fixture pass 1/1.

zig build test-dsv41-mv-mma-setup -Dfixed-cpu -j2 --summary all

That target is the local fault-injection fixture. The PR's normal F32 and BF16 device contract results are in the earlier receipt. This isolates setup ownership and leaves the separate early-picks test issue outside this PR.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the pr/dsv41-mv-mma-errdefer branch from 1f6dfdc to 0c96dbf Compare November 25, 2026 11:37
@ashhart
ashhart merged commit 5927a90 into ashhart:main Nov 25, 2026
12 checks passed
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @cwschroeder. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

3 participants