Skip to content
Merged
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
25 changes: 23 additions & 2 deletions python/sglang/srt/models/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from sglang.srt.layers.radix_attention import RadixAttention
from sglang.srt.layers.sampler import Sampler
from sglang.srt.model_executor.forward_batch_info import InputMetadata
ENABLE_TORCHAO = True


class LlamaMLP(nn.Module):
Expand Down Expand Up @@ -350,8 +351,17 @@ def load_weights(self, weights: Iterable[Tuple[str, torch.Tensor]]):
if name.endswith(".bias") and name not in params_dict:
continue
param = params_dict[name]
weight_loader = param.weight_loader
weight_loader(param, loaded_weight, shard_id)
if hasattr(param, "weight_loader"):
weight_loader = param.weight_loader
weight_loader(param, loaded_weight, shard_id)
if ENABLE_TORCHAO and name.endswith("proj.weight") and param.ndim == 2:
from torchao.quantization import quantize_, int4_weight_only
dummy_linear = torch.nn.Linear(param.shape[1], param.shape[0], bias=False)
dummy_linear.weight.data = param.data
quantize_(dummy_linear, int4_weight_only())
params_dict[name] = dummy_linear.weight

# TODO
break
else:
# Skip loading extra bias for GPTQ models.
Expand All @@ -361,6 +371,17 @@ 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 ENABLE_TORCHAO and name.endswith("proj.weight") and param.ndim == 2:
from torchao.quantization import quantize_, int4_weight_only
dummy_linear = torch.nn.Linear(param.shape[1], param.shape[0], bias=False)
dummy_linear.weight.data = param.data
quantize_(dummy_linear, int4_weight_only())
params_dict[name] = dummy_linear.weight

self.load_state_dict(params_dict, assign=True)




class Phi3ForCausalLM(LlamaForCausalLM):
pass
Expand Down