mlabonne commited on
Commit
a422f49
Β·
1 Parent(s): d4fe099

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +75 -0
README.md ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - mlabonne/CodeLlama-2-20k
5
+ tags:
6
+ - code
7
+ ---
8
+
9
+ # πŸ¦™πŸ’» CodeLlama
10
+
11
+ πŸ“ [Article](https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32) |
12
+ πŸ’» [Colab](https://colab.research.google.com/drive/1PEQyJO1-f6j0S_XJ8DV50NkpzasXkrzd?usp=sharing) |
13
+ πŸ“„ [Script](https://gist.github.com/mlabonne/b5718e1b229ce6553564e3f56df72c5c)
14
+
15
+ <center><img src="https://i.imgur.com/yTPNIZj.png" width="300"></center>
16
+
17
+ `CodeLlama-7b` is a Llama 2 version of [**CodeAlpaca**](https://github.com/sahil280114/codealpaca).
18
+
19
+ ## πŸ”§ Training
20
+
21
+ This model is based on the `Llama-2-7b-hf` model, fine-tuned using QLoRA on the [`mlabonne/CodeLlama-2-20k`](https://huggingface.co/datasets/mlabonne/CodeLlama-2-20k) dataset. It was trained on an RTX 3090 and can be used for inference.
22
+
23
+ It was trained using this custom [`finetune_llama2.py`](https://gist.github.com/mlabonne/b5718e1b229ce6553564e3f56df72c5c) script as follows:
24
+
25
+ ``` bash
26
+ python finetune_llama2.py --dataset_name=mlabonne/CodeLlama-2-20k --new_model=mlabonne/codellama-2-7b --bf16=True --learning_rate=2e-5
27
+ ```
28
+
29
+ <center><img src="https://i.imgur.com/5Qx7Kzo.png"></center>
30
+
31
+ ## πŸ’» Usage
32
+
33
+ ``` python
34
+ # pip install transformers accelerate
35
+
36
+ from transformers import AutoTokenizer
37
+ import transformers
38
+ import torch
39
+
40
+ model = "mlabonne/codellama-2-7b"
41
+ prompt = "Write Python code to generate an array with all the numbers from 1 to 100"
42
+
43
+ tokenizer = AutoTokenizer.from_pretrained(model)
44
+ pipeline = transformers.pipeline(
45
+ "text-generation",
46
+ model=model,
47
+ torch_dtype=torch.float16,
48
+ device_map="auto",
49
+ )
50
+
51
+ sequences = pipeline(
52
+ f'<s>[INST] {prompt} [/INST]',
53
+ do_sample=True,
54
+ top_k=10,
55
+ num_return_sequences=1,
56
+ eos_token_id=tokenizer.eos_token_id,
57
+ max_length=200,
58
+ )
59
+ for seq in sequences:
60
+ print(f"Result: {seq['generated_text']}")
61
+ ```
62
+
63
+ Ouput:
64
+ ```
65
+ Here is a Python code to generate an array with all the numbers from 1 to 100:
66
+
67
+ β€…```
68
+ numbers = []
69
+ for i in range(1,101):
70
+ numbers.append(i)
71
+ β€…```
72
+
73
+ This code generates an array with all the numbers from 1 to 100 in Python. It uses a loop that iterates over the range of numbers from 1 to 100, and for each number, it appends that number to the array 'numbers'. The variable 'numbers' is initialized to a list, and its length is set to 101 by using the range of numbers (0-99).
74
+
75
+ ```