PEFT
Safetensors
English
code
python
lora
qwen2
code-generation
SathishKumar89 commited on
Commit
27922f7
·
verified ·
1 Parent(s): bb6690f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +50 -0
README.md CHANGED
@@ -38,3 +38,53 @@ This model was fine-tuned as a learning project to demonstrate the full workflow
38
  ## Prompt Format
39
 
40
  This model was trained with the following instruction format. Using the same format at inference time will give the best results:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  ## Prompt Format
39
 
40
  This model was trained with the following instruction format. Using the same format at inference time will give the best results:
41
+
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ import torch
47
+ from transformers import AutoTokenizer, AutoModelForCausalLM
48
+ from peft import PeftModel
49
+
50
+ # Load base model and LoRA adapter
51
+ base_model = AutoModelForCausalLM.from_pretrained(
52
+ "Qwen/Qwen2.5-Coder-1.5B-Instruct",
53
+ dtype=torch.float16,
54
+ device_map="auto",
55
+ )
56
+ model = PeftModel.from_pretrained(base_model, "SathishKumar89/my-python-coder")
57
+ tokenizer = AutoTokenizer.from_pretrained("SathishKumar89/my-python-coder")
58
+
59
+ # Prepare a prompt
60
+ prompt = """### Instruction:
61
+ Write a Python function that checks if a number is prime.
62
+
63
+ ### Response:
64
+ """
65
+
66
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
67
+ outputs = model.generate(**inputs, max_new_tokens=200, do_sample=False)
68
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
69
+
70
+ ### Instruction:
71
+ Write a Python function that checks if a number is prime.
72
+
73
+ ### Response:
74
+ def is_prime(num):
75
+ # Check for 0 and 1
76
+ if num <= 1:
77
+ return False
78
+
79
+ # Check for even numbers greater than 2
80
+ elif num == 2:
81
+ return True
82
+ elif num % 2 == 0:
83
+ return False
84
+
85
+ # Check for odd numbers greater than 3
86
+ else:
87
+ for i in range(3, int(num**0.5) + 1, 2):
88
+ if num % i == 0:
89
+ return False
90
+ return True