Repository navigation
Support auto_functionalized_v2 nodes in the sharding solver and apply pass - #596
schmidt-jake wants to merge 1 commit into
Conversation
… pass aot_export_module functionalizes a custom op with mutates_args into an auto_functionalized_v2 higher-order op whose tensors are all kwargs (the mutated ones as indices into _all_bases). The solver crashed on it in get_op_strategy (`'AutoFunctionalizedV2' object has no attribute '_can_decompose'`), and every input-node helper read node.args only. * graph_utils.all_input_nodes, the solver's input lookup, build_sharding_metadata and the ordered-sharding helpers flatten (args, kwargs). * shardings/auto_functionalize.py decodes the node from the wrapped op's schema and the view-info kwargs, rebuilds the op's call with each mutated argument as its base, asks the DTensor registry (or AutoParallel's op rules) for the op's strategy, and maps it back onto the node's value (op returns..., updated bases...), each updated base taking its argument's placement. Strict views of a base and shared bases get the all-replicated strategy; out= variants and tensor-list mutated arguments raise NotImplementedError. DTensor's trailing-underscore in-place filter is disabled while the strategy is generated, since the solver places every operand. * apply_sharding redistributes tensors found in kwargs and runs the node. * compute estimation: non-OpOverload targets were priced at zero; price the node as a memory-bound opaque kernel on its sharded inputs and outputs. * tests: toy mutating ops with register_sharding rules (plain, underscore-named, a no-return op with two mutated arguments), decode and fallback cases, solves on 1-D and 2-D fake meshes, an end-to-end AutoParallel run, the cost model, and apply against the eager op on 2 and 4 gloo ranks, including an operand that must be redistributed through kwargs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @schmidt-jake! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Problem
aot_export_modulefunctionalizes a custom op that declaresmutates_argsinto anauto_functionalized_v2higher-order op. All of that node's tensors are kwargs; the mutated ones are indices into_all_bases. Graphs containing such nodes currently fail in the solver:The failure is in
get_op_strategy→_try_decomp_sharding, because a higher-order op is not anOpOverload. Beyond that, every input-node helper readsnode.argsonly, so the solver and the apply pass never see the node's tensors.Change
graph_utils.all_input_nodes, the solver's input lookup,build_sharding_metadataand the ordered-sharding helpers flatten(args, kwargs).shardings/auto_functionalize.py. It:(op returns..., updated bases...), each updated base taking its argument's placement.out=variants and tensor-list mutated arguments raiseNotImplementedError.apply_sharding. It redistributes tensors found in kwargs and runs the node.OpOverloadtargets were priced at zero compute. This PR prices the node as a memory-bound opaque kernel over its sharded inputs and outputs. It's a proxy, with no FLOP count. The zero-cost default also applies to other higher-order ops (e.g. flex attention), which this PR leaves unchanged.Tests
tests/test_auto_functionalize.py(20 tests) covers:register_shardingrules: plain, underscore-named, and a no-return op with two mutated arguments;AutoParallelrun;We also validated it against real in-place custom ops (a top-k repair kernel and a routing scan) on 2 and 4 H200s, in a separate harness not included here. Lint passes with the repo's pinned black, isort and flake8. mypy was not run locally.
🤖 Generated with Claude Code