Views
No views yet
Qwen/Qwen2.5-Coder-1.5B-Instruct, specifically engineered to understand complex algorithmic instructions and generate clean, efficient, and highly accurate Python code.transformers library, or deploy it instantly using Ollama for local inference.1pip install -U huggingface_hub
2huggingface-cli download karim0010/Qwen2.5-Coder-1.5B-python-MyTune --local-dir ./my_qwen_model
3Modelfile**
In the same folder, create a file named Modelfile (no extension) and paste the following ChatML configuration:1FROM ./my_qwen_model
2
3TEMPLATE """{{ if .System }}<|im_start|>system
4{{ .System }}<|im_end|>
5{{ end }}{{ if .Prompt }}<|im_start|>user
6{{ .Prompt }}<|im_end|>
7{{ end }}<|im_start|>assistant
8"""
9
10PARAMETER stop "<|im_start|>"
11PARAMETER stop "<|im_end|>"
12PARAMETER temperature 0.3
13PARAMETER top_p 0.9
141ollama create karim-coder -f ./Modelfile
2ollama run karim-coder
31pip install transformers torch accelerate
21import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Define the repository
5model_id = "karim0010/Qwen2.5-Coder-1.5B-python-MyTune"
6
7# Load Tokenizer and Model
8tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
9model = AutoModelForCausalLM.from_pretrained(
10 model_id,
11 torch_dtype=torch.float16,
12 device_map="auto",
13 trust_remote_code=True
14)
15
16# Prepare the prompt using the ChatML template
17instruction = "Write a complete and clean Python function to calculate the Fibonacci sequence up to a given number 'n'."
18prompt = f"<|im_start|>user\n{instruction}<|im_end|>\n<|im_start|>assistant\n"
19
20# Tokenize inputs
21inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
22
23# Generate code
24print("Generating code...")
25outputs = model.generate(
26 inputs["input_ids"],
27 attention_mask=inputs["attention_mask"],
28 max_new_tokens=256,
29 temperature=0.3, # Low temperature is recommended for accurate coding
30 top_p=0.9,
31 do_sample=True,
32 pad_token_id=tokenizer.eos_token_id
33)
34
35# Decode and print the result
36response = tokenizer.decode(outputs[0][len(inputs["input_ids"][0]):], skip_special_tokens=True)
37print("\n--- Output ---")
38print(response.strip())
39