Update flex_attention.py
This commit is contained in:
parent
ed56977a8c
commit
2a251ec594
1 changed files with 17 additions and 12 deletions
|
|
@ -25,18 +25,23 @@ torch_compile_options = {
|
|||
}
|
||||
|
||||
# Flex Attention supported from torch 2.5 onwards only
|
||||
import torch.nn.attention
|
||||
if hasattr(torch.nn.attention, "flex_attention"):
|
||||
import torch.nn.attention.flex_attention
|
||||
from torch.nn.attention.flex_attention import flex_attention
|
||||
from torch.nn.attention.flex_attention import create_block_mask
|
||||
FLEX_ATTENTION_PADDING = getattr(
|
||||
torch.nn.attention.flex_attention,
|
||||
"_DEFAULT_SPARSE_BLOCK_SIZE",
|
||||
1,
|
||||
)
|
||||
flex_attention = torch.compile(flex_attention, dynamic = False)
|
||||
HAS_FLEX_ATTENTION = True
|
||||
import torch.nn
|
||||
if hasattr(torch.nn, "attention"):
|
||||
import torch.nn.attention
|
||||
if hasattr(torch.nn.attention, "flex_attention"):
|
||||
import torch.nn.attention.flex_attention
|
||||
from torch.nn.attention.flex_attention import flex_attention
|
||||
from torch.nn.attention.flex_attention import create_block_mask
|
||||
FLEX_ATTENTION_PADDING = getattr(
|
||||
torch.nn.attention.flex_attention,
|
||||
"_DEFAULT_SPARSE_BLOCK_SIZE",
|
||||
1,
|
||||
)
|
||||
flex_attention = torch.compile(flex_attention, dynamic = False)
|
||||
HAS_FLEX_ATTENTION = True
|
||||
else:
|
||||
HAS_FLEX_ATTENTION = False
|
||||
pass
|
||||
else:
|
||||
HAS_FLEX_ATTENTION = False
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue