Skip to content

Fix diffusion GPU memory leak: reuse InferenceFunction#110

Merged
stikves merged 1 commit into
apple:mainfrom
stikves:fix/diffusion-function-reuse
Jul 17, 2026
Merged

Fix diffusion GPU memory leak: reuse InferenceFunction#110
stikves merged 1 commit into
apple:mainfrom
stikves:fix/diffusion-function-reuse

Conversation

@stikves

@stikves stikves commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

The diffusion pipeline loaded a fresh InferenceFunction on every inference call (~30 per generation) as a workaround for an MPSGraph buffer caching bug. That bug is fixed since macOS 27 Beta 3+. The workaround caused GPU memory to accumulate across generations, leading to SIGABRT after ~20 images.

Now reuses the stored function (matching how LLM engines work). Also wraps model loading and inference in do/catch to surface actionable errors instead of crashing on GPU memory exhaustion.

Addresses #77.

The diffusion pipeline loaded a fresh InferenceFunction on every inference
call (~30 per generation) as a workaround for a framework buffer caching
bug that has since been fixed. The workaround caused GPU memory to
accumulate across generations, leading to SIGABRT after ~20 images.

Now reuses the stored function (matching how LLM engines work). Also wraps
model loading and inference in do/catch to surface actionable errors instead
of crashing on GPU memory exhaustion.

Addresses apple#77.
@stikves stikves self-assigned this Jul 16, 2026
@stikves
stikves merged commit aeb6ae3 into apple:main Jul 17, 2026
3 checks passed
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.

2 participants