Repository navigation
[FLOPs] Fix attention FLOPs estimate - #1923
Conversation
| model_args.n_layers, | ||
| model_args.n_heads, | ||
| model_args.dim // model_args.n_heads, | ||
| head_dims, | ||
| seq_len, |
There was a problem hiding this comment.
Do you think it's better if we set n_layers and n_heads as args to this function? I feel it might be more clear as a pure util function. E.g. a model can define number of layers using model_args.num_layers or model_args.L but still be able to use this util function.
We can even consider putting it to tools/utils.py instead of model/utils.py.
There was a problem hiding this comment.
I agree. Do you think we can also move the following part to args.py so get_moe_model_nparams_and_flops does not need to take model_args as input, and thus become model_args agnostic?
torchtitan/torchtitan/models/utils.py
Lines 445 to 446 in 06ec495
For your last point, I think these two functions are still more model relevant than those functions currently in tools/utils.py.
There was a problem hiding this comment.
oh, it seems the moe part has top_k and num_experts in model_args as well. Yeah NVM we can keep model_args as input arg for now.
There was a problem hiding this comment.
one minor thing is that we might need n_layers , and n_heads, and head_dim, and dim as the function args. This is because in Qwen3, the head_dim != dim / n_heads
There was a problem hiding this comment.
Thanks for the suggestions! Code updated accordingly.
| ) | ||
|
|
||
| l, h, q, t = ( | ||
| l, h, qv, t = ( |
There was a problem hiding this comment.
It might be better to be more specific on the naming n_layers n_heads, etc. especially for qv which looks a bit confusing.
tianyu-l
left a comment
There was a problem hiding this comment.
Had one more comments. O/w lgtm.
| n_layers: int, | ||
| n_heads: int, |
There was a problem hiding this comment.
oh sorry I didn't make myself clear -- I think if we need to pass in model_args anyway, we shouldn't pass in n_layers, n_heads redundantly.
Fix the FLOPs estimate in non-parameterized attention matmuls. This part estimate of FLOPs is customized for each model due to different Attention mechanisms.
Fix the FLOPs estimate in non-parameterized attention matmuls. This part estimate of FLOPs is customized for each model due to different Attention mechanisms.
Fix the FLOPs estimate in non-parameterized attention matmuls. This part estimate of FLOPs is customized for each model due to different Attention mechanisms.
Fix the FLOPs estimate in non-parameterized attention matmuls. This part estimate of FLOPs is customized for each model due to different Attention mechanisms.