Pankaj Mathur commited on
Commit
55dc209
1 Parent(s): c1ee8ac

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +65 -3
README.md CHANGED
@@ -1,3 +1,65 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # alpaca_orca_open_llama: A Instruction-Following OpeLLaMA Model using Orca approaches on Alpaca dataset
2
+
3
+
4
+ # Dataset and Training
5
+
6
+ We train OpenLLaMa-3B model on the custom Alpaca dataset created using Orca Research Paper approaches.
7
+ Please pay attention how System prompt is added and used for each instruction.
8
+ The training configurations are provided in the table below.
9
+ The training takes on 4 x A600(50G) GPUs and lasts for around 20 Hours for cost of $66.
10
+ We used DeepSpeed with Zero-3 approaches for parallel gpu training.
11
+
12
+ |||
13
+ |:-------------:|:-------------:|
14
+ |**Batch Size**|16|
15
+ |**train_micro_batch_size_per_gpu**|2|
16
+ |**gradient_accumulation_steps**|2|
17
+ |**Learning rate**|2e-5|
18
+ |**Epochs**|3|
19
+ |**Max length**|1024|
20
+
21
+
22
+
23
+ # Example Usage
24
+
25
+ Below shows an example on how to use OpenAlpaca
26
+
27
+ ```python
28
+ import torch
29
+ from transformers import LlamaForCausalLM, LlamaTokenizer
30
+
31
+ # the previewed version of OpenAlpaca
32
+ model_path = r'psmathur/alpaca_orca_open_llama_3b'
33
+ tokenizer = LlamaTokenizer.from_pretrained(model_path)
34
+ model = LlamaForCausalLM.from_pretrained(model_path).cuda()
35
+ tokenizer.bos_token_id, tokenizer.eos_token_id = 1,2 # see https://github.com/openlm-research/open_llama#preview-weights-release-and-usage
36
+
37
+ # same prompt as provided by Orca Research Paper
38
+ system = r'You are an AI assistant. User will you give you a task. Your goal is to complete the task as faithfully as you can. While performing the task think step-by-step and justify your steps.'
39
+ instruction = r'Use the given data to calculate the median.'
40
+ input = r'[7, 3, 8, 2, 10]'
41
+
42
+
43
+ prompt_no_input = f'.\n\n### Instruction:\n{instruction}\n\n### Response:'
44
+ tokens = tokenizer.encode(prompt_no_input)
45
+
46
+ tokens = torch.LongTensor(tokens).unsqueeze(0)
47
+ instance = {'input_ids': tokens,
48
+ 'top_k': 50,
49
+ 'top_p': 0.9,
50
+ 'generate_len': 128}
51
+
52
+ length = len(tokens[0])
53
+ with torch.no_grad():
54
+ rest = model.generate(
55
+ input_ids=tokens,
56
+ max_length=length+instance['generate_len'],
57
+ use_cache=True,
58
+ do_sample=True,
59
+ top_p=instance['top_p'],
60
+ top_k=instance['top_k']
61
+ )
62
+
63
+ output = rest[0][length:]
64
+ string = tokenizer.decode(output, skip_special_tokens=True)
65
+ print(f'[!] Generation results: {string}')