gpt4 book ai didi

gpu - `exp` 的计算成本如何?

转载 作者:行者123 更新时间:2023-12-05 04:16:30 33 4
gpt4 key购买 nike

我目前正在听一个关于自动语音识别 (ASR) 的讲座。最后一讲是关于矢量量化(VQ)和k最近邻(kNN)以及二叉树和高斯混合模型(GMMs)。

据讲师介绍,VQ只是通过计算GMM的一个近似值来加速GMM的评估。这是通过在 GMM 中找到具有最高值的高斯并向上查找该向量的值(从先前构建的字典中存储为二叉树)来完成的。每个 GMM 有大约 42 个高斯分布。根据讲师的说法,这应该会加快计算速度,因为计算 e 函数(exp,自然指数函数)的计算量很大。

我很好奇这是否(仍然)是真的,搜索了 Python 实现并找到了 this answer这说明 exp 是由硬件计算的。

如今的 CPU(和 GPU)非常复杂,我对它们的了解非常有限。 exp 比例如 float 、加法或乘法的比较。

问题

  • 与 float 比较、加法、乘法和类似的基本命令相比,exp 的开销如何?
  • 我最终是否理解了为什么 VQ 在 ASR 中完成的错误?

实验评估

我试图通过开始实验来获得结果。但是我很难消除其他因使我的数字出错而造成的影响(例如缓存、变量查找时间、随机数生成器的时间……)。

目前,我有

#!/usr/bin/env python

import math
import time
import random

# Experiment settings
numbers = 5000000
seed = 0
repetitions = 10

# Experiment
random.seed(seed)
values = [random.uniform(-5, 5) for _ in range(numbers)]
v2 = [random.uniform(-5, 5) for _ in range(numbers)]

# Exp
for i in range(repetitions):
t0 = time.time()
ret = [math.exp(x) for x in values]
t1 = time.time()
time_delta = t1 - t0
print("Exp time: %0.4fs (%0.4f per second)" % (time_delta, numbers/time_delta))

# Comparison
for i in range(repetitions):
t0 = time.time()
ret = [x+y for x, y in zip(values, v2)]
t1 = time.time()
time_delta = t1 - t0
print("x+y time: %0.4fs (%0.4f per second)" % (time_delta, numbers/time_delta))

但我猜 zip 使这个失败,因为结果是:

Exp time: 1.3640s (3665573.5997 per second)
Exp time: 1.7404s (2872978.6149 per second)
Exp time: 1.5441s (3238178.6480 per second)
Exp time: 1.5161s (3297876.5227 per second)
Exp time: 1.9912s (2511009.5658 per second)
Exp time: 1.3086s (3820818.9478 per second)
Exp time: 1.4770s (3385254.5642 per second)
Exp time: 1.5179s (3294040.1828 per second)
Exp time: 1.3198s (3788392.1744 per second)
Exp time: 1.5752s (3174296.9903 per second)
x+y time: 9.1045s (549179.7651 per second)
x+y time: 2.2017s (2270981.5582 per second)
x+y time: 2.0781s (2406097.0233 per second)
x+y time: 2.1386s (2338005.6240 per second)
x+y time: 1.9963s (2504681.1570 per second)
x+y time: 2.1617s (2313042.3523 per second)
x+y time: 2.3166s (2158293.4313 per second)
x+y time: 2.2966s (2177155.9497 per second)
x+y time: 2.2939s (2179730.8867 per second)
x+y time: 2.3094s (2165055.9488 per second)

最佳答案

According to the lecturer, VQ is used to speed up the evaluation of GMMs by just calculating an approximate value of the GMM. This is done by finding the gaussian in a GMM which would have the highest value and looking the value of this vector up (from a previously built dictionary, stored as a binary tree). Each GMM has about 42 gaussians.

这是正确的描述。您可以在以下论文中找到对最优高斯计算的有趣描述:

George Saon、Daniel Povey 和 Geoffrey Zweig,“极快 LVCSR 解码器的剖析”,Interspeech 2005。 http://www.danielpovey.com/files/eurospeech05_george_decoder.pdf

似然计算部分

According to the lecturer, this should speed the calculation up, because the calculation of the e-function (exp, natural exponential function) is computationally expensive.

这部分你可能误解了讲师。 exp 不是一个非常重要的问题。由于其他原因,高斯计算非常昂贵:每帧有数千个高斯得分,每个帧有几十个组件,每个组件有 40 个 float 。由于需要提供和存储的内存量,处理所有这些数据的成本很高。高斯选择在这里有助于将高斯数量减少几倍,从而加快计算速度。

使用 GPU 是解决此问题的另一种方法。通过将评分转移到 GPU,您可以显着加快评分速度。然而,HMM 搜索存在一个问题,即它不容易并行化。这是解码的另一个重要部分,即使您将得分降低为零,由于搜索,解码仍然会很慢。

Exp time: 1.5752s (3174296.9903 per second) x+y time: 9.1045s (549179.7651 per second)

这不是一个有意义的比较。您在这里忽略了很多事情,例如 Python zip 调用的成本(izip 更好)。通过这种方式,您可以轻松地展示任何结果。

关于gpu - `exp` 的计算成本如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27280327/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com