Skip to content

Add HiGHS as an opt-in MILP backend for the sharding solve - #599

Open
schmidt-jake wants to merge 1 commit into
meta-pytorch:mainfrom
schmidt-jake:jake/highs-milp-backend
Open

schmidt-jake wants to merge 1 commit into
meta-pytorch:mainfrom
schmidt-jake:jake/highs-milp-backend

Conversation

@schmidt-jake

Copy link
Copy Markdown

Problem

The sharding MILP is always solved with PuLP's bundled CBC. For large graphs this can be out of reach in practical time. We hit this on one whole-training-step placement problem from a large MoE model: 1.83M binary variables and about 1M rows, with a 900 s limit.

HiGHS 1.16 (via highspy) CBC (current default)
first integer-feasible point 68 s 938 s (past the limit)
optimality proven at 108 s (0% gap) not proven
objective 3,863,858 3,863,858

PuLP 3.2.1, which AutoParallel already pins, ships an in-process HiGHS interface (pulp.HiGHS, backed by highspy), so supporting it is a small change.

Change

  • ShardingOptimizer(..., milp_backend="cbc" | "highs") and AutoParallel(..., milp_backend=...). The default stays "cbc", so existing behaviour does not change. "highs" raises a clear error when highspy is not importable. highspy is added as an optional extra (autoparallel[highs]) and to requirements-test.txt. The backend is saved and loaded with the optimizer, next to solver_time_limit_seconds.
  • The deadline semantics from Bound sharding solver optimality time #556 are unchanged. PuLP maps HiGHS's time-limit statuses to the same (Optimal, IntegerFeasible) / (NotSolved, NoSolutionFound) pairs as CBC's, so an unproven incumbent is still a TimeoutError. The error message now names the backend.
  • Two changes in solution extraction that HiGHS needs and that are harmless for CBC:
    • HiGHS returns binaries within its integrality tolerance (e.g. 0.9999999), and dv.var.value() == 1 dropped those selections. A variable is now selected when its value is > 0.5.
    • _extract_and_validate_solution caught a node selected twice, but not a node with decision variables and no selection. That case only surfaced later, as a KeyError in apply_sharding. It now raises with the node names.
  • When the problem is infeasible, the violated-constraint walk runs only for CBC. HiGHS proves infeasibility without returning a point, so on a large problem the walk took minutes and reported nothing.

Tests

The new file tests/test_milp_backend.py covers:

  • validation of the backend argument, and the error when highspy is missing;
  • each backend's solver getting the time limit;
  • both backends finding the enumerated optimum of a small placement MILP through ShardingOptimizer._solve, with one strategy per node;
  • both backends reporting infeasibility, with the walk skipped for HiGHS;
  • selection within the integrality tolerance (this test fails with == 1);
  • the new missing-selection check.

tests/test_solver_time_limit.py only gets the new attribute on its stub. Locally, on macOS with a CPU-only torch nightly (2.16.0.dev20261128), these two files pass (16 tests). The CUDA-dependent suites, including test_serialization.py, fail identically before and after this change on that machine because torch is not built with CUDA, so CI is the check for those.

Lint: black 22.3.0, isort and flake8 pass on the changed files. mypy reports one existing error in autoparallel/shardings/propagation_rules.py:60, which is unrelated and also present on main.

Open questions for reviewers

  • HiGHS's default mip_rel_gap is 1e-4, so its "optimal" means optimal within 0.01%. CBC through PuLP uses its own defaults. I left HiGHS at its default. Should the solve pin the gap to 0 for both backends?
  • Would you rather select HiGHS automatically when highspy is installed? I kept it opt-in so that nothing changes for existing users.

This PR was authored with Claude (Claude Code).

🤖 Generated with Claude Code

https://claude.ai/code/session_01UwthrTQxLK9UDaYTG4tAie

The placement MILP of a large graph can be out of CBC's reach in practical
time. On one whole-training-step problem (1.83M binaries) with a 900 s limit,
CBC found its first integer point after 938 s and proved nothing, while HiGHS
found a feasible point at 68 s and proved the same objective optimal at 108 s.

ShardingOptimizer and AutoParallel take milp_backend="cbc" (the default,
unchanged) or "highs", which solves in process through PuLP's highspy
interface; highspy is an optional extra. The deadline semantics stay as they
are: an unproven incumbent at the time limit is still a TimeoutError.

Two changes are needed for HiGHS and are harmless for CBC. HiGHS returns
binaries within its integrality tolerance (0.9999999), so a variable is
selected when its value is above 0.5 rather than equal to 1. And because a
missed selection previously surfaced only later, as a KeyError in
apply_sharding, the solution check now also refuses a node with decision
variables but no selected strategy. HiGHS proves infeasibility without
returning a point, so the violated-constraint walk runs for CBC only.

Authored with Claude.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UwthrTQxLK9UDaYTG4tAie
@meta-cla

meta-cla Bot commented Nov 28, 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