v2.1.5 - Keep attention profiling compatible with torch 1.x (#159)
π Summary
THOP 2.1.5 improves PyTorch compatibility by making attention-operation profiling safe across both PyTorch 1.x and 2.x versions. π οΈ
π Key Changes
-
Fixed
nn.MultiheadAttentionprofiling on PyTorch 1.x
Attention profiling is now enabled only when PyTorch forward hooks can expose keyword arguments. -
Preserved accurate attention counting on PyTorch 2.x
Newer PyTorch versions continue to report attention MACs correctly, including mixed cross-attention scenarios. -
Avoided crashes on older PyTorch versions
When hook inputs cannot be reconstructed, THOP now skips attention MAC counting rather than attempting an unsafe call. -
Updated the package version
The release version was bumped from 2.1.4 to 2.1.5. -
Validated across profiling APIs β
Tests confirmed accurate results on PyTorch 2.x and safe zero-count behavior under PyTorch 1.x compatibility conditions.
π― Purpose & Impact
- Improves backward compatibility for users running models with PyTorch 1.x.
- Prevents profiling-related runtime errors without changing model execution.
- Maintains modern profiling accuracy for PyTorch 2.x users.
- Users should receive a more reliable experience when using THOP to estimate model complexity, especially for models containing multi-head or cross-attention layers. π
What's Changed
- Keep attention profiling compatible with torch 1.x by @glenn-jocher in #159
Full Changelog: v2.1.4...v2.1.5