Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
datasets:
|
| 4 |
+
- BAAI/IndustryInstruction
|
| 5 |
+
- BAAI/IndustryInstruction_Technology-Research
|
| 6 |
+
base_model:
|
| 7 |
+
- meta-llama/Meta-Llama-3.1-8B-Instruct
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
This model is finetuned on the model llama3.1-8b-instruct using the dataset [BAAI/IndustryInstruction_Artificial-Intelligence](https://huggingface.co/datasets/BAAI/IndustryInstruction_Artificial-Intelligence) dataset, the dataset details can jump to the repo: [BAAI/IndustryInstruction](https://huggingface.co/datasets/BAAI/IndustryInstruction)
|
| 11 |
+
|
| 12 |
+
## training params
|
| 13 |
+
|
| 14 |
+
The training framework is llama-factory, template=llama3
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
learning_rate=1e-5
|
| 18 |
+
lr_scheduler_type=cosine
|
| 19 |
+
max_length=2048
|
| 20 |
+
warmup_ratio=0.05
|
| 21 |
+
batch_size=64
|
| 22 |
+
epoch=10
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
select best ckpt by the evaluation loss
|
| 26 |
+
## evaluation
|
| 27 |
+
|
| 28 |
+
Duto to there is no evaluation benchmark, we can not eval the model
|
| 29 |
+
|
| 30 |
+
## How to use
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
# !/usr/bin/env python
|
| 34 |
+
# -*- coding:utf-8 -*-
|
| 35 |
+
# ==================================================================
|
| 36 |
+
# [Author] : xiaofeng
|
| 37 |
+
# [Descriptions] :
|
| 38 |
+
# ==================================================================
|
| 39 |
+
|
| 40 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 41 |
+
import transformers
|
| 42 |
+
import torch
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
llama3_jinja = """{% if messages[0]['role'] == 'system' %}
|
| 46 |
+
{% set offset = 1 %}
|
| 47 |
+
{% else %}
|
| 48 |
+
{% set offset = 0 %}
|
| 49 |
+
{% endif %}
|
| 50 |
+
|
| 51 |
+
{{ bos_token }}
|
| 52 |
+
{% for message in messages %}
|
| 53 |
+
{% if (message['role'] == 'user') != (loop.index0 % 2 == offset) %}
|
| 54 |
+
{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}
|
| 55 |
+
{% endif %}
|
| 56 |
+
|
| 57 |
+
{{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }}
|
| 58 |
+
{% endfor %}
|
| 59 |
+
|
| 60 |
+
{% if add_generation_prompt %}
|
| 61 |
+
{{ '<|start_header_id|>' + 'assistant' + '<|end_header_id|>\n\n' }}
|
| 62 |
+
{% endif %}"""
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
dtype = torch.bfloat16
|
| 66 |
+
|
| 67 |
+
model_dir = "MonteXiaofeng/Technology-llama3_1_8B_instruct"
|
| 68 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 69 |
+
model_dir,
|
| 70 |
+
device_map="cuda",
|
| 71 |
+
torch_dtype=dtype,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
| 75 |
+
tokenizer.chat_template = llama3_jinja # update template
|
| 76 |
+
|
| 77 |
+
message = [
|
| 78 |
+
{"role": "system", "content": "You are a helpful assistant"},
|
| 79 |
+
{
|
| 80 |
+
"role": "user",
|
| 81 |
+
"content": "请详细描述科技研究如何改变了我们的教育系统。",
|
| 82 |
+
},
|
| 83 |
+
]
|
| 84 |
+
prompt = tokenizer.apply_chat_template(
|
| 85 |
+
message, tokenize=False, add_generation_prompt=True
|
| 86 |
+
)
|
| 87 |
+
print(prompt)
|
| 88 |
+
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
| 89 |
+
prompt_length = len(inputs[0])
|
| 90 |
+
print(f"prompt_length:{prompt_length}")
|
| 91 |
+
|
| 92 |
+
generating_args = {
|
| 93 |
+
"do_sample": True,
|
| 94 |
+
"temperature": 1.0,
|
| 95 |
+
"top_p": 0.5,
|
| 96 |
+
"top_k": 15,
|
| 97 |
+
"max_new_tokens": 512,
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
generate_output = model.generate(input_ids=inputs.to(model.device), **generating_args)
|
| 102 |
+
|
| 103 |
+
response_ids = generate_output[:, prompt_length:]
|
| 104 |
+
response = tokenizer.batch_decode(
|
| 105 |
+
response_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
|
| 106 |
+
)[0]
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
"""
|
| 110 |
+
技研究对我们的教育系统产生了深远的影响。首先,科技研究使得教育变得更加普及。通过互联网和数字化技术,学生可以在任何时间、任何地点接受教育,这大大增加了教育的可获取性。其次,科技研究也使得教育变得更加个性化。通过大数据和人工智能等技术,教育系统可以根据每个学生的学习情况和需求,提供定制化的教学方案。此外,科技研究还促进了教育的互动性。通过虚拟现实、增强现实等技术,学生可以更好地参与到学习中来,提高学习的趣味性和效果。总的来说,科技研究正在不断地推动教育系统的发展,使教育更加普及、个性化和互动。
|
| 111 |
+
"""
|
| 112 |
+
print(f"response:{response}")
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
```
|