English

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

Machine Learning 2025-04-08 v1 Artificial Intelligence Computation and Language

Abstract

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.

Cite

@article{arxiv.2504.04520,
  title  = {Hessian of Perplexity for Large Language Models by PyTorch autograd (Open Source)},
  author = {Ivan Ilin},
  journal= {arXiv preprint arXiv:2504.04520},
  year   = {2025}
}

Comments

15 pages, 3 figures, open source code on GitHub

R2 v1 2026-06-28T22:48:37.695Z