kimsan0622 commited on
Commit
58ada82
1 Parent(s): 9898ce0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +191 -1
README.md CHANGED
@@ -14,7 +14,7 @@ model-index:
14
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
15
  should probably proofread and complete it, then remove this comment. -->
16
 
17
- # **Llama-3.2-3B-Code-Knowledge-Value-Eval **
18
 
19
  This model is a fine-tuned version of [meta-llama/Llama-3.2-3B](https://huggingface.co/meta-llama/Llama-3.2-3B) on the [kimsan0622/code-knowledge-eval](https://huggingface.co/datasets/kimsan0622/code-knowledge-eval) dataset.
20
  It achieves the following results on the evaluation set:
@@ -38,6 +38,135 @@ The model focuses on understanding the structure, syntax, and logic of various p
38
  2. **Language and Domain Limitations**: Since the dataset is sourced from `bigcode/the-stack`, it may not cover all programming languages or specialized domains. The model may perform less effectively in underrepresented languages or niche coding styles not well-represented in the dataset.
39
  3. **Not Suitable for All Educational Levels**: While the model is designed to evaluate code for educational purposes, its outputs may be better suited for certain levels (e.g., beginner or intermediate coding), and its recommendations might not fully cater to advanced or highly specialized learners.
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  ## Training and evaluation data
42
 
43
  [kimsan0622/code-knowledge-eval](https://huggingface.co/datasets/kimsan0622/code-knowledge-eval)
@@ -110,3 +239,64 @@ The following hyperparameters were used during training:
110
  | **weighted avg** | 0.55 | 0.56 | 0.55 | 18232 |
111
 
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
15
  should probably proofread and complete it, then remove this comment. -->
16
 
17
+ # **Llama-3.2-3B-Code-Knowledge-Value-Eval**
18
 
19
  This model is a fine-tuned version of [meta-llama/Llama-3.2-3B](https://huggingface.co/meta-llama/Llama-3.2-3B) on the [kimsan0622/code-knowledge-eval](https://huggingface.co/datasets/kimsan0622/code-knowledge-eval) dataset.
20
  It achieves the following results on the evaluation set:
 
38
  2. **Language and Domain Limitations**: Since the dataset is sourced from `bigcode/the-stack`, it may not cover all programming languages or specialized domains. The model may perform less effectively in underrepresented languages or niche coding styles not well-represented in the dataset.
39
  3. **Not Suitable for All Educational Levels**: While the model is designed to evaluate code for educational purposes, its outputs may be better suited for certain levels (e.g., beginner or intermediate coding), and its recommendations might not fully cater to advanced or highly specialized learners.
40
 
41
+
42
+ ## How to use this model?
43
+
44
+ ```python
45
+ import torch
46
+ import numpy as np
47
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
48
+
49
+ # Define the model name or path for loading the tokenizer and model
50
+ model_name_or_path = "kimsan0622/Llama-3.2-3B-Code-Knowledge-Value-Eval"
51
+
52
+ # Load the tokenizer from the pre-trained model
53
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
54
+
55
+ # Load the pre-trained model for sequence classification and map it to the first CUDA device
56
+ model = AutoModelForSequenceClassification.from_pretrained(
57
+ model_name_or_path,
58
+ device_map="cuda:0",
59
+ )
60
+
61
+ # Example code snippet to be evaluated
62
+ code = [
63
+ """
64
+ import torch
65
+ import numpy as np
66
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
67
+
68
+ # Define the model name or path for loading the tokenizer and model
69
+ model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
70
+
71
+ # Load the tokenizer from the pre-trained model
72
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
73
+
74
+ # Load the pre-trained model for sequence classification and map it to the first CUDA device
75
+ model = AutoModelForSequenceClassification.from_pretrained(
76
+ model_name_or_path,
77
+ device_map="cuda:0",
78
+ )
79
+
80
+ # Example code snippet to be evaluated
81
+ code = ["code 1"]
82
+
83
+ # Tokenize the input code, setting max length, padding, and truncation
84
+ batch = tokenizer(code, max_length=1024, padding=True, truncation=True, return_tensors="pt")
85
+
86
+ # Perform inference with the model, without computing gradients (for faster inference)
87
+ with torch.no_grad():
88
+ # Pass the input IDs and attention mask to the model, using the CUDA device
89
+ res = model(
90
+ input_ids=batch["input_ids"].to("cuda:0"),
91
+ attention_mask=batch["attention_mask"].to("cuda:0"),
92
+ )
93
+
94
+ # Move the logits to the CPU, convert them to a numpy array
95
+ preds = res.logits.cpu().numpy()
96
+
97
+ # Get the predicted class by taking the argmax of the logits across the classification axis
98
+ preds = np.argmax(preds, axis=1).tolist()
99
+ """
100
+ ]
101
+
102
+ # Tokenize the input code, setting max length, padding, and truncation
103
+ batch = tokenizer(code, max_length=1024, padding=True, truncation=True, return_tensors="pt")
104
+
105
+ # Perform inference with the model, without computing gradients (for faster inference)
106
+ with torch.no_grad():
107
+ # Pass the input IDs and attention mask to the model, using the CUDA device
108
+ res = model(
109
+ input_ids=batch["input_ids"].to("cuda:0"),
110
+ attention_mask=batch["attention_mask"].to("cuda:0"),
111
+ )
112
+
113
+ # Move the logits to the CPU, convert them to a numpy array
114
+ preds = res.logits.cpu().numpy()
115
+
116
+ # Get the predicted class by taking the argmax of the logits across the classification axis
117
+ preds = np.argmax(preds, axis=1).tolist()
118
+ print(preds)
119
+ ```
120
+
121
+ ### 8 Bit quantization
122
+
123
+ ```python
124
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
125
+
126
+ # Define the model name or path for loading the model
127
+ model_name_or_path = "kimsan0622/Llama-3.2-3B-Code-Knowledge-Value-Eval"
128
+
129
+ # Configure the model to load in 8-bit precision for memory efficiency
130
+ bnb_config = BitsAndBytesConfig(load_in_8bit=True)
131
+
132
+ # Load the pre-trained model for sequence classification with quantization for 8-bit precision
133
+ # This helps reduce memory usage, particularly for large models, and map it to the first CUDA device
134
+ model = AutoModelForSequenceClassification.from_pretrained(
135
+ model_name_or_path,
136
+ quantization_config=bnb_config, # Apply 8-bit quantization
137
+ device_map="cuda:0", # Map the model to the first CUDA device
138
+ )
139
+ ```
140
+
141
+ ### 4 Bit quntization
142
+ ```python
143
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
144
+ import torch
145
+
146
+ # Define the model name or path for loading the model
147
+ model_name_or_path = "kimsan0622/Llama-3.2-3B-Code-Knowledge-Value-Eval"
148
+
149
+ # Define configuration parameters for 4-bit quantization
150
+ bnb_config_params = {
151
+ "bnb_4bit_quant_type": "fp4", # Use FP4 for 4-bit quantization type
152
+ "bnb_4bit_compute_dtype": torch.bfloat16, # Use bfloat16 for computation to balance performance and precision
153
+ "bnb_4bit_use_double_quant": False, # Disable double quantization, which is typically used to further reduce precision
154
+ "bnb_4bit_quant_storage": torch.bfloat16, # Store quantized values in bfloat16 format
155
+ }
156
+
157
+ # Configure the model to load in 4-bit precision for memory and performance optimization
158
+ bnb_config = BitsAndBytesConfig(load_in_4bit=True, **bnb_config_params)
159
+
160
+ # Load the pre-trained model for sequence classification with 4-bit quantization settings
161
+ # This reduces memory usage while still maintaining reasonable accuracy, mapping the model to the first CUDA device
162
+ model = AutoModelForSequenceClassification.from_pretrained(
163
+ model_name_or_path,
164
+ quantization_config=bnb_config, # Apply 4-bit quantization configuration
165
+ device_map="cuda:0", # Map the model to the first CUDA device
166
+ )
167
+ ```
168
+
169
+
170
  ## Training and evaluation data
171
 
172
  [kimsan0622/code-knowledge-eval](https://huggingface.co/datasets/kimsan0622/code-knowledge-eval)
 
239
  | **weighted avg** | 0.55 | 0.56 | 0.55 | 18232 |
240
 
241
 
242
+
243
+ ## 8 Bit quantization model
244
+
245
+ ### Confusion matrix
246
+
247
+ | **y_true** |**pred_0**|**pred_1**|**pred_2**|**pred_3**|**pred_4**|**pred_5**|
248
+ |-------|-------|-------|-------|-------|-------|-------|
249
+ | 0 | 933 | 272 | 111 | 56 | 5 | 0 |
250
+ | 1 | 320 | 333 | 340 | 224 | 25 | 2 |
251
+ | 2 | 129 | 244 | 502 | 752 | 139 | 8 |
252
+ | 3 | 43 | 119 | 463 | 2627 | 1604 | 69 |
253
+ | 4 | 7 | 15 | 67 | 1227 | 4191 | 817 |
254
+ | 5 | 0 | 2 | 0 | 30 | 1034 | 1522 |
255
+
256
+
257
+ ### Classification report
258
+
259
+ | **y_true** | **precision** | **recall** | **f1-score** | **support** |
260
+ |:-------------:|:-------------:|:----------:|:------------:|:-----------:|
261
+ | 0 | 0.65 | 0.68 | 0.66 | 1377 |
262
+ | 1 | 0.34 | 0.27 | 0.30 | 1244 |
263
+ | 2 | 0.34 | 0.28 | 0.31 | 1774 |
264
+ | 3 | 0.53 | 0.53 | 0.53 | 4925 |
265
+ | 4 | 0.60 | 0.66 | 0.63 | 6324 |
266
+ | 5 | 0.63 | 0.59 | 0.61 | 2588 |
267
+ | **accuracy** | | | 0.55 | 18232 |
268
+ | **macro avg**| 0.52 | 0.50 | 0.51 | 18232 |
269
+ | **weighted avg** | 0.55 | 0.55 | 0.55 | 18232 |
270
+
271
+
272
+
273
+ ## 4 Bit quantization model
274
+
275
+ ### Confusion matrix
276
+
277
+ | **y_true** |**pred_0**|**pred_1**|**pred_2**|**pred_3**|**pred_4**|**pred_5**|
278
+ |-------|-------|-------|-------|-------|-------|-------|
279
+ | 0 | 695 | 581 | 42 | 55 | 4 | 0 |
280
+ | 1 | 151 | 662 | 190 | 215 | 24 | 2 |
281
+ | 2 | 53 | 485 | 353 | 716 | 159 | 8 |
282
+ | 3 | 20 | 277 | 335 | 2446 | 1765 | 82 |
283
+ | 4 | 4 | 31 | 60 | 1104 | 4211 | 914 |
284
+ | 5 | 0 | 2 | 0 | 24 | 934 | 1628 |
285
+
286
+
287
+
288
+
289
+ ### Classification report
290
+
291
+ | | **precision** | **recall** | **f1-score** | **support** |
292
+ |:-------------:|:-------------:|:----------:|:------------:|:-----------:|
293
+ | 0 | 0.75 | 0.50 | 0.60 | 1377 |
294
+ | 1 | 0.32 | 0.53 | 0.40 | 1244 |
295
+ | 2 | 0.36 | 0.20 | 0.26 | 1774 |
296
+ | 3 | 0.54 | 0.50 | 0.52 | 4925 |
297
+ | 4 | 0.59 | 0.67 | 0.63 | 6324 |
298
+ | 5 | 0.62 | 0.63 | 0.62 | 2588 |
299
+ | **accuracy** | | | 0.55 | 18232 |
300
+ | **macro avg**| 0.53 | 0.50 | 0.51 | 18232 |
301
+ | **weighted avg** | 0.55 | 0.55 | 0.54 | 18232 |
302
+