add anno
This commit is contained in:
1 parent
a747ca26ea
commit
9dc91c262e
3 files changed
+117
-4
No files matched your search
@@ -287,15 +287,30 @@ class GPT(nn.Module):
|
||||
return optimizer
|
||||
|
||||
def estimate_mfu(self, fwdbwd_per_iter, dt):
|
||||
""" estimate model flops utilization (MFU) in units of A100 bfloat16 peak FLOPS """
|
||||
""" 估计MFU (模型每秒的浮点运算次数, Model FLOPS Utilization), 以A100 bfloat16峰值浮点运算次数为基准
|
||||
1. 首先估计每一步的浮点运算次数
|
||||
2. 然后乘以每秒的迭代次数
|
||||
3. 最后除以A100 bfloat16峰值浮点运算次数
|
||||
"""
|
||||
|
||||
# first estimate the number of flops we do per iteration.
|
||||
# see PaLM paper Appendix B as ref: https://arxiv.org/abs/2204.02311
|
||||
# 获取模型参数量
|
||||
N = self.get_num_params()
|
||||
cfg = self.config
|
||||
L, H, Q, T = cfg.n_layer, cfg.n_head, cfg.n_embd//cfg.n_head, cfg.block_size
|
||||
|
||||
# 计算每个token的浮点运算次数
|
||||
# 6*N: 每个参数在前向和后向传播中的计算次数。(前向1次乘法, 反向2次乘法-链式法则,参数更新1次, 梯度计算2次)
|
||||
# 12*L*H*Q*T: 每个注意力头中的运算次数 6次 x 前向后向 2次
|
||||
flops_per_token = 6*N + 12*L*H*Q*T
|
||||
|
||||
# 考虑序列长度T
|
||||
flops_per_fwdbwd = flops_per_token * T
|
||||
|
||||
# 考虑每秒的迭代次数
|
||||
flops_per_iter = flops_per_fwdbwd * fwdbwd_per_iter
|
||||
|
||||
# express our flops throughput as ratio of A100 bfloat16 peak flops
|
||||
flops_achieved = flops_per_iter * (1.0/dt) # per second
|
||||
flops_promised = 312e12 # A100 GPU bfloat16 peak flops is 312 TFLOPS
|
||||
|
||||
Reference in new issue
Block a user