|
|
--- |
|
|
language: |
|
|
- en |
|
|
license: apache-2.0 |
|
|
library_name: transformers |
|
|
tags: |
|
|
- code-generation |
|
|
- python |
|
|
- programming |
|
|
- fine-tuned |
|
|
pipeline_tag: text-generation |
|
|
widget: |
|
|
- text: |- |
|
|
### Instruction: |
|
|
Write a Python function to reverse a string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
example_title: Reverse String |
|
|
- text: |- |
|
|
### Instruction: |
|
|
how are you? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
example_title: Non-Code Request |
|
|
- text: |- |
|
|
### Instruction: |
|
|
Implement quicksort algorithm in Python |
|
|
|
|
|
|
|
|
Use recursion and list comprehensions |
|
|
|
|
|
|
|
|
example_title: Quicksort Algorithm |
|
|
base_model: Mercy-62/python-code-only-Qwen-lora |
|
|
datasets: |
|
|
- sahil2801/CodeAlpaca-20k |
|
|
- google-research-datasets/mbpp |
|
|
- openai/openai_humaneval |
|
|
--- |
|
|
|
|
|
# π Python Code-Only Qwen |
|
|
|
|
|
**A fine-tuned model that generates ONLY executable Python code, with no explanations or conversations.** |
|
|
|
|
|
## π Quick Inference Example |
|
|
|
|
|
```python |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
|
|
# Load model |
|
|
model = AutoModelForCausalLM.from_pretrained("Mercy-62/python-code-only-Qwen-lora") |
|
|
tokenizer = AutoTokenizer.from_pretrained("Mercy-62/python-code-only-Qwen-lora") |
|
|
|
|
|
# Use exact same prompt format from training |
|
|
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. |
|
|
|
|
|
### Instruction: |
|
|
{} |
|
|
|
|
|
### Input: |
|
|
{} |
|
|
|
|
|
### Response: |
|
|
{}""" |
|
|
|
|
|
# Enable faster inference (if using Unsloth) |
|
|
# FastLanguageModel.for_inference(model) |
|
|
|
|
|
# Test 1: Simple code generation |
|
|
inputs = tokenizer( |
|
|
[ |
|
|
alpaca_prompt.format( |
|
|
"Write a Python function to reverse a string", # instruction |
|
|
"", # input (leave empty if no context) |
|
|
"", # output - leave blank for generation |
|
|
) |
|
|
], |
|
|
return_tensors="pt" |
|
|
).to("cuda") |
|
|
|
|
|
outputs = model.generate(**inputs, max_new_tokens=128, use_cache=True) |
|
|
print("Test 1 - Reverse string function:") |
|
|
print(tokenizer.batch_decode(outputs)[0]) |