GraSS: Scalable Data Attribution with Gradient Sparsification and Sparse Projection

Pingbang Hu, Joseph Melkonian, Weijing Tang, Han Zhao, Jiaqi W. Ma

TL;DR

Gradient-based data attribution helps us understand which training examples influence a model's predictions, but it is notoriously slow and memory-hungry for large models. This paper introduces GraSS and its variant FactGraSS, novel algorithms that exploit the natural sparsity of per-sample gradients to compress them efficiently. By combining gradient sparsification with sparse random projections, FactGraSS achieves up to 165% faster throughput on billion-parameter LLMs compared to prior state-of-the-art methods, without sacrificing attribution quality.

The Bottleneck in Data Attribution

As machine learning models grow, understanding why they make certain predictions becomes increasingly difficult. Data attribution methods, like influence functions, trace a model's behavior back to specific training data points. This is incredibly useful for curating datasets, tracing facts, or compensating data creators.

However, gradient-based attribution methods require computing and storing a per-sample gradient—the gradient of the loss with respect to the model's parameters for every single training example. For a model with $p$ parameters and $n$ training samples, this requires $O(np)$ memory and compute. For Large Language Models (LLMs), this is a massive bottleneck.

To fix this, researchers typically use random projections to compress these massive gradients into smaller vectors. But standard projection methods require dense matrix multiplications, which are still computationally heavy. Even recent optimized methods (like LOGRA) don't take advantage of a crucial fact: per-sample gradients are naturally full of zeros (sparse). This paper asks: How can we exploit the inherent sparsity of per-sample gradients to make data attribution fast and scalable enough for LLMs?

Methods: GraSS and FactGraSS

The authors propose a two-stage compression pipeline called GraSS (Gradient Sparsification and Sparse projection), along with a highly optimized variant for linear layers called FactGraSS.

  1. Sparsification (Masking): Instead of processing the whole gradient, GraSS first aggressively drops parameters. It uses either a "Random Mask" (randomly selecting a subset of dimensions) or a "Selective Mask" (learning which dimensions are most important via a lightweight optimization step). This reduces the problem size immediately.
  2. Sparse Projection (SJLT): The remaining dimensions are compressed using the Sparse Johnson-Lindenstrauss Transform (SJLT). Unlike dense random projections, SJLT uses a projection matrix that is mostly zeros, drastically cutting down multiply-add operations.
Sparse Johnson-Lindenstrauss Transform (SJLT) projection mechanism mapping a sparse gradient to a lower-dimensional space.
  1. FactGraSS (Factorized GraSS): In linear layers, a weight gradient is the outer product (Kronecker product) of the layer's input and its output gradient. FactGraSS applies the sparsification step to the input and output vectors before they are multiplied together. This means the massive full gradient is never actually materialized in memory, saving enormous amounts of time and RAM.

Key Insights

  • Sparsity is a per-sample superpower: Modern activation functions like ReLU naturally zero out many values. During standard training, we use mini-batches, which average out and destroy this sparsity. But because data attribution requires per-sample gradients, this extreme sparsity is preserved and ripe for exploitation.
  • Sub-linear complexity is achievable: By applying a mask before projecting, GraSS achieves sub-linear time and space complexity relative to the total number of model parameters. You don't need to look at every parameter to get a good estimate of its influence.
  • Factorization is a cheat code for memory: The biggest bottleneck in LLM attribution is just holding the gradient in memory. FactGraSS proves that by compressing the mathematical factors of the gradient rather than the gradient itself, you can bypass the memory bottleneck entirely.

Results and Performance

The authors evaluated their methods across a variety of modalities and scales, including MNIST, CIFAR2, MAESTRO, WikiText, and OpenWebText.

  • Speed vs. Fidelity: On smaller models (ResNet9, Music Transformer), GraSS achieves competitive Linear Datamodeling Scores (LDS—a metric for how well the attribution works) while running significantly faster than baseline projection methods like FJLT.
  • Massive Speedups on LLMs: On GPT2-small, FactGraSS achieved up to a 250% speedup over LOGRA, the previous state-of-the-art for efficient influence functions.
  • Billion-Scale Scalability: When applied to Llama-3.1-8B, FactGraSS achieved 165% faster compression throughput than LOGRA.
  • Qualitative Accuracy: When prompting Llama-3.1-8B about "data privacy," FactGraSS successfully identified highly relevant training documents (e.g., texts discussing GDPR and journalist jailings) as the most influential data points, proving the compression doesn't destroy the semantic usefulness of the attribution.

Limitations and Hardware Quirks

While SJLT is theoretically fast, naive PyTorch implementations suffer from race conditions and thread contention when the target compression dimension is small. To realize the theoretical speedups, the authors had to build a custom CUDA kernel.

Performance comparison showing the custom CUDA SJLT kernel achieving significantly lower projection time compared to PyTorch and Gaussian baselines.

Additionally, while Random Masking is incredibly fast, it can sometimes degrade attribution fidelity (LDS) if the model isn't sufficiently over-parameterized. However, the authors note that their per-sample gradient compression techniques are highly generalizable. Future work could integrate GraSS and FactGraSS into other gradient-based attribution frameworks beyond influence functions, such as TracIn or DataInf.

Summary updated

BibTeX
@inproceedings{hu2025grass,
  author = {Pingbang Hu and Joseph Melkonian and Weijing Tang and Han Zhao and Jiaqi W. Ma},
  title = {{GraSS: Scalable Data Attribution with Gradient Sparsification and Sparse Projection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=o0HgWRmyY1},
}
Figure