Update README.md
Browse files
README.md
CHANGED
|
@@ -6,202 +6,224 @@ tags:
|
|
| 6 |
- base_model:adapter:Qwen/Qwen1.5-1.8B
|
| 7 |
- lora
|
| 8 |
- transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 14 |
-
|
| 15 |
|
|
|
|
| 16 |
|
| 17 |
## Model Details
|
| 18 |
|
| 19 |
### Model Description
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
- **Developed by:** [More Information Needed]
|
| 26 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 27 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 28 |
-
- **Model type:** [More Information Needed]
|
| 29 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 30 |
-
- **License:** [More Information Needed]
|
| 31 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
-
- **
|
| 38 |
-
- **
|
| 39 |
-
- **Demo [optional]:** [More Information Needed]
|
| 40 |
|
| 41 |
## Uses
|
| 42 |
|
| 43 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 44 |
-
|
| 45 |
### Direct Use
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
## Bias, Risks, and Limitations
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
### Recommendations
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
## How to Get Started with the Model
|
| 76 |
-
|
| 77 |
-
Use the code below to get started with the model.
|
| 78 |
-
|
| 79 |
-
[More Information Needed]
|
| 80 |
|
| 81 |
## Training Details
|
| 82 |
|
| 83 |
### Training Data
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
### Training Procedure
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Preprocessing [optional]
|
| 94 |
-
|
| 95 |
-
[More Information Needed]
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
#### Training Hyperparameters
|
| 99 |
|
| 100 |
-
- **Training
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
####
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
[More Information Needed]
|
| 107 |
|
| 108 |
## Evaluation
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
### Testing Data, Factors & Metrics
|
| 113 |
|
| 114 |
#### Testing Data
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
[More Information Needed]
|
| 119 |
-
|
| 120 |
-
#### Factors
|
| 121 |
-
|
| 122 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 123 |
-
|
| 124 |
-
[More Information Needed]
|
| 125 |
|
| 126 |
#### Metrics
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
[More Information Needed]
|
| 131 |
|
| 132 |
### Results
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
[More Information Needed]
|
| 145 |
|
| 146 |
## Environmental Impact
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
|
| 152 |
-
|
| 153 |
-
- **Hours used:** [More Information Needed]
|
| 154 |
-
- **Cloud Provider:** [More Information Needed]
|
| 155 |
-
- **Compute Region:** [More Information Needed]
|
| 156 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 157 |
|
| 158 |
-
## Technical Specifications
|
| 159 |
|
| 160 |
-
### Model Architecture
|
| 161 |
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
### Compute Infrastructure
|
| 165 |
|
| 166 |
-
[More Information Needed]
|
| 167 |
-
|
| 168 |
#### Hardware
|
| 169 |
|
| 170 |
-
|
|
|
|
| 171 |
|
| 172 |
#### Software
|
| 173 |
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
**BibTeX:**
|
| 181 |
-
|
| 182 |
-
[More Information Needed]
|
| 183 |
-
|
| 184 |
-
**APA:**
|
| 185 |
|
| 186 |
-
|
| 187 |
|
| 188 |
-
|
| 189 |
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
-
|
| 193 |
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
-
|
| 197 |
|
| 198 |
-
|
| 199 |
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
-
## Model Card
|
| 203 |
|
| 204 |
-
[
|
| 205 |
-
### Framework versions
|
| 206 |
|
| 207 |
-
- PEFT 0.17.1
|
|
|
|
| 6 |
- base_model:adapter:Qwen/Qwen1.5-1.8B
|
| 7 |
- lora
|
| 8 |
- transformers
|
| 9 |
+
- code-generation
|
| 10 |
+
- python
|
| 11 |
+
- reasoning
|
| 12 |
+
- synthetic-data
|
| 13 |
+
language:
|
| 14 |
+
- en
|
| 15 |
+
license: apache-2.0
|
| 16 |
---
|
| 17 |
|
| 18 |
+
# Qwen 1.5 1.8B - Python Code Generation with Step-by-Step Reasoning
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
A fine-tuned version of Qwen 1.5 1.8B that generates Python code with detailed step-by-step reasoning explanations. This model teaches users how to solve programming problems by explaining its thought process before writing code.
|
| 21 |
|
| 22 |
## Model Details
|
| 23 |
|
| 24 |
### Model Description
|
| 25 |
|
| 26 |
+
This model is fine-tuned using QLoRA on a synthetic dataset of 1,000 Python programming problems enriched with step-by-step reasoning. The model learns to explain its problem-solving approach before generating code, making it ideal for educational purposes and transparent code generation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
- **Developed by:** [Your Name/Organization]
|
| 29 |
+
- **Model type:** Causal Language Model (Fine-tuned with LoRA adapters)
|
| 30 |
+
- **Language(s):** English (code generation in Python)
|
| 31 |
+
- **License:** Apache 2.0
|
| 32 |
+
- **Finetuned from model:** Qwen/Qwen1.5-1.8B
|
| 33 |
|
| 34 |
+
### Model Sources
|
| 35 |
|
| 36 |
+
- **Base Model:** [Qwen/Qwen1.5-1.8B](https://huggingface.co/Qwen/Qwen1.5-1.8B)
|
| 37 |
+
- **Training Data:** Synthetic dataset generated from MBPP and CodeAlpaca using Llama 3.1 8B
|
|
|
|
| 38 |
|
| 39 |
## Uses
|
| 40 |
|
|
|
|
|
|
|
| 41 |
### Direct Use
|
| 42 |
|
| 43 |
+
This model is designed for:
|
| 44 |
+
- **Educational code generation**: Teaching programming concepts through explained solutions
|
| 45 |
+
- **Transparent AI coding assistants**: Understanding how the model approaches problems
|
| 46 |
+
- **Code explanation**: Generating step-by-step breakdowns of problem-solving strategies
|
| 47 |
+
- **Learning tool**: Helping beginners understand algorithmic thinking
|
| 48 |
|
| 49 |
+
### Example Usage
|
| 50 |
|
| 51 |
+
```python
|
| 52 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 53 |
+
from peft import PeftModel
|
| 54 |
|
| 55 |
+
# Load base model and tokenizer
|
| 56 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 57 |
+
"Qwen/Qwen1.5-1.8B",
|
| 58 |
+
device_map="auto"
|
| 59 |
+
)
|
| 60 |
+
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-1.8B")
|
| 61 |
|
| 62 |
+
# Load LoRA adapter
|
| 63 |
+
model = PeftModel.from_pretrained(base_model, "[YOUR_MODEL_PATH]")
|
| 64 |
|
| 65 |
+
# Generate code with reasoning
|
| 66 |
+
prompt = "Write a Python function to find the longest common prefix in a list of strings."
|
| 67 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 68 |
+
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 69 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 70 |
+
```
|
| 71 |
|
| 72 |
+
### Out-of-Scope Use
|
| 73 |
|
| 74 |
+
- **Production-critical systems**: This model is fine-tuned on a limited dataset and should not be used for safety-critical applications
|
| 75 |
+
- **Non-Python languages**: The model is specifically trained on Python problems
|
| 76 |
+
- **Complex software architecture**: Best suited for algorithm-level problems, not large-scale system design
|
| 77 |
+
- **Security-sensitive code**: Should not be used for generating cryptographic or security-critical code without expert review
|
| 78 |
|
| 79 |
## Bias, Risks, and Limitations
|
| 80 |
|
| 81 |
+
### Limitations
|
| 82 |
|
| 83 |
+
1. **Dataset size**: Trained on only 1,000 examples, may not generalize to all problem types
|
| 84 |
+
2. **Teacher model quality**: Synthetic data generated by Llama 3.1 8B may contain errors
|
| 85 |
+
3. **Small test set**: Evaluated on only 7 problems, true generalization unknown
|
| 86 |
+
4. **Potential overfitting**: High accuracy on test set may indicate memorization rather than true learning
|
| 87 |
+
5. **No code validation**: Training data was not validated for correctness before fine-tuning
|
| 88 |
|
| 89 |
### Recommendations
|
| 90 |
|
| 91 |
+
- Always review and test generated code before using in production
|
| 92 |
+
- Use as a learning tool rather than a replacement for human expertise
|
| 93 |
+
- Validate outputs against test cases and edge cases
|
| 94 |
+
- Consider the model's explanations as one perspective, not absolute truth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
## Training Details
|
| 97 |
|
| 98 |
### Training Data
|
| 99 |
|
| 100 |
+
- **Source datasets**: MBPP (Mostly Basic Programming Problems) and CodeAlpaca
|
| 101 |
+
- **Dataset size**: 1,000 Python programming problems
|
| 102 |
+
- **Data generation**: Synthetic step-by-step reasoning generated using Llama 3.1 8B Instant via Groq API
|
| 103 |
+
- **Data structure**: Each example contains:
|
| 104 |
+
- Original programming problem
|
| 105 |
+
- Step-by-step reasoning (problem understanding, algorithm design, implementation strategy)
|
| 106 |
+
- Python solution
|
| 107 |
|
| 108 |
### Training Procedure
|
| 109 |
|
| 110 |
+
#### Fine-tuning Method
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
- **Technique**: QLoRA (Quantized Low-Rank Adaptation)
|
| 113 |
+
- **Quantization**: 4-bit quantization for memory efficiency
|
| 114 |
+
- **LoRA Configuration**:
|
| 115 |
+
- Rank (r): 8
|
| 116 |
+
- Alpha: 16
|
| 117 |
+
- Target modules: q_proj, k_proj, v_proj, o_proj (attention layers)
|
| 118 |
+
- Dropout: 0.05
|
| 119 |
|
| 120 |
#### Training Hyperparameters
|
| 121 |
|
| 122 |
+
- **Training epochs**: 3
|
| 123 |
+
- **Learning rate**: 2e-4
|
| 124 |
+
- **Optimizer**: paged_adamw_8bit
|
| 125 |
+
- **Batch size**: [Specify if known]
|
| 126 |
+
- **Training regime**: Mixed precision (4-bit quantization)
|
| 127 |
+
- **Hardware**: Google Colab T4 GPU (free tier)
|
| 128 |
+
- **Framework**: PEFT 0.17.1, Transformers, bitsandbytes
|
| 129 |
|
| 130 |
+
#### Training Time
|
| 131 |
|
| 132 |
+
- Approximately [X hours] on Google Colab T4 GPU
|
|
|
|
|
|
|
| 133 |
|
| 134 |
## Evaluation
|
| 135 |
|
| 136 |
+
### Testing Data & Metrics
|
|
|
|
|
|
|
| 137 |
|
| 138 |
#### Testing Data
|
| 139 |
|
| 140 |
+
- **Test set size**: 7 diverse Python programming problems
|
| 141 |
+
- **Problem types**: Mix of algorithmic challenges from the training distribution
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
#### Metrics
|
| 144 |
|
| 145 |
+
- **Primary metric**: Pass@1 (functional correctness - does the generated code execute correctly?)
|
| 146 |
+
- **Secondary metric**: Reasoning structure presence (does output include step-by-step explanation?)
|
|
|
|
| 147 |
|
| 148 |
### Results
|
| 149 |
|
| 150 |
+
| Metric | Base Model (Qwen 1.5 1.8B) | Fine-tuned Model |
|
| 151 |
+
|--------|---------------------------|------------------|
|
| 152 |
+
| Pass@1 | 75% | 100% |
|
| 153 |
+
| Reasoning Structure | Inconsistent | 100% |
|
|
|
|
| 154 |
|
| 155 |
+
**Key Findings**:
|
| 156 |
+
- **+25 percentage point improvement** in functional correctness
|
| 157 |
+
- **100% of outputs** now include structured step-by-step reasoning
|
| 158 |
+
- All 7 test cases passed successfully
|
| 159 |
|
| 160 |
+
**Important Note**: Results are based on a small test set (7 examples). Larger-scale evaluation needed to confirm generalization.
|
|
|
|
|
|
|
| 161 |
|
| 162 |
## Environmental Impact
|
| 163 |
|
| 164 |
+
- **Hardware Type**: NVIDIA T4 GPU (Google Colab)
|
| 165 |
+
- **Hours used**: ~[X hours for fine-tuning]
|
| 166 |
+
- **Cloud Provider**: Google Cloud Platform
|
| 167 |
+
- **Compute Region**: [Specify if known]
|
| 168 |
+
- **Carbon Emitted**: Minimal due to use of QLoRA on single T4 GPU
|
| 169 |
|
| 170 |
+
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
+
## Technical Specifications
|
| 173 |
|
| 174 |
+
### Model Architecture
|
| 175 |
|
| 176 |
+
- **Base architecture**: Qwen 1.5 1.8B (Transformer decoder)
|
| 177 |
+
- **Fine-tuning method**: LoRA adapters on attention layers
|
| 178 |
+
- **Total parameters**: 1.8B (base) + ~4.7M (LoRA adapters)
|
| 179 |
+
- **Trainable parameters**: ~4.7M (0.26% of total)
|
| 180 |
|
| 181 |
### Compute Infrastructure
|
| 182 |
|
|
|
|
|
|
|
| 183 |
#### Hardware
|
| 184 |
|
| 185 |
+
- GPU: NVIDIA T4 (16GB VRAM)
|
| 186 |
+
- Platform: Google Colab (free tier)
|
| 187 |
|
| 188 |
#### Software
|
| 189 |
|
| 190 |
+
- PEFT 0.17.1
|
| 191 |
+
- Transformers
|
| 192 |
+
- bitsandbytes (for 4-bit quantization)
|
| 193 |
+
- PyTorch
|
| 194 |
+
- Groq API (for synthetic data generation)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
+
## Project Insights
|
| 197 |
|
| 198 |
+
### What Worked Well
|
| 199 |
|
| 200 |
+
- Cross-model knowledge distillation (8B teacher → 1.8B student)
|
| 201 |
+
- QLoRA enabled fine-tuning on free-tier GPU
|
| 202 |
+
- Structured prompts for synthetic data generation
|
| 203 |
+
- Teaching reasoning process alongside code generation
|
| 204 |
|
| 205 |
+
### Future Improvements
|
| 206 |
|
| 207 |
+
1. **Better teacher model**: Use Llama 3.1 70B for higher-quality synthetic data
|
| 208 |
+
2. **Data validation**: Verify all generated code executes correctly before training
|
| 209 |
+
3. **Larger dataset**: Scale to 5,000-10,000 examples
|
| 210 |
+
4. **Robust evaluation**: Test on 50-100 problems from benchmarks like HumanEval
|
| 211 |
+
5. **Higher LoRA rank**: Experiment with rank 16 or 32 for more capacity
|
| 212 |
|
| 213 |
+
## Citation
|
| 214 |
|
| 215 |
+
If you use this model, please cite:
|
| 216 |
|
| 217 |
+
```bibtex
|
| 218 |
+
@misc{qwen15-code-reasoning,
|
| 219 |
+
author = {[Rachit Verma]},
|
| 220 |
+
title = {Qwen 1.5 1.8B Fine-tuned for Python Code Generation with Reasoning},
|
| 221 |
+
year = {2025},
|
| 222 |
+
publisher = {HuggingFace},
|
| 223 |
+
}
|
| 224 |
+
```
|
| 225 |
|
| 226 |
+
## Model Card Authors
|
| 227 |
|
| 228 |
+
[Rachit Verma]
|
|
|
|
| 229 |
|
|
|