Repository navigation
Add llama3 - #30334
Add llama3#30334
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
5b8d6d8 to
233d8ad
Compare
233d8ad to
6413e76
Compare
|
Managed to get this commit working, but it requires setting flag --llama_version 3 when calling convert_llama_wieghts_to_hf.py python src/transformers/models/llama/convert_llama_weights_to_hf.py \
--input_dir /mnt/nvme1n1/Models/llama3/Meta-Llama-3-8B-Instruct \
--model_size 8B \
--output_dir /mnt/nvme1n1/Models/llama3/Meta-Llama-3-8B-Instruct-hf \
--llama_version 3
Additionally, it tries to delete the tmp folder before it's empty, so throws an error at the end, even though conversion is successful. |
that is expected since you are converting version3, but should still work for earlier versions. |
|
In |
| <Tip warning={true}> | ||
|
|
||
| The `Llama3` models were trained using `bfloat16`, but the original inference uses `float16`. The checkpoints uploaded on the Hub use `torch_dtype = 'float16'`, which will be | ||
| used by the `AutoModel` API to cast the checkpoints from `torch.float32` to `torch.float16`. | ||
|
|
||
| The `dtype` of the online weights is mostly irrelevant unless you are using `torch_dtype="auto"` when initializing a model using `model = AutoModelForCausalLM.from_pretrained("path", torch_dtype = "auto")`. The reason is that the model will first be downloaded ( using the `dtype` of the checkpoints online), then it will be casted to the default `dtype` of `torch` (becomes `torch.float32`), and finally, if there is a `torch_dtype` provided in the config, it will be used. | ||
|
|
||
| Training the model in `float16` is not recommended and is known to produce `nan`; as such, the model should be trained in `bfloat16`. | ||
|
|
||
| </Tip> |
|
Failing tests are unrelated |
|
I meet this error when using the convert_llama_weights_to_hf.py. ImportError: cannot import name 'TikTokenConverter' from 'transformers.convert_slow_tokenizer', how to solve it ? The version of my transformers is 4.40.1 |
|
Hello @lhanchao777, conversion scripts should be used with a source install of You could also clone the repo and add it as an editable installation: |
Hi, @lhanchao777 i download model from modelscop and meet the same problem when trans model format;
but even thoughi solve this problem, i still get other bugs which i have no clue; so finally i still get llama3 direclly from huggingface ``import transformers model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
hope it helps! |
|
Hi there! Not sure if this is the right place, but I'm trying to convert the 8B model to llama2, is that possible by changing the flag in this fashion: python src/transformers/models/llama/convert_llama_weights_to_hf.py --llama_version 3 works fine, but that result is not what I'm looking for in my application. I keep getting this error:
Thanks! |
|
you want llama2, but your error path is llama "./Meta-Llama-3-8B/original/tokenizer.model", check your path please
…________________________________
发件人: danieltmeta ***@***.***>
发送时间: 2024年4月30日 4:23
收件人: huggingface/transformers ***@***.***>
抄送: ZJL0111 ***@***.***>; Comment ***@***.***>
主题: Re: [huggingface/transformers] Add llama3 (PR #30334)
Hi there! Not sure if this is the right place, but I'm trying to convert the 8B model to llama2, is that possible by changing the flag in this fashion:
python src/transformers/models/llama/convert_llama_weights_to_hf.py
--input_dir /path/to/downloaded/llama/weights --model_size 8B --output_dir /output/path --llama_version 2
--llama_version 3 works fine, but that result is not what I'm looking for in my application.
I keep getting this error:
RuntimeError: Internal: could not parse ModelProto from ./Meta-Llama-3-8B/original/tokenizer.model
Thanks!
―
Reply to this email directly, view it on GitHub<#30334 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEVZCQDAT35B76KQRCX7FTTY72T2LAVCNFSM6AAAAABGOSEOTKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBTGU4TKOJWHE>.
You are receiving this because you commented.Message ID: ***@***.***>
|
|
Hi there! I followed the above instructions to convert Meta-Llama-3-8B to hf format but still got errors as follows: I installed transformers from the source file under the folder
|
|
You are most probably not using the correct original tokenizer.model. We proof tested the script many times 😉 |
|
@ArthurZucker You are correct, I was not using this correctly. Thanks! |
I also have the error "Internal: could not parse ModelProto from ./Meta-Llama-3-8B/original/tokenizer.model", I found the "Meta-Llama-3-8B-chat" don't have the "tokenizer.model", how to solve it ? |
|
You should use |
|
Traceback (most recent call last): |
|
Could you share which version of |
…ersion The Llama3Converter hardcodes clean_up_tokenization_spaces=True, which applies BERT-era string replacements (` .` → `.`, ` !` → `!`, etc.) that silently corrupt decoded text from Llama 3's BPE tokenizer. Llama 2's LlamaTokenizer and Llama 4 both use False. The True was introduced in PR huggingface#30334 and hardcoded in PR huggingface#33778 for backward compat. Fixes huggingface#35175
…nversion (#44914) fix: set clean_up_tokenization_spaces=False in Llama 3 tokenizer conversion The Llama3Converter hardcodes clean_up_tokenization_spaces=True, which applies BERT-era string replacements (` .` → `.`, ` !` → `!`, etc.) that silently corrupt decoded text from Llama 3's BPE tokenizer. Llama 2's LlamaTokenizer and Llama 4 both use False. The True was introduced in PR #30334 and hardcoded in PR #33778 for backward compat. Fixes #35175
bytes_to_unicode was removed from transformers.models.gpt2.tokenization_gpt2 in huggingface/transformers#40936, but it had already been copied into transformers.convert_slow_tokenizer in huggingface/transformers#30334 (transformers 4.54.1), so import it directly from there. Applies the same fix to chatglm.py.
bytes_to_unicode was removed from transformers.models.gpt2.tokenization_gpt2 in huggingface/transformers#40936, but it had already been copied into transformers.convert_slow_tokenizer in huggingface/transformers#30334 (transformers 4.54.1), so import it directly from there. Applies the same fix to chatglm.py.
…rg#26217) bytes_to_unicode was removed from transformers.models.gpt2.tokenization_gpt2 in huggingface/transformers#40936, but it had already been copied into transformers.convert_slow_tokenizer in huggingface/transformers#30334 (transformers 4.54.1), so import it directly from there. Applies the same fix to chatglm.py.
…rg#26217) bytes_to_unicode was removed from transformers.models.gpt2.tokenization_gpt2 in huggingface/transformers#40936, but it had already been copied into transformers.convert_slow_tokenizer in huggingface/transformers#30334 (transformers 4.54.1), so import it directly from there. Applies the same fix to chatglm.py.
…rg#26217) bytes_to_unicode was removed from transformers.models.gpt2.tokenization_gpt2 in huggingface/transformers#40936, but it had already been copied into transformers.convert_slow_tokenizer in huggingface/transformers#30334 (transformers 4.54.1), so import it directly from there. Applies the same fix to chatglm.py.
…rg#26217) bytes_to_unicode was removed from transformers.models.gpt2.tokenization_gpt2 in huggingface/transformers#40936, but it had already been copied into transformers.convert_slow_tokenizer in huggingface/transformers#30334 (transformers 4.54.1), so import it directly from there. Applies the same fix to chatglm.py.



TODOs