Aditya commited on
Commit
268a4fa
·
1 Parent(s): 78c912f

Add LoRA checkpoint, benchmark results table, and updated README

Browse files

- checkpoint-25/: LoRA fine-tune checkpoint for Qwen2.5-1.5B-Instruct
(r=8, alpha=32, target q_proj+v_proj, trained on 50-topic CS Q&A data)
- README: Add Benchmark Results table with real numbers from benchmark_cache.json
(Baseline 81.5% acc / 1.46s, RAG 79.9% acc / 4.19s across 50 questions)
- README: Updated project structure to include checkpoint-25/ and run_benchmark.py
- README: Step 4 now shows how to merge LoRA adapter into finetuned_model/

README.md CHANGED
@@ -57,6 +57,24 @@ Covers CS fundamentals, algorithms, web technologies, databases, and tooling:
57
 
58
  ---
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  ## Project Structure
61
 
62
  ```
@@ -66,10 +84,15 @@ Covers CS fundamentals, algorithms, web technologies, databases, and tooling:
66
  ├── system2_rag.py # FAISS RAG pipeline
67
  ├── system3_inference.py # Fine-tuned model inference
68
  ├── system3_finetune_colab.ipynb # Qwen2.5 fine-tuning notebook (Colab)
 
69
  ├── requirements.txt
 
 
 
 
70
  ├── data/
71
  │ ├── reference_answers.json # 50 Q&A pairs for auto-evaluation
72
- │ ├── benchmark_cache.json # Persisted benchmark results (generated on first run)
73
  │ ├── finetune_data.jsonl # Training data in ChatML format
74
  │ ├── faiss_index/ # FAISS vector store (built automatically)
75
  │ ├── docs/ # Knowledge base .txt files
@@ -107,13 +130,31 @@ streamlit run demo.py
107
 
108
  The FAISS vector store is built automatically on first launch.
109
 
110
- ### 4. (Optional) Fine-tune the model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
 
112
- Open `system3_finetune_colab.ipynb` in Google Colab, run all cells, then download the resulting `finetuned_model/` folder and place it in the project root.
113
 
114
- ### 5. Run the benchmark (once)
115
 
116
- Click **Run Auto-Benchmark** in the Analytics tab. Results are saved to `data/benchmark_cache.json` and displayed permanently on every subsequent app load — no need to re-run.
 
 
117
 
118
  ---
119
 
 
57
 
58
  ---
59
 
60
+ ## Benchmark Results (n = 50 questions)
61
+
62
+ | Metric | Baseline LLM | RAG Chatbot | Fine-Tuned | Unit |
63
+ |--------|-------------|-------------|------------|------|
64
+ | Answer Accuracy | 81.5 | 79.9 | — | % |
65
+ | ROUGE-L | 0.216 | 0.291 | — | 0–1 |
66
+ | Groundedness | 0.815 | 0.575 | — | 0–1 |
67
+ | Answer Relevance | 0.720 | 0.768 | — | 0–1 |
68
+ | Faithfulness | 0.216 | 0.172 | — | 0–1 |
69
+ | Hallucination Rate | 0.0 | 6.0 | — | % |
70
+ | Avg Response Time | 1.46 | 4.19 | — | sec |
71
+ | Cost per Query | $0.0020 | $0.0020 | — | USD |
72
+
73
+ > Fine-Tuned column shows `—` until `finetuned_model/` is placed in the project root (see Setup §4).
74
+ > Full per-question results are in `data/benchmark_cache.json`.
75
+
76
+ ---
77
+
78
  ## Project Structure
79
 
80
  ```
 
84
  ├── system2_rag.py # FAISS RAG pipeline
85
  ├── system3_inference.py # Fine-tuned model inference
86
  ├── system3_finetune_colab.ipynb # Qwen2.5 fine-tuning notebook (Colab)
87
+ ├── run_benchmark.py # Standalone script to regenerate benchmark cache
88
  ├── requirements.txt
89
+ ├── checkpoint-25/ # LoRA fine-tune checkpoint (Qwen2.5-1.5B, r=8, α=32)
90
+ │ ├── adapter_model.safetensors # Trained LoRA weights
91
+ │ ├── adapter_config.json
92
+ │ └── tokenizer.json / tokenizer_config.json
93
  ├── data/
94
  │ ├── reference_answers.json # 50 Q&A pairs for auto-evaluation
95
+ │ ├── benchmark_cache.json # Pre-computed benchmark results (loads on startup)
96
  │ ├── finetune_data.jsonl # Training data in ChatML format
97
  │ ├── faiss_index/ # FAISS vector store (built automatically)
98
  │ ├── docs/ # Knowledge base .txt files
 
130
 
131
  The FAISS vector store is built automatically on first launch.
132
 
