Repository navigation
Conversation
Summary: Syncs the following changes from the internal dev tree to facebookresearch/optimizers via `scripts/oss_sync.sh`. Everything under `ai_codesign/optimizers/` is script output, with two hand edits: - The new `CHANGELOG.md` entry: the generated bullets were rewritten into the release notes below. - `scripts/.last_oss_sync_rev`: the script set it to the hash of the draft fix commit below this diff (D126125211). That hash changes on amend and on land, so the next sync could never find it. It is set instead to the last landed synced commit (D125057665). As a result, the next sync will list D126125211 again once it has landed, and that one test-only bullet should be deleted then. - [shampoo] `pack_upper_triangular` and `unpack_upper_triangular`, used when inverse factor matrices are stored packed, now use a single index gather instead of zero-filling a `d×d` matrix and doing two scatters. Results are bit-identical, and the per-step cost of packing drops. Both functions now raise `ValueError` on malformed input: a non-square matrix passed to pack, or a packed tensor whose length is not `d*(d+1)/2` passed to unpack. In eager mode, the cached index maps grow from `d*(d+1)` to `d*d + d*(d+1)/2` int32 elements per distinct block dimension per device. Under `torch.compile` nothing is cached. - [shampoo] Add `DistributedShampoo.free_dist_buffer()`, `allocate_dist_buffer()` and the `dist_buffer_allocated` property. They release and restore the all-gather communication buffer that the DDP, HSDP and HybridShard distributors otherwise hold for the whole run, so its memory can be used outside the optimizer step. Opt-in: if `free_dist_buffer()` is never called, the buffer stays resident as before. Both calls are rank-local and do not synchronize ranks. `step()`, and `train()` / `eval()` when they communicate, raise `RuntimeError` on a rank whose buffer is still freed; other ranks may then block in a collective until timeout. The check runs before any optimizer state or parameter changes, so restoring the buffer allows a clean retry. Views over the buffer stay valid across free and restore. - [shampoo] Add `use_eager_init_step` to `DistributedShampoo` (default `False`). With a `ShampooPT2CompileConfig` set, the first optimizer step runs eagerly before switching to the compiled step, for callers that use the first step to initialize lazy optimizer state. A gradient-selector change during that eager step no longer triggers the PT2 recompilation warning. - [shampoo] `HybridShardDistributedConfig.communication_dtype` is now honored for gradient communication when `param_assignment_strategy` is `FSDPParamAssignmentStrategy.REPLICATE` or `ROUND_ROBIN`. A dtype narrower than the parameter dtype (e.g. `torch.bfloat16` for fp32 parameters) halves the bytes sent but quantizes the gradients. Parameter communication always stays at the parameter dtype. An equal-width dtype is honored. A wider dtype is ignored rather than applied, so the default `torch.float32` leaves fp32 runs unchanged and never upcasts bf16 parameters. With bf16 parameters, that default now logs a warning at optimizer construction. - [shampoo] Stop allocating each Kronecker factor matrix twice when building preconditioner state. One extra copy of the factor matrices is no longer held for the life of the job (no numerical change). - [shampoo] After an optimizer checkpoint is loaded, the lossless FSDP2/HSDP2 distributors now mark their gathered full parameters stale and rebuild them from the live model at the next optimizer step, rather than inside the load hook. Model and optimizer state can therefore be restored in either order. Restoring a lossless-distributor checkpoint across train/eval modes with GPA or Schedule-Free iterate averaging now raises `RuntimeError`. Same-mode restores are unaffected. - [shampoo] Reuse the supplied process group in `DDPDistributor` when `num_trainers_per_group` equals its size, rather than creating an equivalent subgroup and an extra NCCL communicator. Smaller groups are still partitioned as before. - [shampoo] Fix a hang with `HybridShardDistributedConfig` when a rank is assigned no parameter blocks (e.g. with round-robin assignment). Optimizer-state device meshes are now created on every rank while process groups are being set up, instead of lazily by block-owning ranks only. Later optimizer instances reuse the same meshes and process groups. - [gpa] Add `-> None` return annotations to `GPAAdamW.__init__`, `train` and `eval` (no behavior change). - [shampoo] Test-only type-checking fixes: add type-checker suppression comments in test utilities, and fix mypy errors in two test files (no behavior change). Internal revisions: D126125211, D125057665, D117586164, D123045794, D122710197, D121495947, D121698623, D121272407, D120951040, D120749948, D118385572 D124277336 is listed by the script but has no bullet: it only removed a `# pyre-unsafe` header, which the sync transform strips anyway, so it changes nothing in the mirror. Differential Revision: D126126133
|
@wz337 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D126126133. |
|
This pull request has been merged in 0ac3bd7. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Syncs the following changes from the internal dev tree to facebookresearch/optimizers via
scripts/oss_sync.sh. Everything underai_codesign/optimizers/is script output, with two hand edits:The new
CHANGELOG.mdentry: the generated bullets were rewritten into the release notes below.scripts/.last_oss_sync_rev: the script set it to the hash of the draft fix commit below this diff (D126125211). That hash changes on amend and on land, so the next sync could never find it. It is set instead to the last landed synced commit (D125057665). As a result, the next sync will list D126125211 again once it has landed, and that one test-only bullet should be deleted then.[shampoo]
pack_upper_triangularandunpack_upper_triangular, used when inverse factor matrices are stored packed, now use a single index gather instead of zero-filling ad×dmatrix and doing two scatters. Results are bit-identical, and the per-step cost of packing drops. Both functions now raiseValueErroron malformed input: a non-square matrix passed to pack, or a packed tensor whose length is notd*(d+1)/2passed to unpack. In eager mode, the cached index maps grow fromd*(d+1)tod*d + d*(d+1)/2int32 elements per distinct block dimension per device. Undertorch.compilenothing is cached.[shampoo] Add
DistributedShampoo.free_dist_buffer(),allocate_dist_buffer()and thedist_buffer_allocatedproperty. They release and restore the all-gather communication buffer that the DDP, HSDP and HybridShard distributors otherwise hold for the whole run, so its memory can be used outside the optimizer step. Opt-in: iffree_dist_buffer()is never called, the buffer stays resident as before. Both calls are rank-local and do not synchronize ranks.step(), andtrain()/eval()when they communicate, raiseRuntimeErroron a rank whose buffer is still freed; other ranks may then block in a collective until timeout. The check runs before any optimizer state or parameter changes, so restoring the buffer allows a clean retry. Views over the buffer stay valid across free and restore.[shampoo] Add
use_eager_init_steptoDistributedShampoo(defaultFalse). With aShampooPT2CompileConfigset, the first optimizer step runs eagerly before switching to the compiled step, for callers that use the first step to initialize lazy optimizer state. A gradient-selector change during that eager step no longer triggers the PT2 recompilation warning.[shampoo]
HybridShardDistributedConfig.communication_dtypeis now honored for gradient communication whenparam_assignment_strategyisFSDPParamAssignmentStrategy.REPLICATEorROUND_ROBIN. A dtype narrower than the parameter dtype (e.g.torch.bfloat16for fp32 parameters) halves the bytes sent but quantizes the gradients. Parameter communication always stays at the parameter dtype. An equal-width dtype is honored. A wider dtype is ignored rather than applied, so the defaulttorch.float32leaves fp32 runs unchanged and never upcasts bf16 parameters. With bf16 parameters, that default now logs a warning at optimizer construction.[shampoo] Stop allocating each Kronecker factor matrix twice when building preconditioner state. One extra copy of the factor matrices is no longer held for the life of the job (no numerical change).
[shampoo] After an optimizer checkpoint is loaded, the lossless FSDP2/HSDP2 distributors now mark their gathered full parameters stale and rebuild them from the live model at the next optimizer step, rather than inside the load hook. Model and optimizer state can therefore be restored in either order. Restoring a lossless-distributor checkpoint across train/eval modes with GPA or Schedule-Free iterate averaging now raises
RuntimeError. Same-mode restores are unaffected.[shampoo] Reuse the supplied process group in
DDPDistributorwhennum_trainers_per_groupequals its size, rather than creating an equivalent subgroup and an extra NCCL communicator. Smaller groups are still partitioned as before.[shampoo] Fix a hang with
HybridShardDistributedConfigwhen a rank is assigned no parameter blocks (e.g. with round-robin assignment). Optimizer-state device meshes are now created on every rank while process groups are being set up, instead of lazily by block-owning ranks only. Later optimizer instances reuse the same meshes and process groups.[gpa] Add
-> Nonereturn annotations toGPAAdamW.__init__,trainandeval(no behavior change).[shampoo] Test-only type-checking fixes: add type-checker suppression comments in test utilities, and fix mypy errors in two test files (no behavior change).
Internal revisions: D126125211, D125057665, D117586164, D123045794, D122710197, D121495947, D121698623, D121272407, D120951040, D120749948, D118385572
D124277336 is listed by the script but has no bullet: it only removed a
# pyre-unsafeheader, which the sync transform strips anyway, so it changes nothing in the mirror.Differential Revision: D126126133