Add custom multi_tensor_apply kernels (L2norm, Adam)#585
Draft
matthiasdiener wants to merge 2 commits into
Draft
Add custom multi_tensor_apply kernels (L2norm, Adam)#585matthiasdiener wants to merge 2 commits into
matthiasdiener wants to merge 2 commits into
Conversation
alextmagro
reviewed
May 16, 2026
| template <int N, typename T> | ||
| __device__ __forceinline__ void load_store_n(T *dst, const T *src, | ||
| int dst_offset, int src_offset) { | ||
| typedef typename std::aligned_storage<N * sizeof(T), N * alignof(T)>::type LT; |
Contributor
There was a problem hiding this comment.
We already have some load store functions that are optimal for rocm here -- Can we reuse them?
Contributor
There was a problem hiding this comment.
P.S., this also has some other utils that come in handy for us.
|
|
||
| TRANSFORMER_ENGINE_TYPE_SWITCH_NON_FP8ONLY( | ||
| grad_dtype, grad_type, | ||
| if (mode == ADAM_MODE_0) { |
Contributor
There was a problem hiding this comment.
We can use TRANSFORMER_ENGINE_SWITCH_CONDITION here I think
| #pragma unroll | ||
| for (int ii = 0; ii < CILP; ii++) { | ||
| if (MODE == ADAM_MODE_0) { // L2 | ||
| r_g[ii] = r_g[ii] + (decay * r_p[ii]); |
Contributor
There was a problem hiding this comment.
+= here for readability
| param_dtype, p_type, | ||
| TRANSFORMER_ENGINE_TYPE_SWITCH_NON_FP8ONLY( | ||
| grad_dtype, g_type, | ||
| if (mode == ADAM_MODE_0) { |
Contributor
There was a problem hiding this comment.
Same, can use TRANSFORMER_ENGINE_SWITCH_CONDITION here
| LAUNCH_CUSTOM_ADAM(g_type, p_type, ADAM_MODE_0, true); | ||
| } else { | ||
| LAUNCH_CUSTOM_ADAM(g_type, p_type, ADAM_MODE_1, true); | ||
| };);); |
Contributor
There was a problem hiding this comment.
Add NOLINT here and at the all of our macro switches
| @@ -1 +1 @@ | |||
| /************************************************************************* | |||
| @@ -1,2 +1,2 @@ | |||
| /************************************************************************* | |||
| * Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |||
| @@ -1,2 +1,2 @@ | |||
| /************************************************************************* | |||
| * Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |||
| @@ -1 +1 @@ | |||
| # Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | |||
| multi_tensor_scale, | ||
| multi_tensor_l2norm, | ||
| multi_tensor_unscale_l2norm, | ||
| multi_tensor_scale as _multi_tensor_scale, |
Contributor
There was a problem hiding this comment.
These changes should be hip guarded I think
alextmagro
requested changes
May 16, 2026
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.
Description
Fixes https://github.com/ROCm/frameworks-internal/issues/16529
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: