Views
No views yet
Qwen/Qwen3-1.7B. This model is specialized for generating Python code to solve linear algebra problems described in natural language.numpy library, that solves it.Qwen/Qwen3-1.7B1# First, install necessary libraries
2# !pip install transformers torch peft accelerate bitsandbytes
3
4import torch
5from peft import PeftModel
6from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
7
8BASE_MODEL_ID = "Qwen/Qwen3-1.7B"
9ADAPTER_MODEL_ID = "premjatin/qwen-linear-algebra-coder"
10
11
12quantization_config = BitsAndBytesConfig(load_in_4bit=True)
13
14# Load the base model and tokenizer
15base_model = AutoModelForCausalLM.from_pretrained(
16 BASE_MODEL_ID,
17 torch_dtype=torch.bfloat16,
18 device_map="auto",
19 trust_remote_code=True,
20 quantization_config=quantization_config,
21)
22tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID, trust_remote_code=True)
23tokenizer.pad_token = tokenizer.eos_token
24
25# Load the LoRA adapter
26model = PeftModel.from_pretrained(base_model, ADAPTER_MODEL_ID)
27
28# --- Define a problem ---
29problem_description = """
30Find the eigenvalues and eigenvectors of the following 3x3 matrix:
31[[4, 0, 1],
32 [-2, 1, 0],
33 [-2, 0, 1]]
34"""
35
36# --- Create a structured prompt ---
37prompt = f"""### INSTRUCTION:
38You are an AI assistant that generates Python code to solve linear algebra problems.
39
40### PROBLEM:
41{problem_description}
42
43### PYTHON SOLUTION:
Training Details
Training Data
The model was fine-tuned on a custom dataset of approximately 10,000 problem-and-solution pairs related to linear algebra. The data was structured to teach the model how to convert a word problem into a Python script.
Training Hyperparameters
The model was trained using the PEFT library with the following LoRA configuration:
{
"r": 16,
"lora_alpha": 32,
"lora_dropout": 0.05,
"bias": "none",
"task_type": "CAUSAL_LM",
"target_modules": [
"down_proj", "k_proj", "v_proj",
"gate_proj", "up_proj", "q_proj", "o_proj"
]
}
Bias, Risks, and Limitations
Code Correctness: The generated code is not guaranteed to be 100% correct or optimal. Always review and test the code before using it in a production environment.
Scope: The model's capabilities are limited to the types of problems present in its training data. It may not perform well on highly complex or novel problems.
Library Bias: The model was primarily trained on solutions using numpy and will heavily favor it in its responses.