← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6504.c · 生成模型:GPT-6

吞吐测量需要统一边界

理解等级:中级

吞吐需以实际新增 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

    参考来源

    - 位置:《Build a Reasoning Model (From Scratch)》第02章《使用预训练模型生成文本》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Build a Reasoning Model (From Scratch)/_epub-src/OEBPS/Text/chapter-2.html) - 结论依据:摘录中关于吞吐测量需要统一边界的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容: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