133
+ ### 4. (Optional) Use the fine-tuned model
134
+
135
+ A trained LoRA checkpoint is included in `checkpoint-25/`. To activate it for inference:
136
+
137
+ ```bash
138
+ # Merge LoRA adapter into base model and save as finetuned_model/
139
+ python -c "
140
+ from peft import PeftModel
141
+ from transformers import AutoModelForCausalLM, AutoTokenizer
142
+ base = AutoModelForCausalLM.from_pretrained('Qwen/Qwen2.5-1.5B-Instruct')
143
+ model = PeftModel.from_pretrained(base, 'checkpoint-25')
144
+ model.merge_and_unload().save_pretrained('finetuned_model')
145
+ AutoTokenizer.from_pretrained('checkpoint-25').save_pretrained('finetuned_model')
146
+ "
147
+ ```
148
+
149
+ Alternatively, open `system3_finetune_colab.ipynb` in Google Colab to retrain from scratch.
150
 
151
+ ### 5. Benchmark results — pre-loaded
152
 
153
+ `data/benchmark_cache.json` is included with pre-computed results for all 50 questions. The Analytics tab shows results instantly on startup. To regenerate:
154
 
155
+ ```bash
156
+ python run_benchmark.py
157
+ ```
158
 
159
  ---
160
 
checkpoint-25/README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-1.5B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen2.5-1.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.18.1
checkpoint-25/adapter_config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen2.5-1.5B-Instruct",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 32,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "megatron_config": null,
23
+ "megatron_core": "megatron.core",
24
+ "modules_to_save": null,
25
+ "peft_type": "LORA",
26
+ "peft_version": "0.18.1",
27
+ "qalora_group_size": 16,
28
+ "r": 8,
29
+ "rank_pattern": {},
30
+ "revision": null,
31
+ "target_modules": [
32
+ "v_proj",
33
+ "q_proj"
34
+ ],
35
+ "target_parameters": null,
36
+ "task_type": "CAUSAL_LM",
37
+ "trainable_token_indices": null,
38
+ "use_dora": false,
39
+ "use_qalora": false,
40
+ "use_rslora": false
41
+ }
checkpoint-25/adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:95ad32357e436c5010a145f4d3112e63be05302f70eb6a185cf869a030147895
3
+ size 4372840
checkpoint-25/chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
checkpoint-25/optimizer.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b1c7b47dacc25704dc6d905d6cfabc8ac0771a14e643a1fbe598644348b0f6e
3
+ size 8812555
checkpoint-25/rng_state.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:69610a701bcb39d3ec8463156b5457e3bd27b4732a2460a17492b205152b6237
3
+ size 14645
checkpoint-25/scaler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:652500b9116ca5d48648b8fc119f3c03e149cea9780a405ddba77469ca31da55
3
+ size 1383
checkpoint-25/scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51b5f7b55a43d2101a6b59146fef39ecf82d00ede346ad72ebb6609fa0b9ef0c
3
+ size 1465
checkpoint-25/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4b3fd40ce9345a559acbb2f18d1b0061a94c4197e899ef94f623749188852d8
3
+ size 11422167
checkpoint-25/tokenizer_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "model_max_length": 131072,
25
+ "pad_token": "<|im_end|>",
26
+ "split_special_tokens": false,
27
+ "tokenizer_class": "Qwen2Tokenizer",
28
+ "unk_token": null
29
+ }
checkpoint-25/trainer_state.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_global_step": null,
3
+ "best_metric": null,
4
+ "best_model_checkpoint": null,
5
+ "epoch": 5.0,
6
+ "eval_steps": 500,
7
+ "global_step": 25,
8
+ "is_hyper_param_search": false,
9
+ "is_local_process_zero": true,
10
+ "is_world_process_zero": true,
11
+ "log_history": [
12
+ {
13
+ "epoch": 2.0,
14
+ "grad_norm": 1.173736333847046,
15
+ "learning_rate": 0.00012800000000000002,
16
+ "loss": 1.449178981781006,
17
+ "step": 10
18
+ },
19
+ {
20
+ "epoch": 4.0,
21
+ "grad_norm": 1.3650461435317993,
22
+ "learning_rate": 4.8e-05,
23
+ "loss": 1.2445411682128906,
24
+ "step": 20
25
+ }
26
+ ],
27
+ "logging_steps": 10,
28
+ "max_steps": 25,
29
+ "num_input_tokens_seen": 0,
30
+ "num_train_epochs": 5,
31
+ "save_steps": 50,
32
+ "stateful_callbacks": {
33
+ "TrainerControl": {
34
+ "args": {
35
+ "should_epoch_stop": false,
36
+ "should_evaluate": false,
37
+ "should_log": false,
38
+ "should_save": true,
39
+ "should_training_stop": true
40
+ },
41
+ "attributes": {}
42
+ }
43
+ },
44
+ "total_flos": 402871340236800.0,
45
+ "train_batch_size": 4,
46
+ "trial_name": null,
47
+ "trial_params": null
48
+ }
checkpoint-25/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b66ecf0437db273e03d6d6b1fe4f5c54801df73d52a5f028f60897bb705926a3
3
+ size 5137