MonteXiaofeng commited on
Commit
d25803a
1 Parent(s): 7cf2bef

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_Automobiles
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_Automobiles](https://huggingface.co/datasets/BAAI/IndustryInstruction_Automobiles) 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/Automobile-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": "随着特斯拉和小米汽车等新势力的崛起,传统车企如何应对互联网和科技公司的挑战,加速向智能化、电动化的方向转型?",
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
+ 传统车企应积极拥抱互联网和科技公司的挑战,加速向智能化、电动化的方向转型。首先,车企需要加强与科技公司的合作,利用其在人工智能、自动驾驶等领域的技术优势,提升自身产品的智能化水平。其次,车企应加大在电动化领域的投入,研发更多电动车型,满足市场对环保、节能的需求。同时,车企还应加强与电池供应商的合作,提升电动车的续航里程和充电速度,提高用户体验。此外,车企还应加强在智能互联方面的投入,提供更好的车联网服务,满足用户对智能化、便捷化的需求。总之,传统车企应积极应对互联网和科技公司的挑战,加速向智能化、电动化的方向转型,以适应市场的变化,保持竞争力
112
+ """
113
+
114
+ ```