Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/175230
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 2 New FailuresAs of commit d5a4e6a with merge base 018bf86 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Results for DeepSeek-V3-671B training shared here #146542 (comment) |
e0579a9 to
6f62811
Compare
crcrpar
left a comment
There was a problem hiding this comment.
I'm not sure AT_DISPATCH macro in mixed precision is necessary
|
@claude please review this PR! |
|
Claude finished @janeyx99's task in 5m 14s —— View job PR Review: #175230SummaryThis PR adds mixed-precision fused CUDA kernels for Adam/AdamW that allow optimizer states ( Code Quality
Infrastructure
API Design
Testing
Backward Compatibility
Performance
RecommendationRequest Changes Key issues to resolve before merge:
|
|
@janeyx99 I have addressed 3/4 changes requested by Claude, regarding 4th I am not sure if we want to expose hook as a proper utility, since in longer term I assume we will have a proper front-end interface. Review comment from @crcrpar is also addressed as part of these changes. Regarding some other comments listed by Claude,
|
janeyx99
left a comment
There was a problem hiding this comment.
thank you! looks good overall, please link benchmark results for memory and perf!
also, please ensure lint and tests pass. It would be nice once this lands to document how to use this in torchtitan to widen visibility |
|
@janeyx99 Uploaded another patch with changes as suggested in review comments. 1 of the tests test_fused_mixed_precision_hook_skips_existing_state has been refactored to align more closely to original intent of the test. Adding some plots giving a picture of Peformance, memory usage and convergence with float32 vs bfloat16 optimize r states for DeepSeek-V3-16B. Please help trigger CI if everything looks ok to you. Thanks. |
| p.grad = torch.rand_like(p) | ||
|
|
||
| optim = optim_cls( | ||
| [{"params": g1_params}, {"params": g2_params}], |
There was a problem hiding this comment.
great!
just curious, if this had been one group, i expect there'd be errors because our current group by device + dtype is unaware + wouldn't separate them based on the types of exp_avg+exp_avg_sq, right?
There was a problem hiding this comment.
Yes, if this had been 1 group it would have triggered an assert because we do not allow mixed dtypes within a tensorlist (but allow mixing dtypes across tensorlists).
|
Still a bit confusing to me that it appears the code is slower for bf16 vs fp32 in TFLOPs. Did you end up investigating why? I think the memory perf win is good enough to have this land but it'd be good to understand why it's not faster, even if just slightly |
|
@janeyx99 In the TFlops plot, orange (bfloat16) is always same or slightly higher than blue (float32), it will be difficult to see anything better than this from end-to-end TFlops plots because optimizer is only a small part of compute during an iteration. I will try to take some torch traces to extract optimizer compute times, that will give a better picture. Some of the CI jobs are failing, does not look related to changes in PR, can you please help confirm it? If there is an issue due to change in PR I will work on fixing it. |
|
@vivekgoe can you rebase? CI failures do not look related/are about calculating docker images which this PR shouldn;t be touching. And yes it would be good to confirm that the optim step is faster, though yes, slightly higher TFLOPs is a good sign (I had been dumb earlier and misinterpreted the axes) |
|
@janeyx99 I extracted average time for optimizer.step from torch traces (on 8xH100). For float32 it takes 20.59ms whereas for bfloat16 it reduces to 15.29ms, so there is a ~25% reduction, which means we do gain in terms of perf. as well. It's just that for this workload optimizer is not a significant enough contributor to overall compute, therefore it does not show up clearly in end-to-end TFLOP numbers. Rebased PR now. Thanks. |
a403149 to
34662f8
Compare
|
@pytorchbot merge |
|
@vivekgoe can you share the benchmark script in a gist or just a code snippet here? |
|
@pytorchmergebot rebase -b main |
|
@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here |
Introduced a pre-hook to initialize optimizer states in bfloat16 format, allowing for efficient mixed-precision training. Updated tests to verify the correct behavior of the new hook, ensuring it skips already-populated states and maintains dtype consistency across optimizer parameters. Renamed test methods for clarity and improved structure.
Removed the dtype policy logic from the Adam optimizer, streamlining the initialization of state tensors. This change enhances clarity and reduces complexity by directly using the parameter's dtype for state tensors. Additionally, unnecessary dtype checks during the update step have been eliminated, improving performance and maintainability.
Added checks to ensure that parameters and gradients are in float32 while optimizer states are in bfloat16 for mixed-precision training. Updated the fast path restriction checks to allow for mixed-precision states and improved error messages for clarity. Refactored the fused Adam and AdamW implementations to handle these requirements, ensuring compatibility with the new mixed-precision initialization hook. Updated tests to verify the correct behavior of these changes.
Updated the FusedAdam and FusedAdamW implementations to support mixed-precision training by adding a new max_exp_avg_sq_type parameter. Improved state initialization and handling for mixed-precision scenarios, ensuring compatibility with the new requirements. Enhanced tests to verify the correct behavior of mixed-precision state initialization, including checks for max_exp_avg_sq in the optimizer states. Updated error messages for clarity and consistency.
- Replace redundant AT_DISPATCH_FLOATING_TYPES_AND2 on params dtype with
AT_DISPATCH_V2 dispatching on state dtype in all 8 mixed-precision sites
across 4 impl files, since params are already validated as float32
- Extract shared validate_mixed_precision_dtypes() helper into
fused_adam_utils.cuh to deduplicate TORCH_CHECK blocks across impl files
- Rename skip_dtype_check to skip_cross_list_dtype_check and enforce
within-list dtype homogeneity even in mixed-precision mode; only skip
cross-list dtype check conditionally when is_mixed_precision is true
- Fix mutable kwargs bug in test_fused_mixed_precision_numerics
- Use @parametrize for amsgrad in state_init and hook_skips tests
- Reduce test params from 600 to 10 in numerics test
- Document bfloat16-only restriction and [0]-only validation assumption
- Add TBD comment for making grouping dtypes configurable per optimizer
…W kernels - Updated the error messages in the TORCH_CHECK statements to clarify requirements for parameter and gradient types. - Enhanced the check_fast_path_restrictions function by adding a new parameter for skipping cross-list dtype checks. - Improved documentation regarding the mixed-precision configuration for optimizer states. - Cleaned up the test cases for mixed-precision state initialization, ensuring consistency and clarity in assertions.
- Updated the test for mixed-precision optimizers to handle two parameter groups with different state dtypes. - Ensured that the state initialization hook correctly skips already-populated states and initializes others in bfloat16. - Improved clarity in assertions regarding dtype consistency for both parameter groups during optimizer steps.
|
Successfully rebased |
34662f8 to
d5a4e6a
Compare
Added Mixed precision optimizer Fused kernels for Adam/AdamW. Continuation of POC work done by @janeyx99 [Refer to pytorch#146542 (comment) for more details]. Motivation for adding these kernels is to provide a path to users to initialize optimizer states for Adam/AdamW in low-precision from user code and use these Fused kernels to achieve reduced device memory foot-print. TorchTitan example here pytorch/torchtitan#2732 Co-authored-by: Jane (Yuan) Xu <janeyx99> Pull Request resolved: pytorch#175230 Approved by: https://github.com/janeyx99
|
@pytorchbot merge -f "CI failures look preexisting and irrelevant" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Added Mixed precision optimizer Fused kernels for Adam/AdamW. Continuation of POC work done by @janeyx99 [Refer to pytorch#146542 (comment) for more details]. Motivation for adding these kernels is to provide a path to users to initialize optimizer states for Adam/AdamW in low-precision from user code and use these Fused kernels to achieve reduced device memory foot-print. TorchTitan example here pytorch/torchtitan#2732 Co-authored-by: Jane (Yuan) Xu <janeyx99> Pull Request resolved: pytorch#175230 Approved by: https://github.com/janeyx99
This reverts commit c3bd84f. Reverted pytorch#175230 on behalf of https://github.com/atalman due to Failing internal tests ([comment](pytorch#175230 (comment)))
Added Mixed precision optimizer Fused kernels for Adam/AdamW. Continuation of POC work done by @janeyx99 [Refer to pytorch#146542 (comment) for more details]. Motivation for adding these kernels is to provide a path to users to initialize optimizer states for Adam/AdamW in low-precision from user code and use these Fused kernels to achieve reduced device memory foot-print. TorchTitan example here pytorch/torchtitan#2732 Co-authored-by: Jane (Yuan) Xu <janeyx99> Pull Request resolved: pytorch#175230 Approved by: https://github.com/atalman
Added Mixed precision optimizer Fused kernels for Adam/AdamW. Continuation of POC work done by @janeyx99 [Refer to pytorch#146542 (comment) for more details]. Motivation for adding these kernels is to provide a path to users to initialize optimizer states for Adam/AdamW in low-precision from user code and use these Fused kernels to achieve reduced device memory foot-print. TorchTitan example here pytorch/torchtitan#2732 Co-authored-by: Jane (Yuan) Xu <janeyx99> Pull Request resolved: pytorch#175230 Approved by: https://github.com/janeyx99
This reverts commit c3bd84f. Reverted pytorch#175230 on behalf of https://github.com/atalman due to Failing internal tests ([comment](pytorch#175230 (comment)))
Added Mixed precision optimizer Fused kernels for Adam/AdamW. Continuation of POC work done by @janeyx99 [Refer to pytorch#146542 (comment) for more details]. Motivation for adding these kernels is to provide a path to users to initialize optimizer states for Adam/AdamW in low-precision from user code and use these Fused kernels to achieve reduced device memory foot-print. TorchTitan example here pytorch/torchtitan#2732 Co-authored-by: Jane (Yuan) Xu <janeyx99> Pull Request resolved: pytorch#175230 Approved by: https://github.com/atalman

Added Mixed precision optimizer Fused kernels for Adam/AdamW. Continuation of POC work done by @janeyx99 [Refer to https://github.com//issues/146542#issuecomment-2836583889 for more details].
Motivation for adding these kernels is to provide a path to users to initialize optimizer states for Adam/AdamW in low-precision from user code and use these Fused kernels to achieve reduced device memory foot-print. TorchTitan example here pytorch/torchtitan#2732
Co-authored-by: Jane (Yuan) Xu