Skip to content

Drop sharding strategies whose cost estimation raises - #598

Open
schmidt-jake wants to merge 1 commit into
meta-pytorch:mainfrom
schmidt-jake:jake/cost-estimation-skip-invalid
Open

schmidt-jake wants to merge 1 commit into
meta-pytorch:mainfrom
schmidt-jake:jake/cost-estimation-skip-invalid

Conversation

@schmidt-jake

Copy link
Copy Markdown

Problem

Estimating a strategy's cost runs the op on its sharded fake inputs. A kernel can reject a shape that only some placements produce. For example, _grouped_mm requires 16-byte-aligned strides, and one candidate sharding of a small expert width left 12 bytes. The error propagated and killed the whole solve, though that strategy was simply unavailable and the others were fine.

Change

ShardingOptimizer now filters each node's strategy list through _drop_invalid_strategies before its consumers read it, so redistribute costs stay aligned with the strategy list.

  • A strategy whose cost estimation raises RuntimeError or ValueError is dropped and logged once per (op, error).
  • A node with no valid strategy left raises, with the first error chained.

Trade-offs for review:

  • Cost: it runs cost estimation for every strategy at strategy-building time, which adds solve-time work.
  • Masking: catching RuntimeError/ValueError broadly could hide a genuine bug in an op's fake implementation. The warning makes such drops visible. A narrower contract, e.g. a dedicated exception type for "invalid placement", may be preferable, and I'm happy to change it.

Test

tests/test_invalid_strategy_skip.py defines an op whose fake implementation rejects one sharded shape. The solve picks the remaining strategy with the fix and fails without it. Lint passes with the repo's pinned black, isort and flake8. In this environment, tests/test_conservative_operator_strategies.py shows the same 4 failures with and without this change. The full suite wasn't run.

🤖 Generated with Claude Code

Estimating a strategy's cost runs the op on the sharded fake inputs, and a kernel can
refuse a shape that only some placements produce (_grouped_mm needs 16-byte aligned
strides). That was fatal for the whole solve. The strategy is now dropped, before the
node's consumers read its strategy list, logged once per (op, error); a node left with no
strategy raises.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@meta-cla

meta-cla Bot commented Nov 26, 2026

Copy link
Copy Markdown

Hi @schmidt-jake!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant