2.3K Star 8K Fork 4.2K

GVPMindSpore / mindspore

 / 详情

[MDT][PERF]resample算子特定场景下性能比不过对标librose

DONE
Bug-Report
创建于  
2022-12-02 15:57
name about labels
Bug Report Use this template for reporting a bug kind/bug

Describe the current behavior / 问题描述 (Mandatory / 必填)

在gcd值(orig_freq和new_freq的最小公约数)偏小的情况下,MindData算子resample的性能比不过对标框架

Environment / 环境信息 (Mandatory / 必填)

  • Hardware Environment(Ascend/GPU/CPU) / 硬件环境:

Please delete the backend not involved / 请删除不涉及的后端:
/device ascend/GPU/CPU/kirin/等其他芯片

  • Software Environment / 软件环境 (Mandatory / 必填):
    -- MindSpore version (e.g., 1.7.0.Bxxx) :commit_id = '[sha1]:e2c89157,[branch]:(HEAD,origin/master,origin/HEAD,master)'
    -- Python version (e.g., Python 3.7.5) :Python 3.7.5
    -- OS platform and distribution (e.g., Linux Ubuntu 16.04):Ubuntu 18.04.6 LTS
    -- GCC/Compiler version (if compiled from source): gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

  • Excute Mode / 执行模式 (Mandatory / 必填)(PyNative/Graph):

Please delete the mode not involved / 请删除不涉及的模式:

Related testcase / 关联用例 (Mandatory / 必填)


import numpy as np
from mindspore import log as logger
import mindspore.dataset as ds
import mindspore.dataset.audio.transforms as audio
from mindspore.dataset.audio.utils import ResampleMethod
import librosa
import time
import torch
import torchaudio.functional
import math
from torch.utils.data import Dataset


def testEagerTorchAudio(input_shape, orig_freq, new_freq):
    waveform = np.random.rand(*input_shape) * 100
    orig_freq = orig_freq
    sleep_time = 10
    new_freq = new_freq
    times2 = 100
    print("waveform.shape", waveform.shape)
    print("orig_freq:", orig_freq)
    print("new_freq:", new_freq)
    print("gcd:", math.gcd(orig_freq, new_freq))
    time.sleep(sleep_time)
    start_time = time.time()
    for i in range(times2):
        audio.Resample(orig_freq=orig_freq, new_freq=new_freq)(waveform)
    end_time = time.time()
    output1 = audio.Resample(orig_freq=orig_freq, new_freq=new_freq)(waveform)
    print("minddata time over ", times2, " runs is ", (end_time - start_time) / times2 * 1000 ** 2, "µs")

    time.sleep(sleep_time)
    times = 100
    start_time = time.time()
    for i in range(times):
        librosa.core.resample(waveform, orig_sr=orig_freq, target_sr=new_freq)
    end_time = time.time()
    print("librosa resample average time over", times, "runs is ", (end_time - start_time) / times * 1000 ** 2, "µs")

    time.sleep(sleep_time)
    waveform2 = torch.from_numpy(waveform)
    start_time = time.time()

    times3 = 1
    for i in range(times3):
        torchaudio.functional.resample(waveform2, orig_freq=orig_freq, new_freq=new_freq)
    end_time = time.time()
    output3 = torchaudio.functional.resample(waveform2, orig_freq=orig_freq, new_freq=new_freq)
    output3 = output3.detach().numpy()
    print("pytorch time over ", times3, "runs is ", (end_time - start_time) / times3 * 1000 ** 2, "µs")
    print(abs(output3 - output1))
    assert (np.all(output1 - output3 < 1e-5))

if __name__ == '__main__':
    

