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

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

Closed
hrson-1203 opened this issue Feb 23, 2024 · 24 comments
Closed

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

hrson-1203 opened this issue Feb 23, 2024 · 24 comments
Labels

Comments

@hrson-1203
Copy link

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?

@newportchen
Copy link

newportchen commented Feb 23, 2024

please support bigger vocab size like yi_6b: 64000 @Yard1

@AlphaINF
Copy link

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

@r4dm
Copy link

r4dm commented Feb 27, 2024

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

@AlphaINF
Copy link

AlphaINF commented Mar 1, 2024

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 = []

@Xingxiangrui
Copy link

Xingxiangrui commented Mar 4, 2024

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

@ashgold
Copy link

ashgold commented Mar 14, 2024

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?

@flexorRegev
Copy link

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

@Yard1
Copy link
Collaborator

Yard1 commented Mar 18, 2024

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.

@flexorRegev
Copy link

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

@Yard1
Copy link
Collaborator

Yard1 commented Mar 19, 2024

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

@newportchen
Copy link

newportchen commented Mar 26, 2024

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

@PenutChen
Copy link

PenutChen commented Mar 28, 2024

+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.

@Yard1
Copy link
Collaborator

Yard1 commented Mar 28, 2024

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.

@flexorRegev
Copy link

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

@qZhang88
Copy link

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?

@Yard1
Copy link
Collaborator

Yard1 commented Apr 19, 2024

@qZhang88 Llama 3 should be supported in latest release.

@piercefreeman
Copy link

piercefreeman commented Apr 22, 2024

@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?

@Yard1
Copy link
Collaborator

Yard1 commented Apr 22, 2024

It should be 0.4.1 - this is the commit: 1e96c33

@Techinix
Copy link

@Yard1 how can we upgrade to this release ??

@piercefreeman
Copy link

@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.

@SuperBruceJia
Copy link

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

@schoennenbeck
Copy link
Contributor

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.

@AlphaINF
Copy link

AlphaINF commented Jun 1, 2024

hello. In some multilingual models(like qwen2 or OpenBuddy multilingual series model), the vocab_size may exceed 128512, their size are bigger than 128k but usually not larger than 200k, can you extend the vocab_size to 200k?

@qZhang88 Llama 3 should be supported in latest release.

Copy link

This issue has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this issue should remain open. Thank you!

@github-actions github-actions bot added the stale label Oct 30, 2024
Copy link

This issue has been automatically closed due to inactivity. Please feel free to reopen if you feel it is still relevant. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests