vllm icon indicating copy to clipboard operation
vllm copied to clipboard

How can I use the Lora Adapter for a model with Vocab size 40960?

Open hrson-1203 opened this issue 1 year ago • 22 comments

The error occurs when I call the LLMEngine object. The error below appears.

ValueError: When using LoRA, vocab size must be 32000 >= vocab_size <= 33024

Does the method using the Lora Adapter not apply to models that expand the vocab or have a vocab size larger than 32000?

hrson-1203 avatar Feb 23 '24 01:02 hrson-1203

please support bigger vocab size like yi_6b: 64000 @Yard1

newportchen avatar Feb 23 '24 07:02 newportchen

same issue, I deployed a LLaMA structure LLLM but the vocab_size had been expanded to 130,000

AlphaINF avatar Feb 25 '24 11:02 AlphaINF

same problem, please add support for vocab_size over 32000. in my case need vocab_size 60256

r4dm avatar Feb 27 '24 12:02 r4dm

I found a solution which inspired by Gemma you can find the file: vllm/vllm/model_executor/models/llama.py, then find the definition of LlamaForCausalLM (in line 278)

that's the original support lora modules

    # LoRA specific attributes
    supported_lora_modules = [
        "qkv_proj",
        "o_proj",
        "gate_up_proj",
        "down_proj",
        "embed_tokens",
        "lm_head",
    ]
    embedding_modules = {
        "embed_tokens": "input_embeddings",
        "lm_head": "output_embeddings",
    }
    embedding_padding_modules = ["lm_head"]

just remove some modules which may cause errors and finally saving like this:

    # LoRA specific attributes
    supported_lora_modules = [
        "qkv_proj",
        "o_proj",
        "gate_up_proj",
        "down_proj",
    ]
    embedding_modules = {}
    embedding_padding_modules = []

AlphaINF avatar Mar 01 '24 13:03 AlphaINF

+1 for this, Please add more vocab size support.

Xingxiangrui avatar Mar 04 '24 07:03 Xingxiangrui

Why doesn't the lora adapter load based on the vocabulary size of the origin model, even though the target_modules in adapter_config.json doesn't have embed_tokens and lm_head?

ashgold avatar Mar 14 '24 04:03 ashgold

Was also trying to run Yi with the same problem.. @Yard1 can you elaborate on what's needed to support? I'd be glad to work on this PR

flexorRegev avatar Mar 18 '24 19:03 flexorRegev

We'd need to modify the kernel/write a new LoRA kernel to support such a large vocabulary size. The current Punica ones cannot do that.

Yard1 avatar Mar 18 '24 20:03 Yard1

@Yard1 How does the Gemma avoid this? it also has a huge vocab_size

flexorRegev avatar Mar 19 '24 09:03 flexorRegev

We just don't allow the embeddings layer to be modified on gemma

Yard1 avatar Mar 19 '24 17:03 Yard1

We just don't allow the embeddings layer to be modified on gemma

The Yi_6B has 64000 vocab_size, when i modify the llama model source just like gemma,it's work fine。

but the Yi_6B_200K always throw exception: 20240326-112124

The Yi_6B_200K has a different max_position_embeddings:200000

@Yard1

newportchen avatar Mar 26 '24 03:03 newportchen

+1. Need support for a larger vocabulary size. In addition to vocabulary size, there is also a use case like LLaMA Pro block expansion fine-tuning with LoRA, which may not have LoRA weights for all layers. For example, only layers 5, 10, 15, and 20 might have corresponding LoRA weights.

PenutChen avatar Mar 28 '24 03:03 PenutChen

It should already be possible to use adapters which do not modify every layer - if that is not the case, it is a bug and should be fixed.

Yard1 avatar Mar 28 '24 08:03 Yard1

Also made it work with a gemma-like adaptation to Yi and it works :)

flexorRegev avatar Mar 28 '24 16:03 flexorRegev

lora finetune for Llama-3 has the same problem, however same code finetune Qwen1.5-7B-Chat, with vocab size 151643, has no such problem, why?

qZhang88 avatar Apr 19 '24 14:04 qZhang88

@qZhang88 Llama 3 should be supported in latest release.

Yard1 avatar Apr 19 '24 20:04 Yard1

@Yard1 I've tried llama3 on v0.4.0.post1, but this issue is still present when initializing the engine with lora adapters. The latest main code seems to get further in the initialization process (ie. no explicit crash about vocab size) but seems to stall out later in the pipeline - haven't gotten a chance to debug that yet.

But to confirm - llama3 with adapters is supposed to work on 0.4.0.post1, or were you referring to the 0.4.1 prerelease?

piercefreeman avatar Apr 22 '24 19:04 piercefreeman

It should be 0.4.1 - this is the commit: https://github.com/vllm-project/vllm/commit/1e96c3341a4e055ae392085fecc7a672295b71c2

Yard1 avatar Apr 22 '24 19:04 Yard1

@Yard1 how can we upgrade to this release ??

Techinix avatar Apr 23 '24 10:04 Techinix

@Techinix You can either manually install the wheel from the Release page or build yourself locally from the tagged git version. On my setup, local building takes around 15-30min.

piercefreeman avatar Apr 23 '24 14:04 piercefreeman

For the LLaMA 3 model:

Please use the following codes for your tokenizer:

tokenizer.pad_token = tokenizer.eos_token

In this way, the vocabulary size is still 128256 .

However, if you use

tokenizer.add_special_tokens(
    {'pad_token': '[PAD]'}
)
# Resize input token embeddings matrix of the model if new_num_tokens != config.vocab_size.
model.resize_token_embeddings(len(tokenizer))

The vocabulary size is increased to 128768 , which leads to this ValueError: When using LoRA, vocab size must be 32000 > vocab_size < 128512 error.

For now, I don't know the reason. If you know the reason, please leave a message. Thank you very much in advance!

Shuyue May 11th, 2024

SuperBruceJia avatar May 12 '24 02:05 SuperBruceJia

Wouldn't it make more sense to check which layers the LoRA-adapter actually applies to? Most LoRA-frameworks don't even touch the embedding layer by default.

schoennenbeck avatar May 16 '24 11:05 schoennenbeck