Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tie_word_embeddings when loading weights + support for SmolLM #1508

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3-8B-Instruct
- BaiChuan2
- MiniCPM / MiniCPM 3
- XVERSE / XVERSE MoE
- SmolLM


**Embedding Models**
Expand Down
6 changes: 6 additions & 0 deletions python/sglang/srt/models/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
weight_loader = getattr(param, "weight_loader", default_weight_loader)
weight_loader(param, loaded_weight)

if hasattr(self.config, "tie_word_embeddings") and self.config.tie_word_embeddings:
# Tie output embedding layer to input embedding layer, to solve issues where lm_head.weight is missing
param = self.lm_head.weight
weight_loader = getattr(param, "weight_loader", default_weight_loader)
weight_loader(param, self.model.embed_tokens.weight)
merrymercy marked this conversation as resolved.
Show resolved Hide resolved

merrymercy marked this conversation as resolved.
Show resolved Hide resolved
apply_torchao_config_(self, params_dict, set(["proj.weight"]))


Expand Down
1 change: 1 addition & 0 deletions test/srt/models/test_generation_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ModelCase:
# All other models
ALL_OTHER_MODELS = [
ModelCase("Qwen/Qwen2-1.5B"),
ModelCase("HuggingFaceTB/SmolLM-135M-Instruct"),
]

TORCH_DTYPES = [torch.float16]
Expand Down
Loading