Skip to content

加载用lora微调后的模型进行推理时,出现“IndexError: index out of range in self”问题,请问是什么原因? #873

Closed Answered by fanll
fanll asked this question in Q&A
Discussion options

You must be logged in to vote

统一回复一下,我后来尝试用下面的方法可以正常加载了。transformer用的是requirements指定的版本。
代码:

    from transformers import AutoTokenizer, AutoModel
    from peft import PeftModel

    TOKENIZER_PATH = "path/to/tokenizer"
    LORA_PATH = "path/to/lora"
    device = "cuda"
    tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_PATH, trust_remote_code=True)
    model = AutoModel.from_pretrained(MODEL_PATH, trust_remote_code=True, device_map=device).eval()
    model = PeftModel.from_pretrained(model, LORA_PATH)

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by fanll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants