arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2504.04520cs.LGcs.AIcs.CL
收藏

利用 PyTorch autograd 计算大语言模型困惑度的 Hessian 矩阵(开源)

Hessian of Perplexity for Large Language Models by PyTorch autograd (Open Source)

Ivan Ilin

AI总结:

本文提供基于 PyTorch autograd 计算大语言模型部分 Hessian 矩阵及完整对角线的实用指南,并开源代码以帮助研究者理解 LLM 中 Hessian 的行为与结构。

摘要:

计算完整 Hessian 矩阵——即整个大语言模型(LLM)的二阶导数矩阵——由于其规模过于庞大而不可行。在本技术报告中,我们旨在提供一份全面指南,说明如何使用 PyTorch autograd 库准确计算 LLM 的至少一小部分 Hessian。我们还演示了如何使用多个向量-Hessian 乘积(HVP)样本来计算 Hessian 矩阵的完整对角线。我们希望本指南及随附的 GitHub 代码能成为实践者和研究人员的宝贵资源,帮助他们更好地理解 LLM 中 Hessian 的行为与结构。

英文摘要:

Computing the full Hessian matrix -- the matrix of second-order derivatives for an entire Large Language Model (LLM) is infeasible due to its sheer size. In this technical report, we aim to provide a comprehensive guide on how to accurately compute at least a small portion of the Hessian for LLMs using PyTorch autograd library. We also demonstrate how to compute the full diagonal of the Hessian matrix using multiple samples of vector-Hessian Products (HVPs). We hope that both this guide and the accompanying GitHub code will be valuable resources for practitioners and researchers interested in better understanding the behavior and structure of the Hessian in LLMs.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