Skip to content

Commit 24525da

Browse files
authored
fix(loader,eval): disable continuous-batching CUDA graphs for paged attention and require Evalution>=0.0.10 (#2978)
* fix(loader,eval): disable continuous-batching CUDA graphs for paged attention and require Evalution>=0.0.10 * chore(version): bump to 7.3.3
1 parent f6f1ab1 commit 24525da

4 files changed

Lines changed: 48 additions & 3 deletions

File tree

gptqmodel/models/loader.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,44 @@ def _override_attn_implementation(config: PretrainedConfig, attn_implementation:
178178
pass
179179

180180

181+
def _set_paged_attention_safe_cuda_graphs(model) -> None:
182+
"""Disable CUDA graph capture for paged attention by default.
183+
184+
``transformers`` continuous batching defaults ``use_cuda_graph=True`` for flash-attention
185+
paths, but ``flash_attn_with_kvcache`` is not currently CUDA-graph capture-safe. Setting
186+
the model's default ``continuous_batching_config`` keeps paged Flash Attention working for
187+
direct ``generate_batch`` / ``init_continuous_batching`` callers without requiring a monkey
188+
patch.
189+
"""
190+
if not hasattr(model, "config") or not isinstance(model.config, PretrainedConfig):
191+
return
192+
193+
attn = getattr(model.config, "_attn_implementation", None) or getattr(
194+
model.config, "attn_implementation", None
195+
)
196+
if not isinstance(attn, str) or "paged" not in [part.strip() for part in attn.split("|")]:
197+
return
198+
199+
try:
200+
from transformers import ContinuousBatchingConfig, GenerationConfig
201+
except Exception:
202+
return
203+
204+
gen_config = getattr(model, "generation_config", None)
205+
if gen_config is None:
206+
try:
207+
gen_config = GenerationConfig.from_model_config(model.config)
208+
except Exception:
209+
return
210+
model.generation_config = gen_config
211+
212+
cb_config = getattr(gen_config, "continuous_batching_config", None)
213+
if not isinstance(cb_config, ContinuousBatchingConfig):
214+
gen_config.continuous_batching_config = ContinuousBatchingConfig(use_cuda_graph=(False, False))
215+
elif getattr(cb_config, "use_cuda_graph", None) is None:
216+
cb_config.use_cuda_graph = (False, False)
217+
218+
181219
def _is_accelerated_attention_device(device: object) -> bool:
182220
"""Return True when the selected device can run CUDA/ROCm flash attention."""
183221

@@ -663,6 +701,7 @@ def from_pretrained(
663701
trust_remote_code=trust_remote_code,
664702
model_local_path=model_local_path,
665703
)
704+
_set_paged_attention_safe_cuda_graphs(instance.model)
666705

667706
return instance
668707

@@ -825,6 +864,7 @@ def skip(*args, **kwargs):
825864
trust_remote_code=trust_remote_code,
826865
model_local_path=model_local_path,
827866
)
867+
_set_paged_attention_safe_cuda_graphs(instance.model)
828868

829869
timer = getattr(instance, "quant_region_timer", None)
830870
if timer is not None:
@@ -1078,6 +1118,7 @@ def from_quantized(
10781118
model_local_path=model_local_path,
10791119
)
10801120
instance._runtime_generate = runtime_generate
1121+
_set_paged_attention_safe_cuda_graphs(instance.model)
10811122
return instance
10821123

10831124
if format_code == FORMAT.MARLIN:
@@ -1677,7 +1718,7 @@ def assign(mod, device_id):
16771718
cls.generate = lambda _, **kwargs: mlx_generate(model=model, tokenizer=tokenizer, **kwargs)
16781719

16791720

1680-
return cls(
1721+
instance = cls(
16811722
model,
16821723
quantized=True,
16831724
quantize_config=qcfg,
@@ -1687,6 +1728,8 @@ def assign(mod, device_id):
16871728
trust_remote_code=trust_remote_code,
16881729
model_local_path=model_local_path,
16891730
)
1731+
_set_paged_attention_safe_cuda_graphs(instance.model)
1732+
return instance
16901733

16911734
cls.from_quantized = from_quantized
16921735

gptqmodel/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
# even minor versions are release
88
# 5.2.0 => release, 5.1.0 => devel
99
# micro version (5.2.x) denotes patch fix, i.e. 5.2.1 is a patch fix release
10-
__version__ = "7.3.2"
10+
__version__ = "7.3.3"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ hf = [
6666
"optimum>=1.21.2",
6767
]
6868
eval = [
69-
"Evalution>=0.0.9",
69+
"Evalution>=0.0.10",
7070
]
7171
triton = [
7272
"triton>=3.4.0",

tests/eval.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"tokenizer_revision",
4949
"tp_size",
5050
"trust_remote_code",
51+
"use_cuda_graph",
5152
"vllm_path",
5253
}
5354
_DROPPED_MODEL_ARG_KEYS = {
@@ -533,6 +534,7 @@ def _build_evalution_runtime(
533534
"padding_side": engine_padding_side,
534535
"backend": _normalize_backend_name(backend),
535536
"gptqmodel_path": str(Path(__file__).resolve().parents[2]),
537+
"use_cuda_graph": engine_options.get("use_cuda_graph"),
536538
}
537539
engine = safe_kwargs_call(evalution.GPTQModel, kwargs=engine_kwargs)
538540
model_config = evalution.Model(

0 commit comments

Comments
 (0)