Repository: vllm-project/vllm
File: vllm/platforms/cuda.py (Python)

Code before:
                logger.info(
                    "Setting kv cache block size to %d for %s backend.",
                    preferred,
                    chosen_backend.name,
                )
                cache_config.block_size = preferred  # type: ignore[assignment]
            return

        # No valid backend found. If the user didn't constrain the
        # selection, defer the error to get_attn_backend_cls where
        # the full config (including per-layer settings) is available.
        if not user_specified_block_size:
            return

        # User specified --block-size (and possibly --attention-backend)
        # but no backend supports it. Build a helpful error message.
        if selected_backend is not None:
            try:
                backend_class = selected_backend.get_class()
                supported = backend_class.get_supported_kernel_block_sizes()
            except ImportError:
                supported = None
            raise ValueError(
                f"User-specified --block-size "
                f"{cache_config.block_size} is incompatible with "
                f"--attention-backend {selected_backend.name}"
                f" (supported kernel block sizes: {supported})."
                f" Either remove --block-size to auto-select,"
                f" or choose a compatible value."
            )
        else:
            _, invalid_reasons = cls.get_valid_backends(
                device_capability=device_capability,
                attn_selector_config=attn_selector_config,
                num_heads=num_heads,
            )
            reasons_str = ", ".join(
                f"{b.name}: [{', '.join(r)}]" for b, r in invalid_reasons.items()
            )
            raise ValueError(
                f"No valid attention backend found for --block-size "
                f"{cache_config.block_size}. "
                f"Reasons: {{{reasons_str}}}."
                f" Either remove --block-size to auto-select,"
                f" or choose a compatible value."
            )

    @classmethod
    def get_current_memory_usage(
        cls, device: torch.types.Device | None = None
    ) -> float:

Review comment (suggestion):
```suggestion
                f"the specified --attention-backend {selected_backend.name}"
```

Code after:
                preferred = backend_class.get_preferred_block_size(
                    cache_config.block_size,
                )
                if cache_config.block_size != preferred:
                    logger.info(
                        "Setting kv cache block size to %d for %s backend.",
                        preferred,
                        chosen_backend.name,
                    )
                    cache_config.block_size = preferred
                return

            # No valid backend found. If the user didn't constrain the
            # selection, defer the error to get_attn_backend_cls where
            # the full config (including per-layer settings) is
            # available.
            if not user_specified_block_size:
                return

            if user_specified_backend is not None:
                # User specified --block-size and --attention-backend
                # and they are incompatible.
                try:
                    backend_class = user_specified_backend.get_class()
                    supported = backend_class.get_supported_kernel_block_sizes()
                except ImportError:
                    supported = None
                raise ValueError(
                    f"User-specified --block-size "
                    f"{cache_config.block_size} is incompatible with "
                    f"the specified --attention-backend "
                    f"{user_specified_backend.name} (supported kernel "
                    f"block sizes: {supported}). Either remove "
                    f"--block-size to auto-select, or choose a "
                    f"compatible value."
                )
            else:
                # User specified --block-size but no backend supports
                # it.
                _, invalid_reasons = cls.get_valid_backends(
                    device_capability=device_capability,
                    attn_selector_config=attn_selector_config,
                    num_heads=num_heads,
                )
                reasons_str = ", ".join(
                    f"{b.name}: [{', '.join(r)}]" for b, r in invalid_reasons.items()
                )
                raise ValueError(
                    f"No valid attention backend found for "
                    f"--block-size {cache_config.block_size}. "
                    f"Reasons: {{{reasons_str}}}. Either remove "