Repository navigation
mtmd: cast vision K/V before attention permutation - #207
Draft
liangliangchang wants to merge 1 commit into
Draft
liangliangchang wants to merge 1 commit into
liangliangchang wants to merge 1 commit into
Conversation
Use contiguous FP32-to-FP16 conversion before constructing attention views. Keep the existing path available through MTMD_VISION_KV_CAST_EARLY. Assisted-by: Codex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves the vision K/V conversion to FP16 before the attention permutation, so eligible FP32 tensors use a contiguous conversion instead of a strided copy. The values are still converted to FP16 at the same point in the mathematical computation; attention precision and image budgets are unchanged.
Enable with
MTMD_VISION_KV_CAST_EARLY=1. The existing path remains the default and is also available with=0. The guard requires both K and V to be FP32; other types keep their existing path.Fresh Qwen3-VL-4B HTTP TTFT tests on Strix Halo, with identical model files, requests, prompt positions, microbatch size, and checkpoints/cache reuse disabled. Each arm has two warmups per process and ten retained measurements across an A/B/B/A sequence.
The earlier combined-stack trace had 48 strided conversion launches costing 17.68 ms per prefill. This change addresses that traffic. Gemma-4-E2B was essentially unchanged in isolation (0.12%); the improvement is workload dependent.
Built independently from gfx11 and exercised through complete VLM requests. Source style and whitespace checks passed. This PR has no dependency on the attention, BLAS, or MMDQ PRs. The Qwen window PR edits the nearby conversion guards, so combining them needs a small source conflict resolution that retains both behaviors.
AI assistance: Codex helped with the implementation, validation, and description. The change is submitted to the AMD fork for human review.