if __name__ == '__main__':
    test_data = [{"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 160000},
                 {"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 48000},
                 {"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 8000},
                 {"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 11000},
                 {"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 500},
                 {"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 11025},
                 {"waveform": (1000, 1000), "orig_freq": 16000, "new_freq": 11005},
                 {"waveform": (1000, 1000), "orig_freq": 22050, "new_freq": 44100},
                 {"waveform": (1000, 1000), "orig_freq": 22050, "new_freq": 11025},
                 {"waveform": (1000, 1000), "orig_freq": 22050, "new_freq": 500},
                 {"waveform": (1000, 1000), "orig_freq": 22050, "new_freq": 11005},
                 {"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 160000},
                 {"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 48000},
                 {"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 8000},
                 {"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 11000},
                 {"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 500},
                 {"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 11025},
                 {"waveform": (17, 12345), "orig_freq": 16000, "new_freq": 11005},
                 {"waveform": (16560,), "orig_freq": 24000, "new_freq": 48000},
                 {"waveform": (16560,), "orig_freq": 24000, "new_freq": 16000},
                 {"waveform": (16560,), "orig_freq": 24000, "new_freq": 1600},
                 {"waveform": (16560,), "orig_freq": 24000, "new_freq": 11025},
                 {"waveform": (16560,), "orig_freq": 24000, "new_freq": 11005},
                 {"waveform": (7432986,), "orig_freq": 16000, "new_freq": 48000},
                 {"waveform": (7432986,), "orig_freq": 16000, "new_freq": 24000},
                 {"waveform": (7432986,), "orig_freq": 16000, "new_freq": 1600},
                 {"waveform": (7432986,), "orig_freq": 16000, "new_freq": 11025},
                 {"waveform": (241840,), "orig_freq": 16000, "new_freq": 48000},
                 {"waveform": (241840,), "orig_freq": 16000, "new_freq": 24000},
                 {"waveform": (241840,), "orig_freq": 16000, "new_freq": 1600},
                 {"waveform": (241840,), "orig_freq": 16000, "new_freq": 11025},
                 {"waveform": (241840,), "orig_freq": 16000, "new_freq": 11005},
                 {"waveform": (2, 125800), "orig_freq": 22050, "new_freq": 11025},
                 {"waveform": (2, 125800), "orig_freq": 22050, "new_freq": 44100},
                 ]
    for data in test_data:
        testEagerTorchAudio(input_shape=data["waveform"], orig_freq=data["orig_freq"], new_freq=data["new_freq"])

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

修改参数值,执行脚本

Describe the expected behavior / 预期结果 (Mandatory / 必填)

minddata time < librose time

Related log / screenshot / 日志 / 截图 (Mandatory / 必填)

见附件

Special notes for this issue/备注 (Optional / 选填)

附件

评论 (6)

曾小龙 创建了Bug-Report
曾小龙 添加了
 
sig/minddata
标签
曾小龙 添加了
 
attr/performance
标签
曾小龙 添加了
 
kind/bug
标签
曾小龙 添加了
 
stage/func-debug
标签
曾小龙 添加了
 
v2.0.0.rc1
标签
展开全部操作日志

Please assign maintainer to check this issue.
请为此issue分配处理人。
@曾小龙

Please add labels (comp or sig), also you can visit https://gitee.com/mindspore/community/blob/master/sigs/dx/docs/labels.md to find more.
为了让代码尽快被审核,请您为Pull Request打上 组件(comp)或兴趣组(sig) 标签,打上标签的PR可直接推送给责任人进行审核。
更多的标签可以查看https://gitee.com/mindspore/community/blob/master/sigs/dx/docs/labels.md
以组件相关代码提交为例,如果你提交的是data组件代码,你可以这样评论:
//comp/data
当然你也可以邀请data SIG组来审核代码,可以这样写:
//sig/data
另外你还可以给这个PR标记类型,例如是bugfix或者是特性需求:
//kind/bug or //kind/feature
恭喜你,你已经学会了使用命令来打标签,接下来就在下面的评论里打上标签吧!

@xiaotianci 后续回归转给hanshunping

此需求为媒体院提出,现有优化能够满足他们的网络运行场景,gcd较小的场景不常见,暂不做处理。

该场景下性能对比情况如下
输入图片说明

xiaotianci 添加了
 
rct/newfeature
标签
xiaotianci 添加了
 
rca/others
标签
xiaotianci 添加了
 
ctl/personalbuild
标签
xiaotianci 里程碑B-SIG-Data 修改为B-MDT
xiaotianci 添加协作者xiaotianci
xiaotianci 负责人xiaotianci 修改为韩顺平
xiaotianci 任务状态TODO 修改为VALIDATION

回归时间:2023.0103
回归版本:mindspore-2.0.0-0102
回归步骤:按照问题单中步骤回归检查
回归结果:执行用例,mindspore性能优于librosa
回归结论:回归通过

韩顺平 任务状态VALIDATION 修改为DONE

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(6)
Python
1
https://gitee.com/mindspore/mindspore.git
git@gitee.com:mindspore/mindspore.git
mindspore
mindspore
mindspore

搜索帮助