File size: 1,933 Bytes
4d99473 7548a68 4d99473 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
---
license: apache-2.0
base_model:
- Qwen/Qwen2.5-7B-Instruct
---
# Converted LLaMA from QWEN2-7B-Instruct
## Descritpion
This is a converted model from [Qwen2-7B-Instruct](https://huggingface.co/Qwen/Qwen2-7B-Instruct) to __LLaMA__ format. This conversion allows you to use Qwen2-7B-Instruct as if it were a LLaMA model, which is convenient for some *inference use cases*. The __precision__ is __excatly the same__ as the original model.
## Usage
You can load the model using the `LlamaForCausalLM` class as shown below:
```python
from transformers import AutoTokenizer, LlamaForCausalLM
prompt = "Give me a short introduction to large language model."
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
# we still use the original tokenizer from Qwen2-7B-Instruct
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2-7B-Instruct")
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text],return_tensors="pt").cuda()
# Converted LlaMA model
llama_model = LlamaForCausalLM.from_pretrained(
"silence09/Qwen2-7B-Instruct-Converted-Llama",
torch_dtype='auto').cuda()
llama_generated_ids = llama_model.generate(model_inputs.input_ids, max_new_tokens=32, do_sample=False)
llama_generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, llama_generated_ids)
]
llama_response = tokenizer.batch_decode(llama_generated_ids, skip_special_tokens=True)[0]
print(llama_response)
```
## Precision Guarantee
To comare result with the original model, you can use this [code](https://github.com/silencelamb/naked_llama/blob/main/hf_example/hf_qwen2_7b.py)
## More Info
It was converted using the python script available at [this repository](https://github.com/silencelamb/naked_llama/blob/main/hf_example/convert_qwen_to_llama_hf.py) |