This model is a fine-tuned version of
meta-llama/Llama-3.2-3B on the
kimsan0622/code-knowledge-eval dataset.
It achieves the following results on the evaluation set:
The model focuses on understanding the structure, syntax, and logic of various programming languages, enabling it to provide insights into the learning potential and technical depth of different code samples. The dataset used for training consists of 22,786 samples for training, 4,555 for validation, and 18,232 for testing, ensuring that the model is both robust and well-generalized across different coding contexts.
1import torch
2import numpy as np
3from transformers import AutoTokenizer, AutoModelForSequenceClassification
4from peft import PeftModel, PeftConfig
5
6# Define the model name or path for loading the tokenizer and model using LoRA fine-tuning
7model_name_or_path = "kimsan0622/Llama-3.2-3B-Code-Knowledge-Value-Eval-lora"
8
9# Load the PEFT (Parameter-Efficient Fine-Tuning) configuration from the pretrained model
10config = PeftConfig.from_pretrained(model_name_or_path)
11
12# Load the base model for sequence classification, setting up for 6 possible labels
13inference_model = AutoModelForSequenceClassification.from_pretrained(
14 config.base_model_name_or_path, # Base model path
15 device_map="cuda:0", # Use the first CUDA device for inference
16 label2id={str(k): k for k in range(6)}, # Map label names (0-5) to IDs
17 id2label={k: str(k) for k in range(6)}, # Map label IDs to names (0-5)
18 num_labels=6, # Define the number of labels for classification (0 to 5)
19)
20
21# Load the tokenizer for the base model
22tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
23
24# Set the padding token if it is not already defined, matching it with the EOS token
25if not tokenizer.pad_token_id:
26 tokenizer.pad_token_id = tokenizer.eos_token_id
27 inference_model.config.pad_token_id = inference_model.config.eos_token_id
28
29# Load the PEFT model using the pre-trained LoRA model and the base model
30model = PeftModel.from_pretrained(inference_model, model_name_or_path)
31
32# Sample code input to evaluate
33code = [
34"""
35import torch
36import numpy as np
37from transformers import AutoTokenizer, AutoModelForSequenceClassification
38from peft import PeftModel, PeftConfig
39
40# Define the model name or path for loading the tokenizer and model using LoRA fine-tuning
41model_name_or_path = "kimsan0622/Llama-3.2-3B-Code-Knowledge-Value-Eval-lora"
42
43# Load the PEFT (Parameter-Efficient Fine-Tuning) configuration from the pretrained model
44config = PeftConfig.from_pretrained(model_name_or_path)
45
46# Load the base model for sequence classification, setting up for 6 possible labels
47inference_model = AutoModelForSequenceClassification.from_pretrained(
48 config.base_model_name_or_path, # Base model path
49 device_map="cuda:0", # Use the first CUDA device for inference
50 label2id={str(k): k for k in range(6)}, # Map label names (0-5) to IDs
51 id2label={k: str(k) for k in range(6)}, # Map label IDs to names (0-5)
52 num_labels=6, # Define the number of labels for classification (0 to 5)
53)
54
55# Load the tokenizer for the base model
56tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
57
58# Set the padding token if it is not already defined, matching it with the EOS token
59if not tokenizer.pad_token_id:
60 tokenizer.pad_token_id = tokenizer.eos_token_id
61 inference_model.config.pad_token_id = inference_model.config.eos_token_id
62
63# Load the PEFT model using the pre-trained LoRA model and the base model
64model = PeftModel.from_pretrained(inference_model, model_name_or_path)
65
66# Sample code input to evaluate
67code = ["code"]
68
69# Tokenize the input code, setting the maximum length and ensuring proper padding and truncation
70batch = tokenizer(code, max_length=1024, padding=True, truncation=True, return_tensors="pt")
71
72# Perform inference without computing gradients for faster processing
73with torch.no_grad():
74 # Pass the input IDs and attention mask to the model for prediction
75 res = model(
76 input_ids=batch["input_ids"].to("cuda:0"),
77 attention_mask=batch["attention_mask"].to("cuda:0"),
78 )
79
80 # Move the logits to the CPU and convert them to a numpy array
81 preds = res.logits.cpu().numpy()
82
83 # Get the predicted label by taking the argmax of the logits
84 preds = np.argmax(preds, axis=1).tolist()
85
86 # Print the predicted labels
87 print(preds)
88"""
89]
90
91# Tokenize the input code, setting the maximum length and ensuring proper padding and truncation
92batch = tokenizer(code, max_length=1024, padding=True, truncation=True, return_tensors="pt")
93
94# Perform inference without computing gradients for faster processing
95with torch.no_grad():
96 # Pass the input IDs and attention mask to the model for prediction
97 res = model(
98 input_ids=batch["input_ids"].to("cuda:0"),
99 attention_mask=batch["attention_mask"].to("cuda:0"),
100 )
101
102 # Move the logits to the CPU and convert them to a numpy array
103 preds = res.logits.cpu().numpy()
104
105 # Get the predicted label by taking the argmax of the logits
106 preds = np.argmax(preds, axis=1).tolist()
107
108 # Print the predicted labels
109 print(preds)
110
1from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
2from peft import PeftModel, PeftConfig
3
4# Define the model name or path for loading the LoRA fine-tuned model
5model_name_or_path = "kimsan0622/Llama-3.2-3B-Code-Knowledge-Value-Eval-lora"
6
7# Configure the model to load in 8-bit precision to optimize memory usage and speed
8bnb_config = BitsAndBytesConfig(load_in_8bit=True)
9
10# Load the PEFT (Parameter-Efficient Fine-Tuning) configuration from the pre-trained model
11config = PeftConfig.from_pretrained(model_path)
12
13# Load the base model for sequence classification with 8-bit quantization and a device map to the first CUDA device
14inference_model = AutoModelForSequenceClassification.from_pretrained(
15 config.base_model_name_or_path, # Base model path from PEFT config
16 quantization_config=bnb_config, # Apply 8-bit quantization for memory efficiency
17 device_map="cuda:0", # Map the model to the first CUDA device
18 label2id={str(k): k for k in range(6)}, # Map label names (0-5) to label IDs
19 id2label={k: str(k) for k in range(6)}, # Map label IDs to label names (0-5)
20 num_labels=6, # Specify the number of labels for classification
21)
22
23# Load the tokenizer associated with the base model
24tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
25
26# Set the padding token if it's not defined, using the EOS token as the fallback
27if not tokenizer.pad_token_id:
28 tokenizer.pad_token_id = tokenizer.eos_token_id
29 inference_model.config.pad_token_id = inference_model.config.eos_token_id
30
31# Load the PEFT model by applying LoRA (Low-Rank Adaptation) on top of the base model
32model = PeftModel.from_pretrained(inference_model, model_path)