Skip to content

fix(epp): reduce per-request memory retention during inference - #3

Open
Lucas-Fernandes-Martins wants to merge 1 commit into
mistral-mainfrom
lfm/fix-memory-issues-request-parsing
Open

fix(epp): reduce per-request memory retention during inference#3
Lucas-Fernandes-Martins wants to merge 1 commit into
mistral-mainfrom
lfm/fix-memory-issues-request-parsing

Conversation

@Lucas-Fernandes-Martins

@Lucas-Fernandes-Martins Lucas-Fernandes-Martins commented Jul 26, 2026

Copy link
Copy Markdown

Why

Profiling EPP pods under multimodal load (1325 heap dumps over 11 hours) showed each request retaining ~225 MB for the full inference duration (60-700s). At 100 concurrent multimodal requests, live heap hits 22.5 GB and RSS balloons to ~40 GB. Two unnecessary memory retention patterns account for most of the waste.

Summary

1. Release heavy fields after repackage (director.go)

Setting request payload to nil after it's used for the last time to save memory (GC won't free that memory since it belongs to a struct that is still in use).

2. Stream base64 for image dimensions (mm_estimate.go)

imageDimensionsFromBase64Payload fully decodes base64 images into memory just to call image.DecodeConfig, which only reads the image header (~100 bytes for PNG/JPEG/GIF). Replaced with a streaming base64.NewDecoder that decodes lazily as image.DecodeConfig.

@Lucas-Fernandes-Martins
Lucas-Fernandes-Martins marked this pull request as ready for review July 26, 2026 14:22
@Lucas-Fernandes-Martins
Lucas-Fernandes-Martins force-pushed the lfm/fix-memory-issues-request-parsing branch 2 times, most recently from 1907f26 to df961a9 Compare July 27, 2026 07:26
Release heavy InferenceRequestBody fields (Payload, ChatCompletions,
Messages, etc.) immediately after repackage so GC can collect them
during the long inference wait (60-700s). Only Stream, Model, and
MaxOutputTokens are read post-repackage.

Replace full base64 decode in image dimension estimation with a
streaming decoder — image.DecodeConfig only needs the image header
(~100 bytes), not the entire decoded payload.

Profiling on production EPP pods showed multimodal requests retaining
~225 MB each for the full inference duration. These two fixes reduce
live heap by ~11 GB at 100 concurrent multimodal requests.
@Lucas-Fernandes-Martins
Lucas-Fernandes-Martins force-pushed the lfm/fix-memory-issues-request-parsing branch from df961a9 to 0cf5db0 Compare July 27, 2026 07:30
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.

1 participant