LZHgrla commited on
Commit
b025a2d
1 Parent(s): ddef646

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +89 -13
README.md CHANGED
@@ -1,20 +1,96 @@
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Qwen-7B-qlora-moss-003-sft is fine-tuned from [Qwen-7B](https://huggingface.co/Qwen/Qwen-7B) 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('Qwen/Qwen-7B', 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('Qwen/Qwen-7B', quantization_config=quantization_config, device_map='auto', trust_remote_code=True).eval()
45
+ model = PeftModel.from_pretrained(model, 'xtuner/Qwen-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
+ prompt_template = (
49
+ 'You are an AI assistant whose name is Qwen.\n'
50
+ 'Capabilities and tools that Qwen can possess.\n'
51
+ '- Inner thoughts: disabled.\n'
52
+ '- Web search: disabled.\n'
53
+ '- Calculator: disabled.\n'
54
+ '- Equation solver: disabled.\n'
55
+ '- Text-to-image: disabled.\n'
56
+ '- Image edition: disabled.\n'
57
+ '- Text-to-speech: disabled.\n'
58
+ '<|Human|>: {input}<eoh>')
59
+
60
+ text = '请给我介绍五个上海的景点'
61
+ inputs = tokenizer(prompt_template.format(input=text), return_tensors='pt')
62
+ inputs = inputs.to(model.device)
63
+ pred = model.generate(**inputs, generation_config=gen_config, stopping_criteria=[StopWordStoppingCriteria(tokenizer, '<eom>')])
64
+ print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
65
+ """
66
+ 好的,以下是五个上海的景点介绍:
67
+ 1. 上海博物馆:上海博物馆是中国最大的综合性博物馆之一,收藏了大量的历史文物和艺术品,包括青铜器、陶瓷、书画、玉器等。
68
+ 2. 上海城隍庙:上海城隍庙是上海最古老的庙宇之一,建于明朝,是上海的标志性建筑之一。庙内有各种神像和文物,是了解上海历史文化的好去处。
69
+ 3. 上海科技馆:上海科技馆是一座集科技、文化、教育为一体的综合性博物馆,展示了各种科技展品和互动体验项目,适合全家人一起参观。
70
+ 4. 上海东方明珠塔:上海东方明珠塔是上海的标志性建筑之一,高468米。游客可以乘坐高速电梯到达观景台,欣赏上海的美景。
71
+ 5. 上海迪士尼乐园:上海迪士尼乐园是中国第一个迪士尼主题公园,拥有各种游乐设施和表演节目,适合全家人一起游玩。
72
+ """
73
+ ```
74
+
75
+ ### Usage with XTuner CLI
76
+
77
+ #### Installation
78
+
79
+ ```shell
80
+ pip install xtuner
81
+ ```
82
+
83
+ #### Chat
84
+
85
+ ```shell
86
+ xtuner chat hf Qwen/Qwen-7B --adapter xtuner/Qwen-7B-qlora-moss-003-sft --bot-name Qwen --prompt-template moss_sft --with-plugins calculate solve search --command-stop-word "<eoc>" --answer-stop-word "<eom>"
87
+ ```
88
+
89
+ #### Fine-tune
90
+
91
+ Use the following command to quickly reproduce the fine-tuning results.
92
+
93
+ ```shell
94
+ NPROC_PER_NODE=8 xtuner train qwen_7b_qlora_moss_sft_all_gpu8_e2 # Recommended!
95
+ xtuner train qwen_7b_qlora_moss_sft_all_e1
96
+ ```