File size: 2,646 Bytes
036f08e 0cf149b 036f08e 432f107 0d9e158 432f107 036f08e |
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 47 48 49 50 51 52 53 54 55 56 57 |
---
license: apache-2.0
base_model:
- internlm/internlm3-8b-instruct
tags:
- llama
- internlm3
---
# Converted Llama from InternLM3-8B-Instruct
## Descritpion
This is a converted model from [InternLM3-8B-Instruct](https://huggingface.co/internlm/internlm3-8b-instruct) to __LLaMA__ format. This conversion allows you to use InternLM3-8B-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 AutoModelForCausalLM, AutoTokenizer, LlamaForCausalLM
device = "cuda" # the device to load the model onto, cpu or cuda
attn_impl = 'eager' # the attention implementation to use
prompt = "大模型和人工智能经历了两年的快速发展,请你以此主题对人工智能的从业者写一段新年寄语"
system_prompt = """You are an AI assistant whose name is InternLM (书生·浦语).
- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.
- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文."""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": prompt},
]
tokenizer = AutoTokenizer.from_pretrained("silence09/InternLM3-8B-Instruct-Converted-LlaMA", trust_remote_code=True)
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)
print(prompt)
llama_model = LlamaForCausalLM.from_pretrained(
"silence09/InternLM3-8B-Instruct-Converted-LlaMA",
torch_dtype='auto',
attn_implementation=attn_impl).to(device)
llama_generated_ids = llama_model.generate(model_inputs.input_ids, max_new_tokens=100, 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_internlm3_8b_llama_compare.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_internlm3_to_llama_hf.py) |