Skip to content

新增MultiLabelMarginLoss #73538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 9, 2025
Merged

Conversation

Qin-sx
Copy link
Contributor

@Qin-sx Qin-sx commented Jun 22, 2025

PR Category

User Experience

PR Types

Improvements

Description

当前问题
目前paddle没有MultiLabelMarginLoss

解决方案
新增MultiLabelMarginLoss

	modified:   python/paddle/nn/__init__.py
	modified:   python/paddle/nn/functional/__init__.py
	modified:   python/paddle/nn/functional/loss.py
	modified:   python/paddle/nn/layer/__init__.py
	modified:   python/paddle/nn/layer/loss.py
	new file:   test/legacy_test/test_multilabelmarginloss.py
Copy link

paddle-bot bot commented Jun 22, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Jun 22, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jun 22, 2025

Codecov Report

Attention: Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (develop@a926cd3). Learn more about missing BASE report.

Files with missing lines Patch % Lines
python/paddle/nn/functional/loss.py 94.44% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #73538   +/-   ##
==========================================
  Coverage           ?   95.74%           
==========================================
  Files              ?        2           
  Lines              ?       47           
  Branches           ?        0           
==========================================
  Hits               ?       45           
  Misses             ?        2           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

	modified:   test/legacy_test/CMakeLists.txt
	modified:   test/legacy_test/test_multilabelmarginloss.py
@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jun 23, 2025

docs: PaddlePaddle/docs#7331

sample_loss = paddle.zeros([], dtype=input.dtype)

# check each position for valid label
for j in range(dim):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的公式看起来比multi_label_soft_margin_loss要复杂很多,使用的n*n复杂度计算,对性能的影响也比较大,单测超时了。

这里与multi_label_soft_margin_loss的公式差异很大吗,能否有更简洁高效的实现

infoflow 2025-06-23 11-43-38

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,收到,因为静态图无法用if else,所以修改了很多,那我改成底层的cpp和cuda实现吧

Copy link

paddle-ci-bot bot commented Jul 1, 2025

Sorry to inform you that abd1da5's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jul 3, 2025

已修改一版新的函数

@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jul 4, 2025

CI报错:

2025-07-04 08:19:58 /paddle/paddle/phi/kernels/funcs/fft_fill_conj.h(163): error: identifier "ctx" is undefined
2025-07-04 08:19:58           detected during instantiation of "void phi::FFTR2CKernel<T,Context>(const Context &, const phi::DenseTensor &, const std::vector<int64_t, std::allocator<int64_t>> &, const std::__cxx11::string &, __nv_bool, __nv_bool, phi::DenseTensor *) [with T=float, Context=phi::GPUContext]" 
2025-07-04 08:19:58 /paddle/paddle/phi/kernels/gpu/fft_kernel.cu(34): here
2025-07-04 08:19:58 
2025-07-04 08:19:58 /paddle/paddle/phi/kernels/funcs/fft_fill_conj.h(163): error: type name is not allowed
2025-07-04 08:19:58           detected during instantiation of "void phi::FFTR2CKernel<T,Context>(const Context &, const phi::DenseTensor &, const std::vector<int64_t, std::allocator<int64_t>> &, const std::__cxx11::string &, __nv_bool, __nv_bool, phi::DenseTensor *) [with T=float, Context=phi::GPUContext]" 
2025-07-04 08:19:58 /paddle/paddle/phi/kernels/gpu/fft_kernel.cu(34): here

应该和pr修改部分无关

猜测可能和这个pr有关

@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jul 4, 2025

PaConvert: PaddlePaddle/PaConvert#599
Docs: PaddlePaddle/docs#7331

@@ -1247,3 +1247,4 @@ set_tests_properties(test_imperative_selected_rows_to_lod_tensor
PROPERTIES TIMEOUT 200)
set_tests_properties(test_slice_op PROPERTIES TIMEOUT 120)
set_tests_properties(test_load_state_dict_from_url PROPERTIES TIMEOUT 40)
set_tests_properties(test_multimarginloss PROPERTIES TIMEOUT 120)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前的API性能如何?这个目前还会超时吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,收到,已修改,等CI测试之后再看一下

@Qin-sx
Copy link
Contributor Author

Qin-sx commented Jul 8, 2025

本地测试时间

Ran 4 tests in 0.192s

Copy link
Contributor

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@luotao1 luotao1 merged commit 8a79a1c into PaddlePaddle:develop Jul 9, 2025
70 of 73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants