transformers
2adb62d6 - Only seed numpy in BigBird block-sparse attention during training (#49037)

Commit
64 days ago
Only seed numpy in BigBird block-sparse attention during training (#49037) * Only seed numpy in BigBird block-sparse attention during training `bigbird_block_sparse_attention` calls `np.random.seed(seed)` on every forward. The random block adjacency list it seeds is only randomized when training: in eval mode both `_bigbird_block_rand_mask` and `_bigbird_block_rand_mask_with_head` return a constant all-zero list before touching `np.random`. So during inference the call is a pure side effect that resets the global numpy RNG, and it is also a hard graph break under `torch.compile` (`np.random.seed` is a C extension that dynamo cannot trace), which makes `fullgraph=True` fail outright. Guarding it with `self.training` leaves the training path bit-for-bit identical while making eval side-effect free and fully compilable. * Propagate the BigBird numpy-seed fix to BigBirdPegasus * Shorten the numpy-seed comment to one line
Author
Parents
Loading