Skip to content

[bugfix]: fix VLM MFU miscomputation - #4057

Closed
ghost wants to merge 2 commits into
mainfrom
unknown repository
Closed

ghost wants to merge 2 commits into
mainfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Aug 3, 2026

Copy link
Copy Markdown

Closes #4009.

Currently, VLM TFLOPs and MFU are reported from decoder FLOPs alone, so vision-encoder work is missing.

this pr adds per-batch vision FLOPs from grid_thw for Qwen3.5 and Kimi2.5. Then accumulates them over each logging window and then adds them to the existing decoder estimate.

Testing

Ran VLM on 8xH100. Ran fixed-seed branch vs upstream runs which matched at every logged loss value. log_freq=3 run matched independent computed FLOPs at every logging bound (max rel error 7.3e-8).

some observations: tflops/mfu increased by the missing vision work. qwen mem peak was identical and tps stayed within bounds.

test plots image image image

@ghost
ghost requested review from fegin, felipemello1, tianyu-l, wconstab and wwwjn as code owners August 3, 2026 21:31
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 3, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@ghost
ghost force-pushed the fix/vlm-mfu-miscomputation branch from 108a1a1 to 3c814e2 Compare August 30, 2026 14:27
@tianyu-l
tianyu-l requested a review from jinsooihm August 30, 2026 21:41
Comment thread torchtitan/models/utils.py Outdated
return 6 * 3 * num_heads * key_head_dim * v_head_dim


def get_vision_flops(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this complicated calculation that goes through the model every time? Similar to how the decoder flops calculation is done by num_flops_per_token * ntokens_since_last_log, can't each model define a fixed constant, like num_flops_per_patch that can be multiplied to the image size to compute the flops?

Also, another thing to consider is that we do not take into account of the individual document lengths within an input sequence for calculating flops for decoder, but just compute the flops as if the given sequence is a single document. I am wondering if we should also just compute the vision encoder flops just in terms of total number of patches, not taking into account of individual images. cc. @tianyu-l

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik vision flops r not linear per total patch count.

that goes through the model every time?
can't each model define a fixed constant like num_flops_per_patch?

👍

I am wondering if we should also just compute the vision encoder flops just in terms of total number of patches, not taking into account of individual images.

same patch count can have different per-image attention flops no?

@ghost ghost closed this by deleting the head repository Sep 30, 2026
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VLM MFU is miscomputed: vision-encoder FLOPs billed per decoder token, not per image patch

1 participant