Skip to content
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

[Hackathon 7th No.56] 在 PaddleSpeech 中复现 DAC 训练需要用到的 loss #3954

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Copy link

paddle-bot bot commented Dec 17, 2024

Thanks for your contribution!

@suzakuwcx
Copy link
Author

suzakuwcx commented Dec 17, 2024

In the original DAC repository, the training data is generated randomly. To assess accuracy, I sampled ten loss values and saved them in PyTorch tensor (.pt) format. The original repository showed no numerical errors, but in the Paddle implementation, bias is observed and I still tracing it . Here is the test result

index AudioSignal_STFT AudioSignal_MEL Tensor_STFT Tensor_MEL
0 2.86102294921875e-06 9.5367431640625e-07 6.103515625e-05 6.198883056640625e-05
1 9.5367431640625e-07 4.76837158203125e-07 6.103515625e-05 0.000194549560546875
2 0.0 9.5367431640625e-07 3.0517578125e-05 0.0005588531494140625
3 9.5367431640625e-07 4.76837158203125e-07 2.09808349609375e-05 4.9114227294921875e-05
4 4.76837158203125e-07 4.76837158203125e-07 0.00012445449829101562 7.05718994140625e-05
5 4.76837158203125e-06 0.0 0.03401947021484375 0.012701988220214844
6 4.76837158203125e-07 9.5367431640625e-07 0.00014448165893554688 0.0003781318664550781
7 3.814697265625e-06 9.5367431640625e-07 0.2675790786743164 0.03282880783081055
8 9.5367431640625e-07 0.0 0.22318553924560547 0.03190279006958008
9 2.384185791015625e-06 0.0 0.22658443450927734 0.03314781188964844

@suzakuwcx
Copy link
Author

suzakuwcx commented Dec 18, 2024

With these patch, the new test result is below

diff --git a/paddlespeech/t2s/modules/losses.py b/paddlespeech/t2s/modules/losses.py
index 029ad1be..ce5f441d 100644
--- a/paddlespeech/t2s/modules/losses.py
+++ b/paddlespeech/t2s/modules/losses.py
@@ -501,7 +502,7 @@ def stft(x,
     real = x_stft.real()
     imag = x_stft.imag()
 
-    return paddle.sqrt(paddle.clip(real**2 + imag**2, min=1e-7)).transpose(
+    return paddle.clip(paddle.sqrt(real**2 + imag**2), min=clamp_eps).transpose(
         [0, 2, 1])

@@ -930,7 +930,7 @@ class MelSpectrogram(nn.Layer):
         real = real.transpose([0, 2, 1])
         imag = imag.transpose([0, 2, 1])
         x_power = real**2 + imag**2
-        x_amp = paddle.sqrt(paddle.clip(x_power, min=self.eps))
+        x_amp = paddle.clip(paddle.sqrt(x_power), min=self.eps)
index Tensor_STFT Tensor_MEL
0 2.86102294921875e-06 9.5367431640625e-07
1 9.5367431640625e-07 4.76837158203125e-07
2 9.5367431640625e-07 9.5367431640625e-07
3 9.5367431640625e-07 4.76837158203125e-07
4 4.76837158203125e-07 4.76837158203125e-07
5 3.814697265625e-06 0.0
6 0.0 9.5367431640625e-07
7 2.86102294921875e-06 4.76837158203125e-06
8 0.0 1.430511474609375e-06
9 2.384185791015625e-06 4.76837158203125e-07

@zxcd
Copy link
Collaborator

zxcd commented Dec 19, 2024

开发者你好,感谢你的参与!由于你的黑客松赛题完成度较高,其PR已被锁定,请尽快完善锁定的PR,并确保在2025年1月3日前完成合入。逾期未合入PR将无法获得奖金发放。

…n calculation methods

- Change precision threshold to ’1e-5‘
- Use relative error instead of absolute error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants