LZHgrla commited on
Commit
652f33a
1 Parent(s): 23ff05b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +94 -13
README.md CHANGED
@@ -1,20 +1,101 @@
1
  ---
2
  library_name: peft
 
 
 
3
  ---
4
- ## Training procedure
5
 
 
 
6
 
7
- The following `bitsandbytes` quantization config was used during training:
8
- - load_in_8bit: False
9
- - load_in_4bit: True
10
- - llm_int8_threshold: 6.0
11
- - llm_int8_skip_modules: None
12
- - llm_int8_enable_fp32_cpu_offload: True
13
- - llm_int8_has_fp16_weight: False
14
- - bnb_4bit_quant_type: nf4
15
- - bnb_4bit_use_double_quant: True
16
- - bnb_4bit_compute_dtype: float16
17
- ### Framework versions
18
 
 
19
 
20
- - PEFT 0.4.0.dev0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  library_name: peft
3
+ pipeline_tag: conversational
4
+ datasets:
5
+ - fnlp/moss-003-sft-data
6
  ---
 
7
 
8
+ <div align="center">
9
+ <img src="https://github.com/InternLM/lmdeploy/assets/36994684/0cf8d00f-e86b-40ba-9b54-dc8f1bc6c8d8" width="600"/>
10
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ [![Generic badge](https://img.shields.io/badge/GitHub-%20XTuner-black.svg)](https://github.com/InternLM/xtuner)
13
 
14
+
15
+ </div>
16
+
17
+ ## Model
18
+
19
+ Llama-2-7b-qlora-moss-003-sft is fine-tuned from [Llama-2-7b](https://huggingface.co/meta-llama/Llama-2-7b-hf) with [moss-003-sft](https://huggingface.co/datasets/fnlp/moss-003-sft-data) dataset by [XTuner](https://github.com/InternLM/xtuner).
20
+
21
+
22
+ ## Quickstart
23
+
24
+ ### Usage with HuggingFace libraries
25
+
26
+ ```python
27
+ import torch
28
+ from peft import PeftModel
29
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, StoppingCriteria
30
+ from transformers.generation import GenerationConfig
31
+
32
+ class StopWordStoppingCriteria(StoppingCriteria):
33
+ def __init__(self, tokenizer, stop_word):
34
+ self.tokenizer = tokenizer
35
+ self.stop_word = stop_word
36
+ self.length = len(self.stop_word)
37
+ def __call__(self, input_ids, *args, **kwargs) -> bool:
38
+ cur_text = self.tokenizer.decode(input_ids[0])
39
+ cur_text = cur_text.replace('\r', '').replace('\n', '')
40
+ return cur_text[-self.length:] == self.stop_word
41
+
42
+ tokenizer = AutoTokenizer.from_pretrained('meta-llama/Llama-2-7b-hf', trust_remote_code=True)
43
+ quantization_config = BitsAndBytesConfig(load_in_4bit=True, load_in_8bit=False, llm_int8_threshold=6.0, llm_int8_has_fp16_weight=False, bnb_4bit_compute_dtype=torch.float16, bnb_4bit_use_double_quant=True, bnb_4bit_quant_type='nf4')
44
+ model = AutoModelForCausalLM.from_pretrained('meta-llama/Llama-2-7b-hf', quantization_config=quantization_config, device_map='auto', trust_remote_code=True).eval()
45
+ model = PeftModel.from_pretrained(model, 'xtuner/Llama-2-7b-qlora-moss-003-sft')
46
+ gen_config = GenerationConfig(max_new_tokens=512, do_sample=True, temperature=0.1, top_p=0.75, top_k=40)
47
+
48
+ # Note: In this example, we disable the use of plugins because the API depends on additional implementations.
49
+ # If you want to experience plugins, please refer to XTuner CLI!
50
+ prompt_template = (
51
+ 'You are an AI assistant whose name is Llama.\n'
52
+ 'Capabilities and tools that Llama can possess.\n'
53
+ '- Inner thoughts: disabled.\n'
54
+ '- Web search: disabled.\n'
55
+ '- Calculator: disabled.\n'
56
+ '- Equation solver: disabled.\n'
57
+ '- Text-to-image: disabled.\n'
58
+ '- Image edition: disabled.\n'
59
+ '- Text-to-speech: disabled.\n'
60
+ '<|Human|>: {input}<eoh>\n'
61
+ '<|Inner Thoughts|>: None<eot>\n'
62
+ '<|Commands|>: None<eoc>\n'
63
+ '<|Results|>: None<eor>\n')
64
+
65
+ text = '请给我介绍五个上海的景点'
66
+ inputs = tokenizer(prompt_template.format(input=text), return_tensors='pt')
67
+ inputs = inputs.to(model.device)
68
+ pred = model.generate(**inputs, generation_config=gen_config, stopping_criteria=[StopWordStoppingCriteria(tokenizer, '<eom>')])
69
+ print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
70
+ """
71
+ 好的,以下是五个上海的景点:
72
+ 1. 外滩:外滩是上海的标志性景点之一,是一条长达1.5公里的沿江大道,沿途有许多历史建筑和现代化的高楼大厦。游客可以欣赏到黄浦江两岸的美景,还可以在这里拍照留念。
73
+ 2. 上海博物馆:上海博物馆是上海市最大的博物馆之一,收藏了大量的历史文物和艺术品。博物馆内有许多展览,包括中国古代文物、近代艺术品和现代艺术品等。
74
+ 3. 上海科技馆:上海科技馆是一座以科技为主题的博物馆,展示了许多科技产品和科技发展的历史。游客可以在这里了解到许多有趣的科技知识,还可以参加一些科技体验活动。
75
+ 4. 上海迪士尼乐园:上海迪士尼乐园是中国第一个迪士尼乐园,是一个集游乐、购物、餐饮、娱乐等多种功能于一体的主题公园。游客可以在这里体验到迪士尼的经典故事和游乐设施。
76
+ 5. 上海野生动物园:上海野生动物园是一座以野生动物观赏和保护为主题的大型动物园。它位于上海市浦东新区,是中国最大的野生动物园之一。
77
+ """
78
+ ```
79
+
80
+ ### Usage with XTuner CLI
81
+
82
+ #### Installation
83
+
84
+ ```shell
85
+ pip install xtuner
86
+ ```
87
+
88
+ #### Chat
89
+
90
+ ```shell
91
+ xtuner chat hf meta-llama/Llama-2-7b-hf --adapter xtuner/Llama-2-7b-qlora-moss-003-sft --bot-name Llama --prompt-template moss_sft --with-plugins calculate solve search --command-stop-word "<eoc>" --answer-stop-word "<eom>"
92
+ ```
93
+
94
+ #### Fine-tune
95
+
96
+ Use the following command to quickly reproduce the fine-tuning results.
97
+
98
+ ```shell
99
+ NPROC_PER_NODE=8 xtuner train llama2_7b_qlora_moss_sft_all_e2_gpu8 # Recommended!
100
+ xtuner train llama2_7b_qlora_moss_sft_all_e1
101
+ ```