Text Generation
PEFT
Safetensors
Transformers
qwen2
lora
coding
code-generation
conversational
text-generation-inference
Instructions to use girish00/ConicAI_LLM_model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use girish00/ConicAI_LLM_model with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-0.5B-Instruct") model = PeftModel.from_pretrained(base_model, "girish00/ConicAI_LLM_model") - Transformers
How to use girish00/ConicAI_LLM_model with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="girish00/ConicAI_LLM_model") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("girish00/ConicAI_LLM_model") model = AutoModelForCausalLM.from_pretrained("girish00/ConicAI_LLM_model", device_map="auto") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use girish00/ConicAI_LLM_model with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "girish00/ConicAI_LLM_model" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "girish00/ConicAI_LLM_model", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/girish00/ConicAI_LLM_model
- SGLang
How to use girish00/ConicAI_LLM_model 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 "girish00/ConicAI_LLM_model" \ --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": "girish00/ConicAI_LLM_model", "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 "girish00/ConicAI_LLM_model" \ --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": "girish00/ConicAI_LLM_model", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use girish00/ConicAI_LLM_model with Docker Model Runner:
docker model run hf.co/girish00/ConicAI_LLM_model
MODIFY README
Browse files
README.md
CHANGED
|
@@ -1,200 +1,68 @@
|
|
| 1 |
---
|
| 2 |
-
license:
|
| 3 |
-
base_model: Qwen/Qwen2.5-Coder-0.5B-Instruct
|
| 4 |
library_name: peft
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
tags:
|
| 7 |
- code
|
| 8 |
- lora
|
|
|
|
| 9 |
- structured-output
|
| 10 |
---
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
This project fine-tunes `Qwen/Qwen2.5-Coder-0.5B-Instruct` using LoRA for:
|
| 15 |
-
- code fixing
|
| 16 |
-
- debugging
|
| 17 |
-
- explanation
|
| 18 |
-
- confidence and relevancy-aware outputs
|
| 19 |
-
|
| 20 |
-
## Files
|
| 21 |
-
|
| 22 |
-
- `generate_dataset.py`: creates training dataset (5k-10k)
|
| 23 |
-
- `finetune_coding_llm_colab.py`: local training script (LoRA) + optional upload
|
| 24 |
-
- `infer_local.py`: test local trained model with structured JSON output
|
| 25 |
-
- `infer_cloud.py`: run Hugging Face API inference and force the same structured JSON output
|
| 26 |
-
- `handler.py`: custom Hugging Face Inference Endpoint handler that returns the same JSON contract from the hosted endpoint
|
| 27 |
-
- `evaluate_model.py`: run multi-prompt quality checks and report accuracy
|
| 28 |
-
- `upload_to_hf.py`: upload local model folder to HF
|
| 29 |
-
- `run_pipeline.py`: one command for generate + train (+ optional upload)
|
| 30 |
-
- `requirements.txt`: Python dependencies
|
| 31 |
-
- `training_config.json`: default values automatically used by `run_pipeline.py`
|
| 32 |
-
|
| 33 |
-
## Local Setup (No Colab)
|
| 34 |
-
|
| 35 |
-
Install dependencies:
|
| 36 |
-
|
| 37 |
-
```bash
|
| 38 |
-
pip install -r requirements.txt
|
| 39 |
-
```
|
| 40 |
-
|
| 41 |
-
Generate dataset (example: 8000 samples):
|
| 42 |
-
|
| 43 |
-
```bash
|
| 44 |
-
python generate_dataset.py --size 8000 --out train.json
|
| 45 |
-
```
|
| 46 |
-
|
| 47 |
-
Train locally:
|
| 48 |
-
|
| 49 |
-
```bash
|
| 50 |
-
python finetune_coding_llm_colab.py --dataset-size 8000
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
-
Enable 4-bit quantized loading (GPU):
|
| 54 |
-
|
| 55 |
-
```bash
|
| 56 |
-
python finetune_coding_llm_colab.py --dataset-size 8000 --use-4bit
|
| 57 |
-
```
|
| 58 |
-
|
| 59 |
-
Fast CPU smoke run:
|
| 60 |
-
|
| 61 |
-
```bash
|
| 62 |
-
python finetune_coding_llm_colab.py --dataset-size 5000 --max-train-samples 200 --epochs 0.1
|
| 63 |
-
```
|
| 64 |
-
|
| 65 |
-
Single command pipeline (no upload):
|
| 66 |
-
|
| 67 |
-
```bash
|
| 68 |
-
python run_pipeline.py --dataset-size 8000 --skip-upload
|
| 69 |
-
```
|
| 70 |
-
|
| 71 |
-
If `training_config.json` exists, `run_pipeline.py` reads it automatically for defaults.
|
| 72 |
-
|
| 73 |
-
Use existing dataset without regenerating:
|
| 74 |
-
|
| 75 |
-
```bash
|
| 76 |
-
python run_pipeline.py --dataset-size 8000 --train-file train.json --skip-generate --skip-upload
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
Tunable training knobs:
|
| 80 |
-
|
| 81 |
-
```bash
|
| 82 |
-
python run_pipeline.py --dataset-size 8000 --epochs 3 --batch-size 2 --learning-rate 1e-4 --max-length 512 --max-train-samples 0 --use-4bit --skip-upload
|
| 83 |
-
```
|
| 84 |
-
|
| 85 |
-
## Configure 5k-10k samples
|
| 86 |
-
|
| 87 |
-
```python
|
| 88 |
-
--dataset-size 5000
|
| 89 |
-
--dataset-size 8000
|
| 90 |
-
--dataset-size 10000
|
| 91 |
-
```
|
| 92 |
-
|
| 93 |
-
Recommended values:
|
| 94 |
-
- 5000 for fast iteration
|
| 95 |
-
- 8000 as balanced
|
| 96 |
-
- 10000 for stronger adaptation (slower)
|
| 97 |
-
|
| 98 |
-
## Hugging Face Deployment
|
| 99 |
-
|
| 100 |
-
Upload is optional and can be done after training:
|
| 101 |
-
|
| 102 |
-
```bash
|
| 103 |
-
python upload_to_hf.py --model-dir model --repo-id your-username/your-model-name
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
### Update Existing HF Model Repo
|
| 107 |
-
|
| 108 |
-
To update your already-created Hugging Face model with this new JSON-output behavior:
|
| 109 |
-
|
| 110 |
-
1. Retrain locally with latest code:
|
| 111 |
-
```bash
|
| 112 |
-
python run_pipeline.py --dataset-size 8000 --skip-upload
|
| 113 |
-
```
|
| 114 |
-
|
| 115 |
-
2. Login to Hugging Face:
|
| 116 |
-
```bash
|
| 117 |
-
huggingface-cli login
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
3. Upload to the same repo ID (this updates existing files):
|
| 121 |
-
```bash
|
| 122 |
-
python upload_to_hf.py --model-dir model --repo-id your-username/your-existing-model-name
|
| 123 |
-
```
|
| 124 |
-
|
| 125 |
-
Optional safer rollout using a new revision/branch:
|
| 126 |
-
```bash
|
| 127 |
-
python -c "from huggingface_hub import upload_folder; upload_folder(folder_path='model', repo_id='your-username/your-existing-model-name', repo_type='model', revision='v2-json-output')"
|
| 128 |
-
```
|
| 129 |
-
|
| 130 |
-
You can also trigger upload from trainer:
|
| 131 |
-
|
| 132 |
-
```bash
|
| 133 |
-
python finetune_coding_llm_colab.py --skip-dataset-gen --skip-train --upload --hf-repo your-username/your-model-name
|
| 134 |
-
```
|
| 135 |
-
|
| 136 |
-
## Quick Inference Test (Structured JSON)
|
| 137 |
-
|
| 138 |
-
After local training, inference returns JSON with:
|
| 139 |
-
- `code`
|
| 140 |
-
- `explanation`
|
| 141 |
-
- `confidence`
|
| 142 |
-
- `important_tokens`
|
| 143 |
-
- `relevancy_score`
|
| 144 |
-
- `hallucination`
|
| 145 |
-
- `hallucination_check_reason`
|
| 146 |
-
- `latency_ms`
|
| 147 |
-
|
| 148 |
-
```python
|
| 149 |
-
python infer_local.py --model-path model --prompt "Fix this code: def add(a,b) return a+b"
|
| 150 |
-
```
|
| 151 |
|
| 152 |
-
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
-
|
| 159 |
|
| 160 |
-
|
| 161 |
-
set HF_TOKEN=your_huggingface_token
|
| 162 |
-
python infer_cloud.py --repo-id your-username/your-model-name --prompt "Fix this code: def add(a,b) return a+b"
|
| 163 |
-
```
|
| 164 |
|
| 165 |
-
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
```
|
| 173 |
|
| 174 |
-
|
| 175 |
|
| 176 |
-
|
| 177 |
|
| 178 |
-
|
| 179 |
-
$env:HF_TOKEN="your_huggingface_token"
|
| 180 |
-
python infer_cloud.py --endpoint-url "https://your-endpoint-url.endpoints.huggingface.cloud" --prompt "Fix this code: def add(a,b) return a+b" --no-local-fallback
|
| 181 |
-
```
|
| 182 |
|
| 183 |
-
|
|
|
|
|
|
|
| 184 |
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
|
| 191 |
-
|
| 192 |
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
|
| 198 |
|
| 199 |
```json
|
| 200 |
{
|
|
@@ -204,60 +72,210 @@ To make other users receive this JSON pattern with their own token, deploy this
|
|
| 204 |
"important_tokens": [],
|
| 205 |
"relevancy_score": 0.0,
|
| 206 |
"hallucination": false,
|
| 207 |
-
"hallucination_check_reason": "
|
| 208 |
"latency_ms": 0
|
| 209 |
}
|
| 210 |
```
|
| 211 |
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
```
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: "Qwen/Qwen2.5-Coder-0.5B-Instruct"
|
| 4 |
library_name: peft
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
tags:
|
| 7 |
- code
|
| 8 |
- lora
|
| 9 |
+
- coding-assistant
|
| 10 |
- structured-output
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# ConicAI Coding LLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
## Model Details
|
| 16 |
|
| 17 |
+
* **Model Name:** ConicAI Coding LLM
|
| 18 |
+
* **Developer:** GIRISH KUMAR DEWANGAN
|
| 19 |
+
* **Base Model:** Qwen/Qwen2.5-Coder-0.5B-Instruct
|
| 20 |
+
* **Architecture:** Transformer (Causal LM)
|
| 21 |
+
* **Fine-tuning Method:** LoRA (PEFT)
|
| 22 |
+
* **Task Domain:** Code Generation, Debugging, Explanation
|
| 23 |
+
* **Primary Language:** Python
|
| 24 |
|
| 25 |
+
---
|
| 26 |
|
| 27 |
+
## Model Description
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
ConicAI Coding LLM is a parameter-efficient fine-tuned model optimized for structured coding tasks.
|
| 30 |
+
It enhances the base model’s reasoning ability by introducing instruction-conditioned outputs and structured response generation.
|
| 31 |
|
| 32 |
+
The model focuses on three key aspects:
|
| 33 |
|
| 34 |
+
* **Accuracy** → Correct code generation
|
| 35 |
+
* **Interpretability** → Explanation + confidence
|
| 36 |
+
* **Efficiency** → Lightweight fine-tuning
|
|
|
|
| 37 |
|
| 38 |
+
---
|
| 39 |
|
| 40 |
+
## Core Design Philosophy
|
| 41 |
|
| 42 |
+
1. **Instruction Conditioning**
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
```
|
| 45 |
+
Instruction → Input → Output
|
| 46 |
+
```
|
| 47 |
|
| 48 |
+
2. **Structured Output Learning**
|
| 49 |
+
|
| 50 |
+
3. **Post-Generation Validation Awareness**
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
|
| 54 |
+
## Capabilities
|
| 55 |
|
| 56 |
+
* Code generation
|
| 57 |
+
* Code debugging
|
| 58 |
+
* Code explanation
|
| 59 |
+
* Structured output generation
|
| 60 |
+
* Confidence estimation
|
| 61 |
+
* Hallucination detection
|
| 62 |
|
| 63 |
+
---
|
| 64 |
|
| 65 |
+
## Output Schema
|
| 66 |
|
| 67 |
```json
|
| 68 |
{
|
|
|
|
| 72 |
"important_tokens": [],
|
| 73 |
"relevancy_score": 0.0,
|
| 74 |
"hallucination": false,
|
| 75 |
+
"hallucination_check_reason": "",
|
| 76 |
"latency_ms": 0
|
| 77 |
}
|
| 78 |
```
|
| 79 |
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## Training Details
|
| 83 |
+
|
| 84 |
+
### Dataset
|
| 85 |
+
|
| 86 |
+
* Size: ~5K–10K samples
|
| 87 |
+
* Instruction-based coding dataset
|
| 88 |
+
|
| 89 |
+
### Training Procedure
|
| 90 |
+
|
| 91 |
+
* Method: LoRA fine-tuning
|
| 92 |
+
* Framework: Transformers + PEFT
|
| 93 |
+
* Precision: FP16 / Mixed
|
| 94 |
+
|
| 95 |
+
### Training Hyperparameters
|
| 96 |
+
|
| 97 |
+
| Parameter | Value |
|
| 98 |
+
| ------------------- | ----- |
|
| 99 |
+
| Epochs | 1–3 |
|
| 100 |
+
| Batch Size | 2 |
|
| 101 |
+
| Learning Rate | 2e-4 |
|
| 102 |
+
| Max Sequence Length | 512 |
|
| 103 |
+
| LoRA Rank (r) | 8 |
|
| 104 |
+
| LoRA Alpha | 16 |
|
| 105 |
+
| LoRA Dropout | 0.05 |
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## Inference Configuration
|
| 110 |
+
|
| 111 |
+
```text
|
| 112 |
+
max_new_tokens = 200
|
| 113 |
+
temperature = 0.2
|
| 114 |
+
top_p = 0.9
|
| 115 |
+
do_sample = True
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## 🧪 How to Use This Model (Colab / Local)
|
| 121 |
+
|
| 122 |
+
```python
|
| 123 |
+
!pip -q install -U transformers peft accelerate huggingface_hub safetensors
|
| 124 |
+
|
| 125 |
+
from google.colab import userdata
|
| 126 |
+
HF_TOKEN = userdata.get('HF_TOKEN')
|
| 127 |
+
model = "girish00/ConicAI_LLM_model"
|
| 128 |
+
prompt = input("Please enter your prompt: ")
|
| 129 |
+
|
| 130 |
+
from huggingface_hub import login, snapshot_download
|
| 131 |
+
login(token=HF_TOKEN)
|
| 132 |
+
|
| 133 |
+
repo = snapshot_download(model, token=HF_TOKEN)
|
| 134 |
+
|
| 135 |
+
import sys
|
| 136 |
+
sys.path.append(repo)
|
| 137 |
|
| 138 |
+
from infer_local import build_instruction_prompt, build_structured_result
|
| 139 |
+
from peft import PeftConfig, PeftModel
|
| 140 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 141 |
+
import torch, time, json
|
| 142 |
+
|
| 143 |
+
cfg = PeftConfig.from_pretrained(repo)
|
| 144 |
+
base = cfg.base_model_name_or_path
|
| 145 |
+
|
| 146 |
+
tokenizer = AutoTokenizer.from_pretrained(base)
|
| 147 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 148 |
+
base,
|
| 149 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 150 |
+
device_map="auto"
|
| 151 |
+
)
|
| 152 |
+
llm = PeftModel.from_pretrained(base_model, repo)
|
| 153 |
+
llm.eval()
|
| 154 |
+
|
| 155 |
+
inputs = tokenizer(build_instruction_prompt(prompt), return_tensors="pt").to(llm.device)
|
| 156 |
+
|
| 157 |
+
start = time.perf_counter()
|
| 158 |
+
with torch.no_grad():
|
| 159 |
+
out = llm.generate(
|
| 160 |
+
**inputs,
|
| 161 |
+
max_new_tokens=320,
|
| 162 |
+
output_scores=True,
|
| 163 |
+
return_dict_in_generate=True,
|
| 164 |
+
do_sample=False,
|
| 165 |
+
pad_token_id=tokenizer.eos_token_id
|
| 166 |
+
)
|
| 167 |
+
latency = int((time.perf_counter() - start) * 1000)
|
| 168 |
+
|
| 169 |
+
gen_ids = out.sequences[0][inputs["input_ids"].shape[1]:].tolist()
|
| 170 |
+
text = tokenizer.decode(gen_ids, skip_special_tokens=True)
|
| 171 |
+
|
| 172 |
+
conf = []
|
| 173 |
+
for tid, score in zip(gen_ids, out.scores):
|
| 174 |
+
probs = torch.softmax(score[0], dim=-1)
|
| 175 |
+
conf.append(float(probs[tid].item()))
|
| 176 |
+
|
| 177 |
+
print(json.dumps(
|
| 178 |
+
build_structured_result(
|
| 179 |
+
prompt,
|
| 180 |
+
text,
|
| 181 |
+
latency,
|
| 182 |
+
tokenizer=tokenizer,
|
| 183 |
+
generated_ids=gen_ids,
|
| 184 |
+
token_confidences=conf
|
| 185 |
+
),
|
| 186 |
+
indent=2
|
| 187 |
+
))
|
| 188 |
```
|
| 189 |
|
| 190 |
+
---
|
| 191 |
+
|
| 192 |
+
## Evaluation
|
| 193 |
+
|
| 194 |
+
* Syntax validation
|
| 195 |
+
* Prompt-based testing
|
| 196 |
+
* Relevancy scoring
|
| 197 |
+
* Hallucination detection
|
| 198 |
+
|
| 199 |
+
---
|
| 200 |
+
|
| 201 |
+
## Strengths
|
| 202 |
+
|
| 203 |
+
* Lightweight and efficient
|
| 204 |
+
* Strong performance on structured prompts
|
| 205 |
+
* Generates readable and correct Python code
|
| 206 |
+
* Provides reasoning-aware outputs
|
| 207 |
+
|
| 208 |
+
---
|
| 209 |
+
|
| 210 |
+
## Limitations
|
| 211 |
+
|
| 212 |
+
* Sensitive to prompt structure
|
| 213 |
+
* Confidence scores are heuristic
|
| 214 |
+
* Limited generalization beyond training dataset
|
| 215 |
+
|
| 216 |
+
---
|
| 217 |
+
|
| 218 |
+
## Risks & Considerations
|
| 219 |
+
|
| 220 |
+
* Always validate generated code
|
| 221 |
+
* Not suitable for critical production systems
|
| 222 |
+
* May produce incorrect logic
|
| 223 |
+
|
| 224 |
+
---
|
| 225 |
+
|
| 226 |
+
## Best Practices
|
| 227 |
+
|
| 228 |
+
```
|
| 229 |
+
Instruction:
|
| 230 |
+
Input:
|
| 231 |
+
Output:
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
* Use clear and specific prompts
|
| 235 |
+
* Keep temperature low for reliability
|
| 236 |
+
* Apply post-processing for cleaner output
|
| 237 |
+
|
| 238 |
+
---
|
| 239 |
+
|
| 240 |
+
## Technical Specifications
|
| 241 |
+
|
| 242 |
+
* Transformer-based causal language model
|
| 243 |
+
* LoRA adaptation on attention layers
|
| 244 |
+
* Hugging Face Transformers + PEFT
|
| 245 |
+
|
| 246 |
+
---
|
| 247 |
+
|
| 248 |
+
## Environmental Impact
|
| 249 |
+
|
| 250 |
+
* Uses parameter-efficient fine-tuning
|
| 251 |
+
* Lower compute compared to full fine-tuning
|
| 252 |
+
* Suitable for local deployment
|
| 253 |
+
|
| 254 |
+
---
|
| 255 |
+
|
| 256 |
+
## Intended Use
|
| 257 |
+
|
| 258 |
+
### Direct Use
|
| 259 |
+
|
| 260 |
+
* Coding assistant
|
| 261 |
+
* Debugging support
|
| 262 |
+
* Learning programming
|
| 263 |
+
|
| 264 |
+
### Out-of-Scope Use
|
| 265 |
+
|
| 266 |
+
* Security-critical systems
|
| 267 |
+
* Autonomous production deployment
|
| 268 |
+
|
| 269 |
+
---
|
| 270 |
+
|
| 271 |
+
## Author
|
| 272 |
+
|
| 273 |
+
**GIRISH KUMAR DEWANGAN**
|
| 274 |
+
|
| 275 |
+
---
|
| 276 |
+
|
| 277 |
+
## License
|
| 278 |
+
|
| 279 |
+
Apache License 2.0
|
| 280 |
+
|
| 281 |
+
---
|