Instructions to use Showmick119/codellama-7b-fastapi-finetuned-20250713 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Showmick119/codellama-7b-fastapi-finetuned-20250713 with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("codellama/CodeLlama-7b-Instruct-hf") model = PeftModel.from_pretrained(base_model, "Showmick119/codellama-7b-fastapi-finetuned-20250713") - Transformers
How to use Showmick119/codellama-7b-fastapi-finetuned-20250713 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Showmick119/codellama-7b-fastapi-finetuned-20250713")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Showmick119/codellama-7b-fastapi-finetuned-20250713", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Showmick119/codellama-7b-fastapi-finetuned-20250713 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Showmick119/codellama-7b-fastapi-finetuned-20250713" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Showmick119/codellama-7b-fastapi-finetuned-20250713", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Showmick119/codellama-7b-fastapi-finetuned-20250713
- SGLang
How to use Showmick119/codellama-7b-fastapi-finetuned-20250713 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 "Showmick119/codellama-7b-fastapi-finetuned-20250713" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Showmick119/codellama-7b-fastapi-finetuned-20250713", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "Showmick119/codellama-7b-fastapi-finetuned-20250713" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Showmick119/codellama-7b-fastapi-finetuned-20250713", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Showmick119/codellama-7b-fastapi-finetuned-20250713 with Docker Model Runner:
docker model run hf.co/Showmick119/codellama-7b-fastapi-finetuned-20250713
CodeLlama-7B Fine-tuned for FastAPI Code Generation
This model is a fine-tuned version of codellama/CodeLlama-7b-Instruct-hf specialized for FastAPI code generation. It was trained using QLoRA (4-bit quantization + LoRA adapters) on 570 carefully curated FastAPI examples from real-world GitHub repositories.
Intended Use Case
Generate production-ready FastAPI code including endpoints, authentication, database integration, and error handling.
Intended Users
- Python developers building FastAPI applications
- Students learning FastAPI best practices
- Teams needing rapid API prototyping
Training Details
Dataset
- Size: 570 examples (augmented from 331 original patterns)
- Source: Real-world FastAPI repositories from GitHub
- Categories: Authentication (215), Database (94), Endpoints (74), Models (29), Validation (4)
- Quality: Enhanced with contextual imports and complete code structure
LoRA Configuration
- LoRA Rank (r):
32 - LoRA Alpha:
64 - LoRA Dropout:
0.1 - Target Modules:
[q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj] - Quantization: 4-bit with bitsandbytes (nf4, double quantization)
- Base Model:
codellama/CodeLlama-7b-Instruct-hf
Training Hyperparameters
The following hyperparameters were used during training:
- num_epochs:
3 - train_batch_size:
2 - gradient_accumulation_steps:
8 - total_train_batch_size:
16 - optimizer:
paged_adamw_32bitwithbetas = (0.900, 0.999)andepsilon = 1e-08 - learning_rate:
0.0001 - lr_scheduler_type: cosine
- lr_scheduler_warmup_ratio:
0.1 - seed:
42
Training Results
| Step | Epoch | Training Loss | Validation Loss |
|---|---|---|---|
| 10 | 0.3113 | 5.4923 | 4.4958 |
| 20 | 0.6226 | 0.4476 | 0.3011 |
| 30 | 0.9339 | 0.2841 | 0.2455 |
| 40 | 1.2179 | 0.2703 | 0.2151 |
| 50 | 1.5292 | 0.2241 | 0.1897 |
| 60 | 1.8405 | 0.1913 | 0.1625 |
| 70 | 2.1245 | 0.2357 | 0.1485 |
| 80 | 2.4358 | 0.1515 | 0.1357 |
| 90 | 2.7471 | 0.1373 | 0.1294 |
- Initial Loss:
5.4923 - Final Loss:
0.1294 - Loss Reduction:
94%
Performance
| Metric | Base Model | Fine-tuned | Improvement |
|---|---|---|---|
| FastAPI Code Quality | 75.1/100 | 85.0/100 | +9.9 points |
| Code Completeness | 59.9/100 | 75.8/100 | +15.9 points |
Key Improvements:
- Proper FastAPI imports and structure
- Professional error handling with HTTP status codes
- Database integration patterns (SQLAlchemy, MongoDB)
- Authentication and validation logic
- Production-ready code patterns
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load model and tokenizer
model_name = "Showmick119/codellama-7b-fastapi-finetuned-20250713"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="auto",
load_in_4bit=True
)
# Generate FastAPI code
prompt = "[INST] Create a FastAPI POST endpoint for user registration with email validation [/INST]"
inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.1,
do_sample=True,
pad_token_id=tokenizer.pad_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response[len(prompt):].strip())
Limitations
- Domain: Specialized for FastAPI; may not perform well on other frameworks
- Context: Limited to 512 tokens; may truncate longer code examples
- Dependencies: Requires GPU for optimal inference speed
- Training Data Quality: GitHub-mined code was often messy and incomplete, requiring extensive preprocessing and enhancement to create complete, runnable training examples
Ethical Considerations
- Code Quality: Generated code should be reviewed before production use
- Security: Always validate generated authentication and security patterns
- Licensing: Respects original training data licenses and CodeLlama terms
Citation
@misc{codellama-fastapi-2025,
title={CodeLlama-7B Fine-tuned for FastAPI Code Generation},
author={Showmick119},
year={2025},
url={https://huggingface.co/Showmick119/codellama-7b-fastapi-finetuned-20250713}
}
Framework Versions
- PEFT 0.16.0
- Transformers 4.53.1
- PyTorch 2.6.0+cu124
- Datasets 4.0.0
- Tokenizers 0.21.2
- Accelerate 0.36.0
- Bitsandbytes 0.45.0
- TRL 0.12.0
- HuggingFace Hub 0.26.0
- NumPy 2.0.0
- Python 3.10+
Additional Resources
- Training Code: GitHub Repository
- Training Notebook: Google Colab
- Base Model: CodeLlama-7b-Instruct-hf
- Downloads last month
- 6
Model tree for Showmick119/codellama-7b-fastapi-finetuned-20250713
Base model
codellama/CodeLlama-7b-Instruct-hf