girish00 commited on
Commit
1f05683
·
verified ·
1 Parent(s): 953dad7

update model

Browse files
Files changed (1) hide show
  1. README.md +207 -244
README.md CHANGED
@@ -1,244 +1,207 @@
1
- # Advanced Fine-Tune Coding Model (Local + Hugging Face)
2
-
3
- This project fine-tunes `Qwen/Qwen2.5-Coder-0.5B-Instruct` using LoRA for:
4
- - code fixing
5
- - debugging
6
- - explanation
7
- - confidence and relevancy-aware outputs
8
-
9
- ## Files
10
-
11
- - `generate_dataset.py`: creates training dataset (5k-10k)
12
- - `finetune_coding_llm_colab.py`: local training script (LoRA) + optional upload
13
- - `infer_local.py`: test local trained model with structured JSON output
14
- - `infer_cloud.py`: run Hugging Face API inference and force the same structured JSON output
15
- - `handler.py`: custom Hugging Face Inference Endpoint handler that returns the same JSON contract from the hosted endpoint
16
- - `evaluate_model.py`: run multi-prompt quality checks and report accuracy
17
- - `upload_to_hf.py`: upload local model folder to HF
18
- - `run_pipeline.py`: one command for generate + train (+ optional upload)
19
- - `requirements.txt`: Python dependencies
20
- - `training_config.json`: default values automatically used by `run_pipeline.py`
21
-
22
- ## Local Setup (No Colab)
23
-
24
- Install dependencies:
25
-
26
- ```bash
27
- pip install -r requirements.txt
28
- ```
29
-
30
- Generate dataset (example: 8000 samples):
31
-
32
- ```bash
33
- python generate_dataset.py --size 8000 --out train.json
34
- ```
35
-
36
- Train locally:
37
-
38
- ```bash
39
- python finetune_coding_llm_colab.py --dataset-size 8000
40
- ```
41
-
42
- Enable 4-bit quantized loading (GPU):
43
-
44
- ```bash
45
- python finetune_coding_llm_colab.py --dataset-size 8000 --use-4bit
46
- ```
47
-
48
- Fast CPU smoke run:
49
-
50
- ```bash
51
- python finetune_coding_llm_colab.py --dataset-size 5000 --max-train-samples 200 --epochs 0.1
52
- ```
53
-
54
- Single command pipeline (no upload):
55
-
56
- ```bash
57
- python run_pipeline.py --dataset-size 8000 --skip-upload
58
- ```
59
-
60
- If `training_config.json` exists, `run_pipeline.py` reads it automatically for defaults.
61
-
62
- Use existing dataset without regenerating:
63
-
64
- ```bash
65
- python run_pipeline.py --dataset-size 8000 --train-file train.json --skip-generate --skip-upload
66
- ```
67
-
68
- Tunable training knobs:
69
-
70
- ```bash
71
- 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
72
- ```
73
-
74
- ## Configure 5k-10k samples
75
-
76
- ```python
77
- --dataset-size 5000
78
- --dataset-size 8000
79
- --dataset-size 10000
80
- ```
81
-
82
- Recommended values:
83
- - 5000 for fast iteration
84
- - 8000 as balanced
85
- - 10000 for stronger adaptation (slower)
86
-
87
- ## Hugging Face Deployment
88
-
89
- Upload is optional and can be done after training:
90
-
91
- ```bash
92
- python upload_to_hf.py --model-dir model --repo-id your-username/your-model-name
93
- ```
94
-
95
- ### Update Existing HF Model Repo
96
-
97
- To update your already-created Hugging Face model with this new JSON-output behavior:
98
-
99
- 1. Retrain locally with latest code:
100
- ```bash
101
- python run_pipeline.py --dataset-size 8000 --skip-upload
102
- ```
103
-
104
- 2. Login to Hugging Face:
105
- ```bash
106
- huggingface-cli login
107
- ```
108
-
109
- 3. Upload to the same repo ID (this updates existing files):
110
- ```bash
111
- python upload_to_hf.py --model-dir model --repo-id your-username/your-existing-model-name
112
- ```
113
-
114
- Optional safer rollout using a new revision/branch:
115
- ```bash
116
- 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')"
117
- ```
118
-
119
- You can also trigger upload from trainer:
120
-
121
- ```bash
122
- python finetune_coding_llm_colab.py --skip-dataset-gen --skip-train --upload --hf-repo your-username/your-model-name
123
- ```
124
-
125
- ## Quick Inference Test (Structured JSON)
126
-
127
- After local training, inference returns JSON with:
128
- - `code`
129
- - `explanation`
130
- - `confidence`
131
- - `important_tokens`
132
- - `relevancy_score`
133
- - `hallucination`
134
- - `hallucination_check_reason`
135
- - `latency_ms`
136
-
137
- ```python
138
- python infer_local.py --model-path model --prompt "Fix this code: def add(a,b) return a+b"
139
- ```
140
-
141
- Run the same structured-output wrapper through the Hugging Face API:
142
-
143
- ```bash
144
- set HF_TOKEN=your_huggingface_token
145
- python infer_cloud.py --repo-id your-username/your-model-name --prompt "Fix this code: def add(a,b) return a+b"
146
- ```
147
-
148
- PowerShell:
149
-
150
- ```powershell
151
- $env:HF_TOKEN="your_huggingface_token"
152
- python infer_cloud.py --repo-id your-username/your-model-name --prompt "Fix this code: def add(a,b) return a+b"
153
- ```
154
-
155
- If you already ran `hf auth login` or `huggingface-cli login`, you can omit `HF_TOKEN`; the saved token will be used automatically.
156
-
157
- For true cloud execution, deploy the model as a Hugging Face Dedicated Inference Endpoint and pass the endpoint URL:
158
-
159
- ```powershell
160
- $env:HF_TOKEN="your_huggingface_token"
161
- 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
162
- ```
163
-
164
- You can also use environment variables:
165
-
166
- ```powershell
167
- $env:HF_TOKEN="your_huggingface_token"
168
- $env:HF_ENDPOINT_URL="https://your-endpoint-url.endpoints.huggingface.cloud"
169
- python infer_cloud.py --prompt "Fix this code: def add(a,b) return a+b" --no-local-fallback
170
- ```
171
-
172
- `infer_cloud.py` applies the same JSON parsing, Python syntax check, relevancy score, hallucination flag, and auto-repair fallback as `infer_local.py`. If Hugging Face cannot serve your custom model repo through an inference provider, the script automatically falls back to the local `model/` folder so the command still returns the local-style JSON. Use `--no-local-fallback` if you want cloud-only failure behavior.
173
-
174
- Hosted Hugging Face API calls usually do not return token logits, so `important_tokens` may be empty and `confidence` may be `0.0` unless your endpoint returns token-level details. When the local fallback runs, those fields are computed the same way as `infer_local.py`.
175
-
176
- ### Cloud Output Guarantee
177
-
178
- To make other users receive this JSON pattern with their own token, deploy this repository as a Hugging Face Dedicated Inference Endpoint. The included `handler.py` is loaded by the endpoint and returns:
179
-
180
- ```json
181
- {
182
- "code": "string",
183
- "explanation": "string",
184
- "confidence": 0.0,
185
- "important_tokens": [],
186
- "relevancy_score": 0.0,
187
- "hallucination": false,
188
- "hallucination_check_reason": "string",
189
- "latency_ms": 0
190
- }
191
- ```
192
-
193
- Endpoint request example:
194
-
195
- ```powershell
196
- $env:HF_TOKEN="their_huggingface_token"
197
- Invoke-RestMethod `
198
- -Uri "https://your-endpoint-url.endpoints.huggingface.cloud" `
199
- -Method Post `
200
- -Headers @{ Authorization = "Bearer $env:HF_TOKEN" } `
201
- -ContentType "application/json" `
202
- -Body '{"inputs":"Fix this code: def add(a,b) return a+b","parameters":{"max_new_tokens":320}}'
203
- ```
204
-
205
- Calling the model repository directly through Hugging Face serverless inference is not enough if Hugging Face has no provider serving the custom repo. Use a Dedicated Inference Endpoint or your own cloud VM for true cloud execution.
206
-
207
- Explicit base model for LoRA adapter loading:
208
-
209
- ```python
210
- python infer_local.py --model-path model --base-model Qwen/Qwen2.5-Coder-0.5B-Instruct --prompt "Fix this code: def add(a,b) return a+b"
211
- ```
212
-
213
- `infer_local.py` automatically handles both:
214
- - LoRA adapter output folders
215
- - Fully merged/full-model output folders
216
-
217
- ## Accuracy Evaluation
218
-
219
- Run default evaluation prompts:
220
-
221
- ```bash
222
- python evaluate_model.py --model-path model
223
- ```
224
-
225
- Run with custom prompts:
226
-
227
- ```bash
228
- python evaluate_model.py --model-path model --prompt "Fix this code: if x = 5: print(x)" --prompt "Write python code for linear regression and explain it"
229
- ```
230
-
231
- For higher quality output:
232
- - use dataset size `8000` or `10000`
233
- - use `epochs >= 3`
234
- - prefer `--use-4bit` when GPU is available
235
- - keep prompts specific and task-focused
236
-
237
- ## Recommended Run Order
238
-
239
- ```bash
240
- python run_pipeline.py --dataset-size 8000 --skip-upload
241
- python infer_local.py --model-path model --prompt "Fix this code: def add(a,b) return a+b"
242
- python evaluate_model.py --model-path model
243
- python upload_to_hf.py --model-dir model --repo-id your-username/your-existing-model-name
244
- ```
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-Coder-0.5B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen2.5-Coder-0.5B-Instruct
7
+ - lora
8
+ - transformers
9
+ ---
10
+
11
+ # Model Card for Model ID
12
+
13
+ <!-- Provide a quick summary of what the model is/does. -->
14
+
15
+
16
+
17
+ ## Model Details
18
+
19
+ ### Model Description
20
+
21
+ <!-- Provide a longer summary of what this model is. -->
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
+ ### Model Sources [optional]
34
+
35
+ <!-- Provide the basic links for the model. -->
36
+
37
+ - **Repository:** [More Information Needed]
38
+ - **Paper [optional]:** [More Information Needed]
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
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
+
49
+ [More Information Needed]
50
+
51
+ ### Downstream Use [optional]
52
+
53
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
+
55
+ [More Information Needed]
56
+
57
+ ### Out-of-Scope Use
58
+
59
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
+
61
+ [More Information Needed]
62
+
63
+ ## Bias, Risks, and Limitations
64
+
65
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
+
67
+ [More Information Needed]
68
+
69
+ ### Recommendations
70
+
71
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
+
73
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
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
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
+
87
+ [More Information Needed]
88
+
89
+ ### Training Procedure
90
+
91
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
+
93
+ #### Preprocessing [optional]
94
+
95
+ [More Information Needed]
96
+
97
+
98
+ #### Training Hyperparameters
99
+
100
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
+
102
+ #### Speeds, Sizes, Times [optional]
103
+
104
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
+
106
+ [More Information Needed]
107
+
108
+ ## Evaluation
109
+
110
+ <!-- This section describes the evaluation protocols and provides the results. -->
111
+
112
+ ### Testing Data, Factors & Metrics
113
+
114
+ #### Testing Data
115
+
116
+ <!-- This should link to a Dataset Card if possible. -->
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
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
+
130
+ [More Information Needed]
131
+
132
+ ### Results
133
+
134
+ [More Information Needed]
135
+
136
+ #### Summary
137
+
138
+
139
+
140
+ ## Model Examination [optional]
141
+
142
+ <!-- Relevant interpretability work for the model goes here -->
143
+
144
+ [More Information Needed]
145
+
146
+ ## Environmental Impact
147
+
148
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
+
150
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
+
152
+ - **Hardware Type:** [More Information Needed]
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 [optional]
159
+
160
+ ### Model Architecture and Objective
161
+
162
+ [More Information Needed]
163
+
164
+ ### Compute Infrastructure
165
+
166
+ [More Information Needed]
167
+
168
+ #### Hardware
169
+
170
+ [More Information Needed]
171
+
172
+ #### Software
173
+
174
+ [More Information Needed]
175
+
176
+ ## Citation [optional]
177
+
178
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
+
180
+ **BibTeX:**
181
+
182
+ [More Information Needed]
183
+
184
+ **APA:**
185
+
186
+ [More Information Needed]
187
+
188
+ ## Glossary [optional]
189
+
190
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
+
192
+ [More Information Needed]
193
+
194
+ ## More Information [optional]
195
+
196
+ [More Information Needed]
197
+
198
+ ## Model Card Authors [optional]
199
+
200
+ [More Information Needed]
201
+
202
+ ## Model Card Contact
203
+
204
+ [More Information Needed]
205
+ ### Framework versions
206
+
207
+ - PEFT 0.19.0