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

CUDA推理结果有问题 #13

Open
Ivy233 opened this issue Sep 12, 2024 · 11 comments
Open

CUDA推理结果有问题 #13

Ivy233 opened this issue Sep 12, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@Ivy233
Copy link

Ivy233 commented Sep 12, 2024

音频来源:iic/SenseVoiceSmall模型,examples/zh.mp3
用ffmpeg转成-ar 16000的wav。
CPU推理的结果:
image
GPU(4080Super)推理的结果:
image
nvidia-smi信息:
image

@lovemefan
Copy link
Owner

CUDA适配包括Metal适配都卡在某一个算子上了,适配好了会在这个issue留言并发布release

@lovemefan lovemefan added the bug Something isn't working label Sep 12, 2024
@Ivy233
Copy link
Author

Ivy233 commented Sep 23, 2024

问一手,现在有进展吗()

@lovemefan
Copy link
Owner

问一手,现在有进展吗()

最近忙了点😂,国庆尝试修复下

@Ivy233
Copy link
Author

Ivy233 commented Sep 25, 2024

对照--no-gpu,目前已经确认到有三个地方有问题:

  1. sense-voice-encoder.cpp那边encoder_layer_sanm_forward里,一开始的USE_CUDA对于norm的处理有问题,自己的代码已经修复这个问题。检测了几个值是完全一样的,先放一边了。
  2. 第一层后续的QKV矩阵乘法中,对照发现会有0.001的误差,由于后续内容的存在,目前无法确认是否因为这个导致输出乱码,不过个人认为影响不是很大,除非后面的错误修复后还有乱码否则不考虑这个。
  3. fsmn中的im2col基本确认是有问题的,似乎没有正确运行(具体原因还需要还在查)。

@lovemefan
Copy link
Owner

我是通过放开下面代码注释,打印tensor里面的值来对比的

// ggml_backend_sched_set_eval_callback(sched, ctx.params.cb_eval, ctx.params.cb_eval_user_data);

  1. 由于第一层的norm的维度为560,560不是32的倍数,在ggml中会报错,后续通过pad均值到576(32的倍数),可正常计算。是否还有其他错误,如有欢迎指出或pr
  2. 精度方面有一点损失,不是乱码主要原因。
  3. 主要原因是im2col算子的问题,该问题在metal和cuda都存在。我在官方提了issue, 但是还没有回复,我个人排查起来非常困难。

@Ivy233
Copy link
Author

Ivy233 commented Sep 25, 2024

第三点+1,简直有毒,要不手写?
第一点不是因为norm的32倍数问题,在扩展后,norm的560变成了576,对应的标准差也需要做缩放变换,表现在代码上是在计算最后加一个scale,倍率就是sqrt(576/560)。

@lovemefan
Copy link
Owner

lovemefan commented Sep 25, 2024

norm没有注意到有个scale,感谢指出。im2col我看看再排查一下,先看看官方能不能修复,实在不行再想办法手写吧

@Ivy233
Copy link
Author

Ivy233 commented Sep 26, 2024

第一点pr已经提了,注释内和没注释的都是可以跑的,都可以测一下。

@Ivy233
Copy link
Author

Ivy233 commented Oct 6, 2024

今天是修好了吗,我今天up之后发现看起来结果正常了。想问下是怎么解决的?

@lovemefan
Copy link
Owner

我把im2col算子单独放在cpu上计算,虽然相比全放在gpu上损失了部分速度,im2col能够跑通了。但是我自己测试在V100没跑通😂,cuda上的softmax出现nan了,所以没发release。

@lovemefan
Copy link
Owner

CUDA 12.0测试正常,最新 CUDA 12.6出现nan,等官方修复了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants