Skip to content
Merged
Changes from all 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
3 changes: 3 additions & 0 deletions python/sglang/srt/configs/internvl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
LlamaConfig,
PretrainedConfig,
PreTrainedTokenizer,
Qwen2Config,
)

from sglang.utils import logger
Expand Down Expand Up @@ -311,6 +312,8 @@ def __init__(
self.llm_config = LlamaConfig(**llm_config)
elif llm_config.get("architectures")[0] == "InternLM2ForCausalLM":
self.llm_config = InternLM2Config(**llm_config)
elif llm_config.get("architectures")[0] == "Qwen2ForCausalLM":
self.llm_config = Qwen2Config(**llm_config)
Comment on lines +315 to +316
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While this change is correct, the overall conditional block could be improved for robustness and maintainability.

  • Robustness: The repeated use of llm_config.get("architectures")[0] is unsafe. It can raise a TypeError or IndexError if architectures is missing or empty. It's better to extract the architecture name into a variable with proper checks.
  • Maintainability: An if/elif chain for architectures is not easily scalable. A dictionary mapping architecture names to config classes would be a more maintainable pattern.

Here's a suggested refactoring for the whole block for future consideration:

LLM_CONFIG_MAPPING = {
    "LlamaForCausalLM": LlamaConfig,
    "InternLM2ForCausalLM": InternLM2Config,
    "Qwen2ForCausalLM": Qwen2Config,
}

architectures = llm_config.get("architectures")
if not architectures:
    raise ValueError("'architectures' key is missing or empty in llm_config.")

arch = architectures[0]
config_class = LLM_CONFIG_MAPPING.get(arch)

if config_class:
    self.llm_config = config_class(**llm_config)
else:
    raise ValueError(f"Unsupported architecture: {arch}")

else:
raise ValueError(
"Unsupported architecture: {}".format(
Expand Down
Loading