Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion vllm/attention/backends/rocm_flash_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CommonMetadataBuilder)
from vllm.attention.ops.paged_attn import (PagedAttention,
PagedAttentionMetadata)
from vllm.config import get_current_vllm_config
from vllm.logger import init_logger
from vllm.platforms import current_platform
from vllm.platforms.rocm import use_rocm_custom_paged_attention
Expand Down Expand Up @@ -580,6 +581,7 @@ def __init__(
logger.debug("Using naive (SDPA) attention in ROCmBackend")

self.aiter_kv_scales_initialized = False
self.vllm_config = get_current_vllm_config()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to save the whole config, just do self.force_fp8_attention = ...


def repeat_kv(self, x: torch.Tensor, n_rep: int) -> torch.Tensor:
"""torch.repeat_interleave(x, dim=1, repeats=n_rep)"""
Expand Down Expand Up @@ -766,9 +768,16 @@ def forward(
query.dtype,
seq_lens,
make_attn_mask=causal_mask) # type: ignore

vllm_config_use_fp8_scales = (
True if self.vllm_config is None
or self.vllm_config.model_config is None else
self.vllm_config.model_config.override_attention_dtype
== "fp8")
use_fp8_scales = (layer._q_scale and layer._k_scale
and layer._v_scale and layer._prob_scale
and self.kv_cache_dtype == "fp8")
and vllm_config_use_fp8_scales)

full_scales = (
layer._q_scale, layer._k_scale, layer._v_scale,
layer._prob_scale) if use_fp8_scales else None
Expand Down
2 changes: 2 additions & 0 deletions vllm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ class ModelConfig:
available.\n
- "vllm" will use the vLLM model implementation.\n
- "transformers" will use the Transformers model implementation."""
override_attention_dtype: str = "fp8"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be None by default:

Suggested change
override_attention_dtype: str = "fp8"
override_attention_dtype: Optional[str] = None

"""Override dtype for attention"""

def compute_hash(self) -> str:
"""
Expand Down
4 changes: 4 additions & 0 deletions vllm/engine/arg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class EngineArgs:
override_generation_config: dict[str, Any] = \
get_field(ModelConfig, "override_generation_config")
model_impl: str = ModelConfig.model_impl
override_attention_dtype: str = ModelConfig.override_attention_dtype

calculate_kv_scales: bool = CacheConfig.calculate_kv_scales

Expand Down Expand Up @@ -526,6 +527,8 @@ def add_cli_args(parser: FlexibleArgumentParser) -> FlexibleArgumentParser:
model_group.add_argument("--model-impl",
choices=[f.value for f in ModelImpl],
**model_kwargs["model_impl"])
model_group.add_argument("--override-attention-dtype",
**model_kwargs["override_attention_dtype"])

# Model loading arguments
load_kwargs = get_kwargs(LoadConfig)
Expand Down Expand Up @@ -909,6 +912,7 @@ def create_model_config(self) -> ModelConfig:
override_generation_config=self.override_generation_config,
enable_sleep_mode=self.enable_sleep_mode,
model_impl=self.model_impl,
override_attention_dtype=self.override_attention_dtype,
)

def create_load_config(self) -> LoadConfig:
Expand Down