知识卡片
吞吐测量需要统一边界
吞吐需以实际新增 token 数除以测量区间,并统一是否包含预填充、编译和输出处理。GPU 异步执行时还应考虑同步,否则墙钟边界可能不对应已完成计算。原书统计函数是教学工具,其结果不能脱离设备、批量、长度和预热条件比较。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
tokenizer, start_time, end_time, print_tokens=True): total_time = end_time - start_time print(f"Time: {total_time:.2f} sec") print(f"{int(output_token_ids.numel() / total_time)} tokens/sec") for name, backend in (("CUDA", getattr(torch, "cuda", None)), ("XPU", getattr(torch, "xpu", None))): if backend is not None and backend.is_available(): max_mem_bytes = backend.max_memory_allocated() max_mem_gb = max_mem_bytes / (1024 ** 3) print(f"Max {name} memory allocated: {max_mem_gb:.2f} GB") backend.reset_peak_memory_stats() if print_tokens: output_text = tokenizer.decode(output_token_ids.squeeze(0).tolist()) print(f"\n{output_text}") The generate_stats function in listing 2.3 will