Views
No views yet
learning_rate=1e-5
lr_scheduler_type=cosine
max_length=2048
warmup_ratio=0.05
batch_size=64
epoch=10
1# !/usr/bin/env python
2# -*- coding:utf-8 -*-
3# ==================================================================
4# [Author] : xiaofeng
5# [Descriptions] :
6# ==================================================================
7
8from transformers import AutoTokenizer, AutoModelForCausalLM
9import transformers
10import torch
11
12
13llama3_jinja = """{% if messages[0]['role'] == 'system' %}
14 {% set offset = 1 %}
15{% else %}
16 {% set offset = 0 %}
17{% endif %}
18
19{{ bos_token }}
20{% for message in messages %}
21 {% if (message['role'] == 'user') != (loop.index0 % 2 == offset) %}
22 {{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}
23 {% endif %}
24
25 {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] | trim + '<|eot_id|>' }}
26{% endfor %}
27
28{% if add_generation_prompt %}
29 {{ '<|start_header_id|>' + 'assistant' + '<|end_header_id|>\n\n' }}
30{% endif %}"""
31
32
33dtype = torch.bfloat16
34
35model_dir = "XiaofengAlg/Tranport-llama3_1_8B_instruct"
36model = AutoModelForCausalLM.from_pretrained(
37 model_dir,
38 device_map="cuda",
39 torch_dtype=dtype,
40)
41
42tokenizer = AutoTokenizer.from_pretrained(model_dir)
43tokenizer.chat_template = llama3_jinja # update template
44
45message = [
46 {"role": "system", "content": "You are a helpful assistant"},
47 {"role": "user", "content": "私人交通工具的发展对经济有什么影响?"},
48]
49prompt = tokenizer.apply_chat_template(
50 message, tokenize=False, add_generation_prompt=True
51)
52print(prompt)
53inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
54prompt_length = len(inputs[0])
55print(f"prompt_length:{prompt_length}")
56
57generating_args = {
58 "do_sample": True,
59 "temperature": 1.0,
60 "top_p": 0.5,
61 "top_k": 15,
62 "max_new_tokens": 512,
63}
64
65
66generate_output = model.generate(input_ids=inputs.to(model.device), **generating_args)
67
68response_ids = generate_output[:, prompt_length:]
69response = tokenizer.batch_decode(
70 response_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
71)
72print(response)
73"""
74私人交通工具的发展对经济有着深远的影响。首先,私人交通工具的发展可以促进汽车制造业的繁荣。随着私人交通工具的需求增加,汽车制造商将面临更大的市场需求,从而带动产业链的发展,创造就业机会,增加经济收入。其次,私人交通工具的发展也会带动相关
75 业的发展,如燃料供应、维修服务和保险等。这些行业的发展将为经济增长做出贡献。此外,私人交通工具的发展还会促进城市交通的便利性,提高人们的生活质量,从而带动消费,刺激经济发展。然而,私人交通工具的发展也会带来一些负面影响,如交通拥堵和环境
76 染等问题。因此,政府需要采取相应的政策措施来平衡经济发展和环境保护的需要。总的来说,私人交通工具的发展对经济有着重要的影响,需要综合考虑各种因素进行合理规划和管理。
77"""
781@misc{shi2024industryinstruction,
2 title = {IndustryInstruction},
3 author = {Xiaofeng Shi and Lulu Zhao and Hua Zhou and Donglin Hao and Yonghua Lin},
4 year = {2024},
5 publisher = {Hugging Face},
6 doi = {10.57967/hf/3487},
7 url = {https://huggingface.co/datasets/BAAI/IndustryInstruction}
8}