Skip to content
Closed
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion vllm/model_executor/models/deepseek_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,12 @@ def __init__(
# we do this for because MTP layer is not included
# in the compress ratio list
if layer_id < config.num_hidden_layers:
self.compress_ratio = max(1, config.compress_ratios[layer_id])
if hasattr(config, "compress_ratios") and config.compress_ratios is not None:
self.compress_ratio = max(1, config.compress_ratios[layer_id])
else:
_rates = getattr(config, "compress_rates", {}) or {}
_types = getattr(config, "layer_types", [])
self.compress_ratio = max(1, _rates.get(_types[layer_id], 0))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The current implementation has a couple of potential issues that could lead to a crash:

  1. If config.layer_types is explicitly set to None, getattr(config, "layer_types", []) will return None, causing a TypeError when trying to index _types.
  2. If layer_types is an empty list or shorter than layer_id, accessing _types[layer_id] will raise an IndexError.

To make the code more robust, I suggest guarding the access to _types and ensuring it's always a list.

Suggested change
_rates = getattr(config, "compress_rates", {}) or {}
_types = getattr(config, "layer_types", [])
self.compress_ratio = max(1, _rates.get(_types[layer_id], 0))
_rates = getattr(config, "compress_rates", None) or {}
_types = getattr(config, "layer_types", None) or []
layer_type = _types[layer_id] if layer_id < len(_types) else None
self.compress_ratio = max(1, _rates.get(layer_type, 0))

else:
self.compress_ratio = 1
self.eps = config.rms_norm_eps
Expand Down
Loading