Skip to content

Conversation

wwwjn
Copy link
Contributor

@wwwjn wwwjn commented Sep 29, 2025

As titled, remove repeated copy

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 29, 2025
@wwwjn wwwjn marked this pull request as ready for review September 29, 2025 05:44
from torchtitan.tools.logging import logger


def get_dense_model_nparams_and_flops(
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel this function for dense can be entirely covered by the MoE one. Should we keep it for readability? I'm OK with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made separate functions because in moe model nparams function, there are several places accessing model_args.moe_args. For our dense model definition, we don't have this field. So if we want to merge them, we need to add several checks like if hasattr(model_args, "xxx"). Technically we can merge them, but for readability I make the separate for now

Comment on lines +90 to +92
# If weight tying is enabled, subtract embedding parameters from total count
if hasattr(model_args, "enable_weight_tying") and model_args.enable_weight_tying:
nparams = nparams - nparams_embedding
Copy link
Contributor

Choose a reason for hiding this comment

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

May not be needed by real models in torchtitan, but I feel this should be added to the dense part as well, because later on new dense + weight tying model could be added so if they reuse the dense fn it's still correct. An example would be Llama 3.2 1B / 3B.

Copy link
Contributor

@fegin fegin left a comment

Choose a reason for hiding this comment

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

LGTM, one minor thing is that we seem to have too many utils.py, lol. In the future we may need to revisit some of the utils.py, otherwise those are quickly becoming a dump ground.

@wwwjn wwwjn merged commit c854924 into main Oct 1, 2025
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants