Repository navigation
Nemotron 3.5 vLLM embed: faster image embedding (flash attention, preprocess once) - #2836
Conversation
…flash attention The HF Pixtral vision tower concatenates every image in a vLLM multimodal batch into one sequence and runs SDPA with a dense block-diagonal mask. Run the tower once per image and drop the mask for a single image so SDPA can select flash attention. Per-image outputs keep the stock order and shape. Text+image admission now counts expanded prompt tokens from the image size and the tokenizer instead of running the processor's pixel preprocessing a second time before vLLM. Images smaller than one merged patch still use the processor so its resize and error behavior is unchanged. Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
… array Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
[Medium impact] The PR appears safe to merge; no new actionable issues were established. SummaryThis PR speeds up image embedding by counting image tokens from dimensions and running the vision model once per image.
|
Signed-off-by: Jacob Ioffe <jioffe@nvidia.com>
| for size in sizes: | ||
| offsets.append(offsets[-1] + size) | ||
|
|
||
| def item(value: object, index: int) -> object: |
There was a problem hiding this comment.
[P3] Consider specializing the slicing to the actual Pixtral contract
This is a nonblocking minimality suggestion. The pinned Pixtral processor reports num_image_patches = [1] * len(image_sizes), and this architecture is already restricted to the Mistral3/Ministral3 retrieval profile. The cumulative offsets plus generic shape-based dispatch over every kwarg support a broader patch/field contract than this model currently uses. Consider slicing the known per-image Pixtral fields directly and continuing to delegate inference/output handling to the parent. That would remove the unused flattened-patch machinery and make the input assumptions explicit. The new test currently uses [2, 3] with a 2-D fake pixel tensor; add or use the real [1, 1] case with 4-D pixels and paired image_sizes to verify the production contract.
| return_tensors="pt", | ||
| ) | ||
| return int(batch["attention_mask"].sum()) | ||
| return self._image_prompt_lengths([prompt], [image])[0] |
There was a problem hiding this comment.
[P3] Clarify or limit the HF admission change beyond the stated vLLM scope
The description presents this as a vLLM optimization, but plan_text_image is shared by both backends, so replacing its processor-based counter unconditionally also changes backend="hf" admission. HF inference still uses the full processor while its split planner now predicts expansion from sizes. I did not find a count mismatch for the supported defaults, so this is a scope/validation comment rather than a confirmed bug. For the smallest vLLM-only change, retain the existing counter for HF; if the shared optimization is intentional, call it out in the description and include an HF planning-versus-processor check near the input limit.
There was a problem hiding this comment.
Intentional: the count only depends on image size, so it's the same for both backends, and it matched the real processor on all 1,006 sizes tested. Noted the HF effect in the description.
Description
Makes image embedding with Nemotron 3.5 (vLLM) faster. It fixes two things:
Image-heavy ingest (ViDoRe) is ~70% faster; PDF/text is unchanged. The speedup is per image, so it holds at any dataset size. Per-subset results are in the stacked PR #2837.
Confidence
main(cosine ≥ 0.9997).backend="hf"split planning (shared code); the count depends only on image size, so it is backend-independent.Checklist
Link to Devin session: https://nvidia-cloud.devinenterprise.com/sessions/bad125a41197410993e49df9e8ca2f37
Open in Devin Desktop: https://nvidia-cloud.devinenterprise.com/desktop/session/bad125a41197410993e49df9e8ca2f37?variant=devin
Requested by: @jioffe502
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work