Skip to content

Commit e77af57

Browse files
committed
Remove flash attention property shim
1 parent aa3c003 commit e77af57

4 files changed

Lines changed: 14 additions & 16 deletions

File tree

‎llama_cpp/llama.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,11 @@ def __init__(
341341
self._logits_all = logits_all if draft_model is None else True
342342
self.context_params.embeddings = embedding # TODO: Rename to embeddings
343343
self.context_params.offload_kqv = offload_kqv
344-
self.context_params.flash_attn = flash_attn
344+
self.context_params.flash_attn_type = (
345+
llama_cpp.LLAMA_FLASH_ATTN_TYPE_ENABLED
346+
if flash_attn
347+
else llama_cpp.LLAMA_FLASH_ATTN_TYPE_DISABLED
348+
)
345349

346350
if op_offload is not None:
347351
self.context_params.op_offload = op_offload
@@ -2103,7 +2107,10 @@ def __getstate__(self):
21032107
logits_all=self._logits_all,
21042108
embedding=self.context_params.embeddings,
21052109
offload_kqv=self.context_params.offload_kqv,
2106-
flash_attn=self.context_params.flash_attn,
2110+
flash_attn=(
2111+
self.context_params.flash_attn_type
2112+
== llama_cpp.LLAMA_FLASH_ATTN_TYPE_ENABLED
2113+
),
21072114
op_offload=self.context_params.op_offload,
21082115
swa_full=self.context_params.swa_full,
21092116
# Sampling Params

‎llama_cpp/llama_chat_format.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,10 @@ def _init_mtmd_context(self, llama_model: llama.Llama):
27572757
ctx_params.n_threads = llama_model.n_threads
27582758
ctx_params.flash_attn_type = (
27592759
llama_cpp.LLAMA_FLASH_ATTN_TYPE_ENABLED
2760-
if llama_model.context_params.flash_attn
2760+
if (
2761+
llama_model.context_params.flash_attn_type
2762+
== llama_cpp.LLAMA_FLASH_ATTN_TYPE_ENABLED
2763+
)
27612764
else llama_cpp.LLAMA_FLASH_ATTN_TYPE_DISABLED
27622765
)
27632766

‎llama_cpp/llama_cpp.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -993,18 +993,6 @@ class llama_context_params(ctypes.Structure):
993993
("n_samplers", ctypes.c_size_t),
994994
]
995995

996-
@property
997-
def flash_attn(self) -> bool:
998-
return self.flash_attn_type == LLAMA_FLASH_ATTN_TYPE_ENABLED
999-
1000-
@flash_attn.setter
1001-
def flash_attn(self, enabled: bool):
1002-
self.flash_attn_type = (
1003-
LLAMA_FLASH_ATTN_TYPE_ENABLED
1004-
if enabled
1005-
else LLAMA_FLASH_ATTN_TYPE_DISABLED
1006-
)
1007-
1008996

1009997
# // Signature for logging events
1010998
# // Note that text includes the new line character at the end for most events.

‎tests/test_llama.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_real_model(llama_cpp_model_path):
8383
cparams.n_threads = multiprocessing.cpu_count()
8484
cparams.n_threads_batch = multiprocessing.cpu_count()
8585
cparams.logits_all = False
86-
cparams.flash_attn = True
86+
cparams.flash_attn_type = llama_cpp.LLAMA_FLASH_ATTN_TYPE_ENABLED
8787

8888
context = internals.LlamaContext(model=model, params=cparams)
8989
tokens = model.tokenize(b"Hello, world!", add_bos=True, special=True)

0 commit comments

Comments
 (0)