forked from apple/axlearn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
BaseAttentionBias.has_value()
. (apple#920)
`BaseAttentionBias.value()` is also used to check whether a bias value exists. However, calling `value()` creates the actual bias on the CPU, which is quadratic O(T^2) — especially when debugging long sequence lengths (e.g., 32k). Hence, we introduce a lightweight `has_value()` method. Normally, unused tensors are pruned from the graph during XLA compilation, and using `BaseAttentionBias.value()` to check for bias presence relies on XLA pruning. But `BaseAttentionBias.value()` is still expensive on the CPU for unittests and debugging, so `has_value()` saves Python runtime. The new `has_value()` method checks whether `value()` actually exists by calling `jax.eval_shape`. Since `jax.eval_shape` invokes `value()` through a tracer, it doesn’t materialize the actual value (proposed by John Peebles).
- Loading branch information
Showing
4 changed files
with
96 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters