This model is a fine-tuned version of
meta-llama/Llama-3.2-1B 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
4
5# Define the model name or path for loading the tokenizer and model
6model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
7
8# Load the tokenizer from the pre-trained model
9tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
10
11# Load the pre-trained model for sequence classification and map it to the first CUDA device
12model = AutoModelForSequenceClassification.from_pretrained(
13 model_name_or_path,
14 device_map="cuda:0",
15)
16
17# Example code snippet to be evaluated
18code = [
19"""
20import torch
21import numpy as np
22from transformers import AutoTokenizer, AutoModelForSequenceClassification
23
24# Define the model name or path for loading the tokenizer and model
25model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
26
27# Load the tokenizer from the pre-trained model
28tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
29
30# Load the pre-trained model for sequence classification and map it to the first CUDA device
31model = AutoModelForSequenceClassification.from_pretrained(
32 model_name_or_path,
33 device_map="cuda:0",
34)
35
36# Example code snippet to be evaluated
37code = ["code 1"]
38
39# Tokenize the input code, setting max length, padding, and truncation
40batch = tokenizer(code, max_length=1024, padding=True, truncation=True, return_tensors="pt")
41
42# Perform inference with the model, without computing gradients (for faster inference)
43with torch.no_grad():
44 # Pass the input IDs and attention mask to the model, using the CUDA device
45 res = model(
46 input_ids=batch["input_ids"].to("cuda:0"),
47 attention_mask=batch["attention_mask"].to("cuda:0"),
48 )
49
50 # Move the logits to the CPU, convert them to a numpy array
51 preds = res.logits.cpu().numpy()
52
53 # Get the predicted class by taking the argmax of the logits across the classification axis
54 preds = np.argmax(preds, axis=1).tolist()
55"""
56]
57
58# Tokenize the input code, setting max length, padding, and truncation
59batch = tokenizer(code, max_length=1024, padding=True, truncation=True, return_tensors="pt")
60
61# Perform inference with the model, without computing gradients (for faster inference)
62with torch.no_grad():
63 # Pass the input IDs and attention mask to the model, using the CUDA device
64 res = model(
65 input_ids=batch["input_ids"].to("cuda:0"),
66 attention_mask=batch["attention_mask"].to("cuda:0"),
67 )
68
69 # Move the logits to the CPU, convert them to a numpy array
70 preds = res.logits.cpu().numpy()
71
72 # Get the predicted class by taking the argmax of the logits across the classification axis
73 preds = np.argmax(preds, axis=1).tolist()
74 print(preds)
1from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
2
3# Define the model name or path for loading the model
4model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
5
6# Configure the model to load in 8-bit precision for memory efficiency
7bnb_config = BitsAndBytesConfig(load_in_8bit=True)
8
9# Load the pre-trained model for sequence classification with quantization for 8-bit precision
10# This helps reduce memory usage, particularly for large models, and map it to the first CUDA device
11model = AutoModelForSequenceClassification.from_pretrained(
12 model_name_or_path,
13 quantization_config=bnb_config, # Apply 8-bit quantization
14 device_map="cuda:0", # Map the model to the first CUDA device
15)
1from transformers import AutoTokenizer, AutoModelForSequenceClassification, BitsAndBytesConfig
2import torch
3
4# Define the model name or path for loading the model
5model_name_or_path = "kimsan0622/Llama-3.2-1B-Code-Knowledge-Value-Eval"
6
7# Define configuration parameters for 4-bit quantization
8bnb_config_params = {
9 "bnb_4bit_quant_type": "fp4", # Use FP4 for 4-bit quantization type
10 "bnb_4bit_compute_dtype": torch.bfloat16, # Use bfloat16 for computation to balance performance and precision
11 "bnb_4bit_use_double_quant": False, # Disable double quantization, which is typically used to further reduce precision
12 "bnb_4bit_quant_storage": torch.bfloat16, # Store quantized values in bfloat16 format
13}
14
15# Configure the model to load in 4-bit precision for memory and performance optimization
16bnb_config = BitsAndBytesConfig(load_in_4bit=True, **bnb_config_params)
17
18# Load the pre-trained model for sequence classification with 4-bit quantization settings
19# This reduces memory usage while still maintaining reasonable accuracy, mapping the model to the first CUDA device
20model = AutoModelForSequenceClassification.from_pretrained(
21 model_name_or_path,
22 quantization_config=bnb_config, # Apply 4-bit quantization configuration
23 device_map="cuda:0", # Map the model to the first CUDA device
24)