Safetensors
llama
MonteXiaofeng commited on
Commit
6f4536e
1 Parent(s): abf76aa

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +114 -0
README.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - BAAI/IndustryInstruction_Artificial-Intelligence
5
+ base_model:
6
+ - meta-llama/Meta-Llama-3.1-8B-Instruct
7
+ ---
8
+
9
+ This model is finetuned on the model llama3.1-8b-instruct using the dataset [BAAI/IndustryInstruction_Transportation](https://huggingface.co/datasets/BAAI/IndustryInstruction_Transportation) dataset, the dataset details can jump to the repo: [BAAI/IndustryInstruction](https://huggingface.co/datasets/BAAI/IndustryInstruction)
10
+
11
+ ## training params
12
+
13
+ The training framework is llama-factory, template=llama3
14
+
15
+ ```
16
+ learning_rate=1e-5
17
+ lr_scheduler_type=cosine
18
+ max_length=2048
19
+ warmup_ratio=0.05
20
+ batch_size=64
21
+ epoch=10
22
+ ```
23
+
24
+ select best ckpt by the evaluation loss
25
+ ## evaluation
26
+
27
+ Duto to there is no evaluation benchmark, we can not eval the model
28
+
29
+ ## How to use
30
+
31
+ ```python
32
+ # !/usr/bin/env python
33
+ # -*- coding:utf-8 -*-
34
+ # ==================================================================
35
+ # [Author] : xiaofeng
36
+ # [Descriptions] :
37
+ # ==================================================================
38
+
39
+ from transformers import AutoTokenizer, AutoModelForCausalLM
40
+ import transformers
41
+ import torch
42
+
43
+
44
+ llama3_jinja = """{% if messages[0]['role'] == 'system' %}
45
+ {% set offset = 1 %}
46
+ {% else %}
47
+ {% set offset = 0 %}
48
+ {% endif %}
49
+
50
+ {{ bos_token }}
51
+ {% for message in messages %}
52
+ {% if (message['role'] == 'user') != (loop.index0 % 2 == offset) %}
53
+ {{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}
54
+ {% endif %}
55
+
56
+ {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }}
57
+ {% endfor %}
58
+
59
+ {% if add_generation_prompt %}
60
+ {{ '<|start_header_id|>' + 'assistant' + '<|end_header_id|>\n\n' }}
61
+ {% endif %}"""
62
+
63
+
64
+ dtype = torch.bfloat16
65
+
66
+ model_dir = "MonteXiaofeng/Artificial-llama3_1_8B_instruct"
67
+ model = AutoModelForCausalLM.from_pretrained(
68
+ model_dir,
69
+ device_map="cuda",
70
+ torch_dtype=dtype,
71
+ )
72
+
73
+ tokenizer = AutoTokenizer.from_pretrained(model_dir)
74
+ tokenizer.chat_template = llama3_jinja # update template
75
+
76
+ message = [
77
+ {"role": "system", "content": "You are a helpful assistant"},
78
+ {
79
+ "role": "user",
80
+ "content": "请解释为什么ChatGPT的英文输出结果的逻辑性和准确性远大于中文结果?",
81
+ },
82
+ ]
83
+ prompt = tokenizer.apply_chat_template(
84
+ message, tokenize=False, add_generation_prompt=True
85
+ )
86
+ print(prompt)
87
+ inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
88
+ prompt_length = len(inputs[0])
89
+ print(f"prompt_length:{prompt_length}")
90
+
91
+ generating_args = {
92
+ "do_sample": True,
93
+ "temperature": 1.0,
94
+ "top_p": 0.5,
95
+ "top_k": 15,
96
+ "max_new_tokens": 512,
97
+ }
98
+
99
+
100
+ generate_output = model.generate(input_ids=inputs.to(model.device), **generating_args)
101
+
102
+ response_ids = generate_output[:, prompt_length:]
103
+ response = tokenizer.batch_decode(
104
+ response_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
105
+ )[0]
106
+
107
+
108
+
109
+ print(f"response:{response}")
110
+ """
111
+ ChatGPT的英文输出结果的逻辑性和准确性远大于中文结果的原因可能是因为以下几点:首先,ChatGPT的训练数据主要来自英文互联网上的大量文本,因此它在处理英文语言时具有更强的能力。其次,英文语言的语法和词汇结构相对简单,容易被ChatGPT理解和生成。此外,ChatGPT的算法优化也可能更适合处理英文语言。然而,对于中文语言,由于其复杂的语法结构和大量的非字节字符,ChatGPT可能难以完全理解和生成准确的中文结果。
112
+ """
113
+
114
+ ```