[Model] Re-add the implicit conversion feature for as_seq_cls_model (#21103)
Signed-off-by: wang.yuqi <noooop@126.com>
This commit is contained in:
@@ -331,13 +331,13 @@ def load_weights_using_from_2_way_softmax(
|
||||
|
||||
false_id = tokenizer.convert_tokens_to_ids(tokens[0])
|
||||
true_id = tokenizer.convert_tokens_to_ids(tokens[1])
|
||||
weight = model.lm_head.weight.data[[true_id]].to(
|
||||
score_weight = model.lm_head.weight.data[[true_id]].to(
|
||||
torch.float32) - model.lm_head.weight.data[[false_id]].to(
|
||||
torch.float32)
|
||||
|
||||
param = model.score.weight
|
||||
weight_loader = getattr(param, "weight_loader", default_weight_loader)
|
||||
weight_loader(param, weight)
|
||||
weight_loader(param, score_weight)
|
||||
|
||||
del model.lm_head
|
||||
loaded_weights.add("score.weight")
|
||||
@@ -350,6 +350,8 @@ def load_weights_no_post_processing(model,
|
||||
torch.Tensor]]):
|
||||
from vllm.model_executor.layers.vocab_parallel_embedding import (
|
||||
ParallelLMHead)
|
||||
from vllm.model_executor.model_loader.weight_utils import (
|
||||
default_weight_loader)
|
||||
from vllm.model_executor.models.utils import AutoWeightsLoader
|
||||
|
||||
model_config = model.vllm_config.model_config
|
||||
@@ -357,8 +359,6 @@ def load_weights_no_post_processing(model,
|
||||
tokens = cast(list[int], tokens)
|
||||
assert len(tokens) > 0
|
||||
|
||||
device = model.score.weight.device
|
||||
|
||||
if model.config.tie_word_embeddings:
|
||||
model.lm_head = model.model.embed_tokens
|
||||
else:
|
||||
@@ -376,8 +376,11 @@ def load_weights_no_post_processing(model,
|
||||
trust_remote_code=model_config.trust_remote_code)
|
||||
|
||||
token_ids = [tokenizer.convert_tokens_to_ids(t) for t in tokens]
|
||||
score_weight = model.lm_head.weight.data[token_ids].to(device)
|
||||
model.score.weight.data.copy_(score_weight)
|
||||
score_weight = model.lm_head.weight.data[token_ids]
|
||||
|
||||
param = model.score.weight
|
||||
weight_loader = getattr(param, "weight_loader", default_weight_loader)
|
||||
weight_loader(param, score_weight)
|
||||
|
||||
del model.lm_head
|
||||
loaded_weights.add("score.weight")
|
||||
|
||||
Reference in New Issue
Block a user