[Embedding] Add inf-cl in embedding trainer#9673
Merged
Merged
Conversation
|
Thanks for your contribution! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9673 +/- ##
===========================================
- Coverage 53.18% 52.76% -0.43%
===========================================
Files 718 718
Lines 113340 112338 -1002
===========================================
- Hits 60282 59276 -1006
- Misses 53058 53062 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ZHUI
reviewed
Dec 23, 2024
| __all__ = ["Simple_Inf_cl_loss", "Matryoshka_Inf_cl_loss"] | ||
|
|
||
|
|
||
| class Simple_Inf_cl_loss(nn.Layer): |
| from paddle.base import core | ||
| from paddle.distributed import fleet | ||
|
|
||
| from ops.src.paddlenlp_kernel.triton.inf_cl.inf_cl_loss import ( |
Contributor
There was a problem hiding this comment.
Suggested change
| from ops.src.paddlenlp_kernel.triton.inf_cl.inf_cl_loss import ( | |
| from paddlenlp_kernel.triton.inf_cl.inf_cl_loss import ( |
ZHUI
reviewed
Dec 23, 2024
| from paddle.base import core | ||
| from paddle.distributed import fleet | ||
|
|
||
| from ops.src.paddlenlp_kernel.triton.inf_cl.inf_cl_loss import ( |
ZHUI
reviewed
Dec 24, 2024
| group_size = p_reps.shape[0] // q_reps.shape[0] # Number of keys per query | ||
| labels = paddle.arange(q_reps.shape[0], dtype="int64") # Generate labels for queries | ||
| labels = labels * group_size # Adjust labels based on group size | ||
| loss = cal_inf_loss(q_reps, p_reps, labels=labels, scale=None, head_dim=self.head_dim) |
Contributor
There was a problem hiding this comment.
你把import 的代码放到这里吧, 然后没有包的话,直接报错。
try:
from paddlenlp_kernel.triton.inf_cl import cal_inf_loss
except ImportError:
logger.warning(
"Paddlenlp_kernels are not available, which means the inf_cl loss cannot be used. If you wish to use the inf_cl loss, please follow the instructions in the README.md on the `ops`."
)
DesmonDay
approved these changes
Dec 25, 2024
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.
PR types
Function optimization
PR changes
Others
Description
在embedding训练中增加inf_cl_loss,在超大batch_size下能有效节省显存消耗。
经测试,inf-cl算子能够与原有损失函数有效对齐:
经测试,在超大batch_size下,inf-cl算子能够有效降低embedding训练时的显存消耗:
42526MiB;42470MiB;
42470MiB;42526MiB;
42526MiB;42182MiB
28372MiB;28308MiB;
28320MiB;28384MiB;
28316MiB;28070MiB
44926MiB;45180MiB;
44674MiB;45022MiB;
45032MiB;44904MiB