kimsan0622 commited on
Commit
1c788a5
·
verified ·
1 Parent(s): fe24856

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +189 -5
README.md CHANGED
@@ -39,6 +39,134 @@ The model focuses on understanding the structure, syntax, and logic of various p
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
  ## Training and evaluation data
43
 
44
  [kimsan0622/code-knowledge-eval](https://huggingface.co/datasets/kimsan0622/code-knowledge-eval)
@@ -80,7 +208,7 @@ The following hyperparameters were used during training:
80
 
81
  ### Confusion matrix
82
 
83
- | y_true |**pred_0**|**pred_1**|**pred_2**|**pred_3**|**pred_4**|**pred_5**|
84
  |:------:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
85
  | 0 | 595 | 680 | 21 | 70 | 11 | 0 |
86
  | 1 | 116 | 727 | 76 | 283 | 39 | 3 |
@@ -90,12 +218,8 @@ The following hyperparameters were used during training:
90
  | 5 | 0 | 3 | 0 | 20 | 583 | 1982 |
91
 
92
 
93
-
94
-
95
  ### Classification report
96
 
97
-
98
-
99
  | **y_true** | **precision** | **recall** | **f1-score** | **support** |
100
  |:-------------:|:-------------:|:----------:|:------------:|:-----------:|
101
  | 0 | 0.78 | 0.43 | 0.56 | 1377 |
@@ -108,3 +232,63 @@ The following hyperparameters were used during training:
108
  | **macro avg**| 0.52 | 0.49 | 0.47 | 18232 |
109
  | **weighted avg** | 0.53 | 0.53 | 0.51 | 18232 |
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
43
+ ## How to use this model?
44
+
45
+ ```python
46
+ import torch
47
+ import numpy as np
48
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
49
+
50
+ # Define the model name or path for loading the tokenizer and model
51
+ model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
52
+
53
+ # Load the tokenizer from the pre-trained model
54
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
55
+
56
+ # Load the pre-trained model for sequence classification and map it to the first CUDA device
57
+ model = AutoModelForSequenceClassification.from_pretrained(
58
+ model_name_or_path,
59
+ device_map="cuda:0",
60
+ )
61
+
62
+ # Example code snippet to be evaluated
63
+ code = [
64
+ """
65
+ import torch
66
+ import numpy as np
67
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
68
+
69
+ # Define the model name or path for loading the tokenizer and model
70
+ model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
71
+
72
+ # Load the tokenizer from the pre-trained model
73
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
74
+
75
+ # Load the pre-trained model for sequence classification and map it to the first CUDA device
76
+ model = AutoModelForSequenceClassification.from_pretrained(
77
+ model_name_or_path,
78
+ device_map="cuda:0",
79
+ )
80
+
81
+ # Example code snippet to be evaluated
82
+ code = ["code 1"]
83
+
84
+ # Tokenize the input code, setting max length, padding, and truncation
85
+ batch = tokenizer(code, max_length=1024, padding=True, truncation=True, return_tensors="pt")
86
+
87
+ # Perform inference with the model, without computing gradients (for faster inference)
88
+ with torch.no_grad():
89
+ # Pass the input IDs and attention mask to the model, using the CUDA device
90
+ res = model(
91
+ input_ids=batch["input_ids"].to("cuda:0"),
92
+ attention_mask=batch["attention_mask"].to("cuda:0"),
93
+ )
94
+
95
+ # Move the logits to the CPU, convert them to a numpy array
96
+ preds = res.logits.cpu().numpy()
97
+
98
+ # Get the predicted class by taking the argmax of the logits across the classification axis
99
+ preds = np.argmax(preds, axis=1).tolist()
100
+ """
101
+ ]
102
+
103
+ # Tokenize the input code, setting max length, padding, and truncation
104
+ batch = tokenizer(code, max_length=1024, padding=True, truncation=True, return_tensors="pt")
105
+
106
+ # Perform inference with the model, without computing gradients (for faster inference)
107
+ with torch.no_grad():
108
+ # Pass the input IDs and attention mask to the model, using the CUDA device
109
+ res = model(
110
+ input_ids=batch["input_ids"].to("cuda:0"),
111
+ attention_mask=batch["attention_mask"].to("cuda:0"),
112
+ )
113
+
114
+ # Move the logits to the CPU, convert them to a numpy array
115
+ preds = res.logits.cpu().numpy()
116
+
117
+ # Get the predicted class by taking the argmax of the logits across the classification axis
118
+ preds = np.argmax(preds, axis=1).tolist()
119
+ print(preds)
120
+ ```
121
+
122
+ ### 8 Bit quantization
123
+
124
+ ```python
125
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
126
+
127
+ # Define the model name or path for loading the model
128
+ model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
129
+
130
+ # Configure the model to load in 8-bit precision for memory efficiency
131
+ bnb_config = BitsAndBytesConfig(load_in_8bit=True)
132
+
133
+ # Load the pre-trained model for sequence classification with quantization for 8-bit precision
134
+ # This helps reduce memory usage, particularly for large models, and map it to the first CUDA device
135
+ model = AutoModelForSequenceClassification.from_pretrained(
136
+ model_name_or_path,
137
+ quantization_config=bnb_config, # Apply 8-bit quantization
138
+ device_map="cuda:0", # Map the model to the first CUDA device
139
+ )
140
+ ```
141
+
142
+ ### 4 Bit quntization
143
+ ```python
144
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
145
+ import torch
146
+
147
+ # Define the model name or path for loading the model
148
+ model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
149
+
150
+ # Define configuration parameters for 4-bit quantization
151
+ bnb_config_params = {
152
+ "bnb_4bit_quant_type": "fp4", # Use FP4 for 4-bit quantization type
153
+ "bnb_4bit_compute_dtype": torch.bfloat16, # Use bfloat16 for computation to balance performance and precision
154
+ "bnb_4bit_use_double_quant": False, # Disable double quantization, which is typically used to further reduce precision
155
+ "bnb_4bit_quant_storage": torch.bfloat16, # Store quantized values in bfloat16 format
156
+ }
157
+
158
+ # Configure the model to load in 4-bit precision for memory and performance optimization
159
+ bnb_config = BitsAndBytesConfig(load_in_4bit=True, **bnb_config_params)
160
+
161
+ # Load the pre-trained model for sequence classification with 4-bit quantization settings
162
+ # This reduces memory usage while still maintaining reasonable accuracy, mapping the model to the first CUDA device
163
+ model = AutoModelForSequenceClassification.from_pretrained(
164
+ model_name_or_path,
165
+ quantization_config=bnb_config, # Apply 4-bit quantization configuration
166
+ device_map="cuda:0", # Map the model to the first CUDA device
167
+ )
168
+ ```
169
+
170
  ## Training and evaluation data
171
 
172
  [kimsan0622/code-knowledge-eval](https://huggingface.co/datasets/kimsan0622/code-knowledge-eval)
 
208
 
209
  ### Confusion matrix
210
 
211
+ | **y_true** |**pred_0**|**pred_1**|**pred_2**|**pred_3**|**pred_4**|**pred_5**|
212
  |:------:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
213
  | 0 | 595 | 680 | 21 | 70 | 11 | 0 |
214
  | 1 | 116 | 727 | 76 | 283 | 39 | 3 |
 
218
  | 5 | 0 | 3 | 0 | 20 | 583 | 1982 |
219
 
220
 
 
 
221
  ### Classification report
222
 
 
 
223
  | **y_true** | **precision** | **recall** | **f1-score** | **support** |
224
  |:-------------:|:-------------:|:----------:|:------------:|:-----------:|
225
  | 0 | 0.78 | 0.43 | 0.56 | 1377 |
 
232
  | **macro avg**| 0.52 | 0.49 | 0.47 | 18232 |
233
  | **weighted avg** | 0.53 | 0.53 | 0.51 | 18232 |
234
 
235
+
236
+ ## 8 bit quantization
237
+
238
+ ### Confusion matrix
239
+
240
+ | **y_true** | **precision** | **recall** | **f1-score** | **support** |
241
+ |-------|-------|-------|-------|-------|-------|-------|
242
+ | 0 | 612 | 660 | 22 | 72 | 11 | 0 |
243
+ | 1 | 128 | 705 | 83 | 287 | 38 | 3 |
244
+ | 2 | 37 | 529 | 120 | 887 | 183 | 18 |
245
+ | 3 | 14 | 277 | 106 | 2413 | 1943 | 172 |
246
+ | 4 | 3 | 42 | 8 | 944 | 3791 | 1536 |
247
+ | 5 | 0 | 3 | 0 | 20 | 588 | 1977 |
248
+
249
+
250
+
251
+ ### Classification report
252
+
253
+ | **y_true** | **precision** | **recall** | **f1-score** | **support** |
254
+ |:-------------:|:-------------:|:----------:|:------------:|:-----------:|
255
+ | 0 | 0.77 | 0.44 | 0.56 | 1377 |
256
+ | 1 | 0.32 | 0.57 | 0.41 | 1244 |
257
+ | 2 | 0.35 | 0.07 | 0.11 | 1774 |
258
+ | 3 | 0.52 | 0.49 | 0.51 | 4925 |
259
+ | 4 | 0.58 | 0.60 | 0.59 | 6324 |
260
+ | 5 | 0.53 | 0.76 | 0.63 | 2588 |
261
+ | **accuracy** | | | 0.53 | 18232 |
262
+ | **macro avg**| 0.51 | 0.49 | 0.47 | 18232 |
263
+ | **weighted avg** | 0.53 | 0.53 | 0.51 | 18232 |
264
+
265
+
266
+
267
+ ## 4 bit quantization
268
+
269
+ ### Confusion matrix
270
+
271
+ | **y_true** | **precision** | **recall** | **f1-score** | **support** |
272
+ |-------|-------|-------|-------|-------|-------|-------|
273
+ | 0 | 473 | 792 | 10 | 91 | 11 | 0 |
274
+ | 1 | 66 | 767 | 47 | 325 | 38 | 1 |
275
+ | 2 | 22 | 541 | 74 | 955 | 166 | 16 |
276
+ | 3 | 8 | 282 | 55 | 2609 | 1824 | 147 |
277
+ | 4 | 3 | 39 | 3 | 1049 | 3831 | 1399 |
278
+ | 5 | 0 | 3 | 0 | 24 | 672 | 1889 |
279
+
280
+
281
+ ### Classification report
282
+
283
+ | **y_true** | **precision** | **recall** | **f1-score** | **support** |
284
+ |:-------------:|:-------------:|:----------:|:------------:|:-----------:|
285
+ | 0 | 0.83 | 0.34 | 0.49 | 1377 |
286
+ | 1 | 0.32 | 0.62 | 0.42 | 1244 |
287
+ | 2 | 0.39 | 0.04 | 0.08 | 1774 |
288
+ | 3 | 0.52 | 0.53 | 0.52 | 4925 |
289
+ | 4 | 0.59 | 0.61 | 0.60 | 6324 |
290
+ | 5 | 0.55 | 0.73 | 0.63 | 2588 |
291
+ | **accuracy** | | | 0.53 | 18232 |
292
+ | **macro avg**| 0.53 | 0.48 | 0.45 | 18232 |
293
+ | **weighted avg** | 0.54 | 0.53 | 0.51 | 18232 |
294
+