Text Generation
Transformers
Safetensors
PEFT
llama
tinyllama
lora
python
code
fine-tuning
conversational
text-generation-inference
Instructions to use mo7amed-3bdalla7/tinyllama-python-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mo7amed-3bdalla7/tinyllama-python-lora with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mo7amed-3bdalla7/tinyllama-python-lora") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mo7amed-3bdalla7/tinyllama-python-lora") model = AutoModelForCausalLM.from_pretrained("mo7amed-3bdalla7/tinyllama-python-lora") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - PEFT
How to use mo7amed-3bdalla7/tinyllama-python-lora with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use mo7amed-3bdalla7/tinyllama-python-lora with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mo7amed-3bdalla7/tinyllama-python-lora" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mo7amed-3bdalla7/tinyllama-python-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mo7amed-3bdalla7/tinyllama-python-lora
- SGLang
How to use mo7amed-3bdalla7/tinyllama-python-lora with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mo7amed-3bdalla7/tinyllama-python-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mo7amed-3bdalla7/tinyllama-python-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "mo7amed-3bdalla7/tinyllama-python-lora" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mo7amed-3bdalla7/tinyllama-python-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use mo7amed-3bdalla7/tinyllama-python-lora with Docker Model Runner:
docker model run hf.co/mo7amed-3bdalla7/tinyllama-python-lora
File size: 1,911 Bytes
de11a90 | 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 | ---
license: apache-2.0
base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
tags:
- tinyllama
- lora
- peft
- python
- code
- fine-tuning
model_type: causal-lm
library_name: transformers
pipeline_tag: text-generation
---
# 🐍 TinyLLaMA LoRA - Fine-tuned on Python Code
This is a **LoRA fine-tuned version** of [`TinyLlama/TinyLlama-1.1B-Chat-v1.0`](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0) using a subset of Python code from the `codeparrot` dataset. It is trained to generate Python functions and code snippets based on natural language or code-based prompts.
## 🔧 Training Details
- **Base model**: `TinyLlama/TinyLlama-1.1B-Chat-v1.0`
- **Adapter type**: LoRA (PEFT)
- **Dataset**: `codeparrot/codeparrot-clean-valid[:1000]`
- **Tokenized max length**: 512
- **Trained on**: Apple M3 Pro (MPS backend)
- **Epochs**: 1
- **Batch size**: 1 (with gradient accumulation)
## 💡 Example Usage
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base_model = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
adapter_model = "your-username/tinyllama-python-lora"
tokenizer = AutoTokenizer.from_pretrained(base_model)
model = AutoModelForCausalLM.from_pretrained(base_model)
model = PeftModel.from_pretrained(model, adapter_model)
prompt = "<|python|>\ndef fibonacci(n):"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=100)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
## 🧠 Intended Use
Code completion for Python
Teaching LLMs Python function structure
Experimentation with LoRA on small code datasets
##⚠️ Limitations
Trained on a small subset of data (1,000 samples)
May hallucinate or generate syntactically incorrect code
Not suitable for production use without further fine-tuning and evaluation
## 📜 License
Apache 2.0 — same as the base model. |