File size: 3,461 Bytes
35cee1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
494c658
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
license: apache-2.0
language: en
tags:
- openbmb/MiniCPM4-0.5B
- coding
- code-generation
- fine-tuned
- qlora
- gguf
- instruction
- python
datasets:
- TokenBender/code_instructions_122k_alpaca_style
model_type: openbmb/MiniCPM4-0.5B
base_model: openbmb/MiniCPM4-0.5B
---

# MiniCPM4-0.5B-Coding-Finetuned-v1

This model is a fine-tuned version of `openbmb/MiniCPM4-0.5B` specialized for Python code generation tasks. It's designed to understand programming-related instructions and provide accurate and efficient Python code solutions.

## ๐Ÿ’ป Model Description

- **Base Model**: `openbmb/MiniCPM4-0.5B`
- **Fine-tuning Method**: **QLoRA** (Quantized Low-Rank Adaptation)
- **Dataset**: `TokenBender/code_instructions_122k_alpaca_style` - A large dataset of coding instructions and their corresponding solutions.
- **Training**: Optimized for instruction-based code generation using 4-bit quantization for efficiency.

## โš ๏ธ Important Considerations

- **Verify All Code**: Generated code may contain errors or be suboptimal. Always test and review the code thoroughly before using it in production environments.
- **Security**: The generated code has not been vetted for security vulnerabilities. Be cautious when using it in security-sensitive applications.
- **Not a Replacement for Developers**: This model is a tool to assist developers, not replace them. Human oversight and expertise are crucial.

## ๐Ÿš€ Usage

### With `transformers`

```python
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
import torch

model_id = "rohitnagareddy/MiniCPM4-0.5B-Coding-Finetuned-v1"

# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="auto",
    trust_remote_code=True
)

# Create conversation for a Python code-generation task
messages = [
    {"role": "system", "content": "You are an expert coding assistant."},
    {"role": "user", "content": "Write a Python function that takes a list of integers and returns the sum of all even numbers in the list."}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)

pipe = pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer
)

# Generate response
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
print(outputs[0]["generated_text"])
```

## ๐Ÿ”ง GGUF Versions

This repository includes quantized GGUF versions for use with `llama.cpp` and compatible tools:

- `MiniCPM4-0.5B-Coding-Finetuned-v1.fp16.gguf` - Full precision (largest, best quality)
- `MiniCPM4-0.5B-Coding-Finetuned-v1.Q8_0.gguf` - 8-bit quantization (good balance)
- `MiniCPM4-0.5B-Coding-Finetuned-v1.Q5_K_M.gguf` - 5-bit quantization (smaller, fast)
- `MiniCPM4-0.5B-Coding-Finetuned-v1.Q4_K_M.gguf` - 4-bit quantization (smallest, fastest)

### Example with llama.cpp

```bash
./main -m ./MiniCPM4-0.5B-Coding-Finetuned-v1.Q4_K_M.gguf -n 256 -p "<|im_start|>system\nYou are an expert coding assistant.<|im_end|>\n<|im_start|>user\nCreate a Python function to find the factorial of a number.<|im_end|>\n<|im_start|>assistant\n"
```

## ๐Ÿ“Š Training Details

- **Training Epochs**: 1
- **QLoRA Rank (r)**: 16
- **QLoRA Alpha**: 32
- **Learning Rate**: 2e-4
- **Optimizer**: Paged AdamW 32-bit
- **Target Modules**: Auto-detected linear layers