Skip to content

Conversation

@fmassa
Copy link
Contributor

@fmassa fmassa commented Aug 21, 2025

Previously, if we had tuple of tensors as an argument to a function, we wouldn't apply any sharding on it. This is split from #26 , where I originally found this issue

Previously, if we had tuple of tensors as an argument to a function, we wouldn't apply any sharding on it. This is split from #26 , where I originally found this issue
@fmassa fmassa requested review from bdhirsh and wconstab August 21, 2025 09:51
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 21, 2025
args = tree_map_only(torch.fx.Node, lambda x: x.meta["val"], node.args)
kwargs = tree_map_only(torch.fx.Node, lambda x: x.meta["val"], node.kwargs)

fake_mode = torch._guards.detect_fake_mode(args)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this bc we are already under a fake mode now, but we weren't in the initial autop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's right, now the whole AutoParallel is running under fake mode, so we can remove it

args = tree_map_only(torch.fx.Node, lambda x: x.meta["val"], node.args)
kwargs = tree_map_only(torch.fx.Node, lambda x: x.meta["val"], node.kwargs)

fake_mode = torch._guards.detect_fake_mode(args)
Copy link
Member

Choose a reason for hiding this comment

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

this is removed because we're already running this in a fake mode?

_get_sharded_shape_stride(spec) for spec in strategy.input_specs
)

flat_args, treespec = tree_flatten(args)
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we just call tree_map_only(Tensor, torch.empty) here instead of doing the for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to get the size from the args_sizes_strides (which comes from the spec), so I think we might need this indirection.

But if there is a cleaner way of doing this I'm happy to change the code!

@fmassa fmassa merged commit 20e53b0 into main Aug 21, 2025
6 checks passed
@fmassa fmassa deleted the fmassa/improve_flop_estimation branch August 21, 2025 18:19
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.

4 participants