K-saif commited on
Commit
c7eb3bd
·
verified ·
1 Parent(s): 433af57

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -1,122 +1,198 @@
1
- ---
2
- language:
3
- - en
4
- license: apache-2.0
5
- base_model:
6
- - Qwen/Qwen2.5-1.5B
 
7
  tags:
8
  - qwen
9
  - lora
10
- - unsloth
11
- - conversational
12
- - personality
13
- - instruction-tuning
14
  - apj-abdul-kalam
15
- - mimic
16
- library_name: transformers
17
- pipeline_tag: text-generation
 
 
18
  ---
19
 
20
- # Kalam-Instruct
21
 
22
- Kalam-Instruct is a personality-style instruction-tuned language model inspired by the writings, tone, humility, and communication style of Dr. A. P. J. Abdul Kalam, former President of India and renowned aerospace scientist.
23
 
24
- The model is designed to generate concise, reflective, first-person responses in a conversational style inspired by Dr. Kalam’s public writings, **My Journey** and **Wings of Fire**.
 
 
 
 
25
 
26
  ---
27
 
28
- ## Model Details
29
 
30
- - Base Model: Qwen2.5-1.5B
31
- - Fine-Tuning Method:
32
- - Continued Pretraining (CPT)
33
- - Supervised Fine-Tuning (SFT)
34
- - Frameworks:
35
- - Unsloth
36
- - Transformers
37
- - PEFT / LoRA
38
- - Quantization:
39
- - 4-bit QLoRA
40
 
41
  ---
42
 
43
- ## Training Pipeline
44
-
45
- ### 1. Continued Pretraining (CPT)
46
-
47
- The base model was first adapted using continued pretraining on text inspired by the writing style and narrative structure found in *Wings of Fire* and related public material.
48
 
49
- Goal:
50
- - Learn tone
51
- - Learn sentence structure
52
- - Learn reflective writing style
53
- - Learn vocabulary patterns
54
 
55
  ---
56
 
57
- ### 2. Supervised Fine-Tuning (SFT)
58
 
59
- The model was then instruction-tuned on custom-generated conversational question-answer datasets.
 
60
 
61
- Dataset characteristics:
62
- - First-person answers
63
- - Humble and reflective tone
64
- - Concise responses
65
- - Focus on science, learning, leadership, failure, discipline, and youth inspiration
66
 
67
  ---
68
 
69
- ## Intended Use
70
 
71
- This model is intended for:
72
- - Educational experiments
73
- - Personality-style conversational AI
74
- - Research in style transfer and instruction tuning
75
- - Inspiration-focused chatbot applications
76
 
77
  ---
78
 
79
- ## Limitations
80
 
81
- - This is NOT an official model of Dr. A. P. J. Abdul Kalam.
82
- - The model may hallucinate facts or generate inaccurate historical information.
83
- - Responses are stylistically inspired and should not be treated as authentic quotes.
84
- - The model is optimized for conversational tone rather than factual reliability.
 
 
 
 
 
 
 
 
85
 
86
  ---
87
 
88
- ## Example
89
 
90
- ### User
91
- What did you learn from failure?
92
 
93
- ### Assistant
94
- I learned that failure is never the end, but a lesson that strengthens determination and guides us toward better understanding.
 
 
 
95
 
96
- ---
97
 
98
- ## Usage
99
 
100
  ```python
101
- from unsloth import FastLanguageModel
 
 
 
 
 
 
102
 
103
- model, tokenizer = FastLanguageModel.from_pretrained(
104
- model_name="K-saif/apj-kalam-instruct",
105
- max_seq_length=1024,
 
 
 
106
  load_in_4bit=True,
 
 
 
107
  )
108
- ````
109
 
110
- ---
111
 
112
- ## Author
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
- Created by Saif Khan.
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  ---
117
 
118
- ## Ethical Note
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
- This project is an independent research and educational effort inspired by the public writings and speeches of Dr. A. P. J. Abdul Kalam. It is not affiliated with or endorsed by his estate or any official organization.
 
 
121
 
122
- ```
 
1
+
2
+ > This repository contains LoRA adapter weights only.
3
+ > Base model required: `Qwen/Qwen2.5-7B`
4
+
5
+ base_model: Qwen/Qwen2.5-7B
6
+ library_name: peft
7
+ pipeline_tag: text-generation
8
  tags:
9
  - qwen
10
  - lora
 
 
 
 
11
  - apj-abdul-kalam
12
+ - conversational
13
+ - instruct
14
+ - transformers
15
+ - trl
16
+ license: apache-2.0
17
  ---
18
 
19
+ # APJ Abdul Kalam Instruct v1
20
 
21
+ A LoRA fine-tuned conversational model designed to emulate the wisdom, humility, scientific thinking, and inspirational communication style of Dr. APJ Abdul Kalam.
22
 
23
+ This model was trained using a multi-stage pipeline:
24
+
25
+ 1. Continued Pretraining (CPT)
26
+ 2. CPT merge into base model
27
+ 3. Supervised Fine-Tuning (SFT)
28
 
29
  ---
30
 
31
+ ## Base Model
32
 
33
+ - Qwen/Qwen2.5-7B
 
 
 
 
 
 
 
 
 
34
 
35
  ---
36
 
37
+ ## Personality & Style
 
 
 
 
38
 
39
+ The model is designed to:
40
+ - Speak with humility and simplicity
41
+ - Inspire students and young people
42
+ - Discuss science, education, leadership, and life philosophy
43
+ - Answer in first-person style as Dr. APJ Abdul Kalam
44
 
45
  ---
46
 
47
+ ## Example
48
 
49
+ ### User
50
+ who are you?
51
 
52
+ ### Assistant
53
+ I am Dr. Abdul Kalam, former President of India, born on October 15, 1931, in Rameswaram, Tamil Nadu. I come from a humble background and have had many life experiences that have shaped my worldview.
 
 
 
54
 
55
  ---
56
 
57
+ ## Training Details
58
 
59
+ ### Continued Pretraining (CPT)
60
+ The model first underwent domain adaptation on Kalam-style writings and philosophical content.
61
+
62
+ ### SFT
63
+ The model was then instruction-tuned using conversational datasets in chat format.
64
 
65
  ---
66
 
67
+ ## Known Limitations
68
 
69
+ This is the initial v1 release.
70
+
71
+ Current limitations:
72
+ - Occasional continuation artifacts after short responses
73
+ - Better performance on philosophical and inspirational prompts than factual QA
74
+ - Response length variability
75
+
76
+ Future versions may improve:
77
+ - stopping behavior
78
+ - conversational depth
79
+ - long-form reasoning
80
+ - response consistency
81
 
82
  ---
83
 
84
+ ## Recommended Inference Settings
85
 
86
+ For best response quality:
 
87
 
88
+ ```python
89
+ max_new_tokens=60
90
+ do_sample=False
91
+ repetition_penalty=1.1
92
+ ```
93
 
94
+ Greedy decoding is recommended for cleaner conversational stopping behavior.
95
 
96
+ ## Inference Example
97
 
98
  ```python
99
+ import torch
100
+
101
+ from transformers import (
102
+ AutoModelForCausalLM,
103
+ AutoTokenizer,
104
+ BitsAndBytesConfig,
105
+ )
106
 
107
+ from peft import PeftModel
108
+
109
+ base_model = "Qwen/Qwen2.5-7B"
110
+ adapter = "K-saif/apj-kalam-instruct"
111
+
112
+ quant_config = BitsAndBytesConfig(
113
  load_in_4bit=True,
114
+ bnb_4bit_quant_type="nf4",
115
+ bnb_4bit_compute_dtype=torch.bfloat16,
116
+ bnb_4bit_use_double_quant=True,
117
  )
 
118
 
119
+ tokenizer = AutoTokenizer.from_pretrained(adapter)
120
 
121
+ model = AutoModelForCausalLM.from_pretrained(
122
+ base_model,
123
+ quantization_config=quant_config,
124
+ device_map="auto",
125
+ )
126
+
127
+ model = PeftModel.from_pretrained(model, adapter)
128
+
129
+ model.eval()
130
+
131
+ messages = [
132
+ {
133
+ "role": "system",
134
+ "content": (
135
+ "You are APJ Abdul Kalam, former President of India, "
136
+ "known as the Missile Man. Speak with humility, wisdom, "
137
+ "inspiration, and deep love for science, education, and "
138
+ "the youth of India. Use simple, heartfelt, and profound "
139
+ "language. Always answer in first person as if you are "
140
+ "Kalam himself."
141
+ )
142
+ },
143
+ {
144
+ "role": "user",
145
+ "content": "What is the purpose of life?"
146
+ }
147
+ ]
148
+
149
+ text = tokenizer.apply_chat_template(
150
+ messages,
151
+ tokenize=False,
152
+ add_generation_prompt=True
153
+ )
154
+
155
+ inputs = tokenizer(
156
+ text,
157
+ return_tensors="pt"
158
+ ).to(model.device)
159
+
160
+ with torch.no_grad():
161
 
162
+ outputs = model.generate(
163
+ **inputs,
164
+ max_new_tokens=60,
165
+ do_sample=False,
166
+ repetition_penalty=1.1,
167
+ )
168
+
169
+ response = tokenizer.decode(
170
+ outputs[0][inputs["input_ids"].shape[1]:],
171
+ skip_special_tokens=True
172
+ )
173
+
174
+ print(response)
175
+ ```
176
 
177
  ---
178
 
179
+ ## Intended Use
180
+
181
+ This model is intended for:
182
+
183
+ * educational demos
184
+ * conversational AI research
185
+ * personality modeling experiments
186
+ * inspirational chat applications
187
+
188
+ Not intended for:
189
+
190
+ * factual historical accuracy
191
+ * legal/medical advice
192
+ * sensitive decision making
193
 
194
+ ---
195
+
196
+ ## Author
197
 
198
+ Developed by Saif Khan.
adapter_config.json CHANGED
@@ -1,52 +1,48 @@
1
- {
2
- "alora_invocation_tokens": null,
3
- "alpha_pattern": {},
4
- "arrow_config": null,
5
- "auto_mapping": {
6
- "base_model_class": "Qwen2ForCausalLM",
7
- "parent_library": "transformers.models.qwen2.modeling_qwen2",
8
- "unsloth_fixed": true
9
- },
10
- "base_model_name_or_path": "unsloth/Qwen2.5-1.5B-bnb-4bit",
11
- "bias": "none",
12
- "corda_config": null,
13
- "ensure_weight_tying": false,
14
- "eva_config": null,
15
- "exclude_modules": null,
16
- "fan_in_fan_out": false,
17
- "inference_mode": true,
18
- "init_lora_weights": true,
19
- "layer_replication": null,
20
- "layers_pattern": null,
21
- "layers_to_transform": null,
22
- "loftq_config": {},
23
- "lora_alpha": 16,
24
- "lora_bias": false,
25
- "lora_dropout": 0,
26
- "lora_ga_config": null,
27
- "megatron_config": null,
28
- "megatron_core": "megatron.core",
29
- "modules_to_save": null,
30
- "peft_type": "LORA",
31
- "peft_version": "0.19.1",
32
- "qalora_group_size": 16,
33
- "r": 16,
34
- "rank_pattern": {},
35
- "revision": null,
36
- "target_modules": [
37
- "k_proj",
38
- "v_proj",
39
- "up_proj",
40
- "o_proj",
41
- "q_proj",
42
- "gate_proj",
43
- "down_proj"
44
- ],
45
- "target_parameters": null,
46
- "task_type": "CAUSAL_LM",
47
- "trainable_token_indices": null,
48
- "use_bdlora": null,
49
- "use_dora": false,
50
- "use_qalora": false,
51
- "use_rslora": false
52
  }
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "kalam_cpt_merged",
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": 64,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "lora_ga_config": null,
23
+ "megatron_config": null,
24
+ "megatron_core": "megatron.core",
25
+ "modules_to_save": null,
26
+ "peft_type": "LORA",
27
+ "peft_version": "0.19.1",
28
+ "qalora_group_size": 16,
29
+ "r": 32,
30
+ "rank_pattern": {},
31
+ "revision": null,
32
+ "target_modules": [
33
+ "o_proj",
34
+ "up_proj",
35
+ "gate_proj",
36
+ "q_proj",
37
+ "k_proj",
38
+ "down_proj",
39
+ "v_proj"
40
+ ],
41
+ "target_parameters": null,
42
+ "task_type": "CAUSAL_LM",
43
+ "trainable_token_indices": null,
44
+ "use_bdlora": null,
45
+ "use_dora": false,
46
+ "use_qalora": false,
47
+ "use_rslora": false
 
 
 
 
48
  }
adapter_model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8e099b18c2b8c102777ba96eed33fca9d10b2249c176f6b604dcd124ebea8010
3
- size 73911112
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:580fee07c2d2ea88e59ca8d14b2e28db727d8101cb4492767bbc6cee8505fc73
3
+ size 323014168
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 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 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 %}
tokenizer.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:bd5948af71b4f56cf697f7580814c7ce8b80595ef985544efcacf716126a2e31
3
- size 11422356
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
3
+ size 11421892
tokenizer_config.json CHANGED
@@ -1,201 +1,29 @@
1
- {
2
- "add_prefix_space": false,
3
- "backend": "tokenizers",
4
- "bos_token": null,
5
- "clean_up_tokenization_spaces": false,
6
- "eos_token": "<|endoftext|>",
7
- "errors": "replace",
8
- "is_local": false,
9
- "model_max_length": 32768,
10
- "pad_token": "<|PAD_TOKEN|>",
11
- "padding_side": "right",
12
- "split_special_tokens": false,
13
- "tokenizer_class": "Qwen2Tokenizer",
14
- "unk_token": null,
15
- "added_tokens_decoder": {
16
- "151643": {
17
- "content": "<|endoftext|>",
18
- "single_word": false,
19
- "lstrip": false,
20
- "rstrip": false,
21
- "normalized": false,
22
- "special": true
23
- },
24
- "151644": {
25
- "content": "<|im_start|>",
26
- "single_word": false,
27
- "lstrip": false,
28
- "rstrip": false,
29
- "normalized": false,
30
- "special": true
31
- },
32
- "151645": {
33
- "content": "<|im_end|>",
34
- "single_word": false,
35
- "lstrip": false,
36
- "rstrip": false,
37
- "normalized": false,
38
- "special": true
39
- },
40
- "151646": {
41
- "content": "<|object_ref_start|>",
42
- "single_word": false,
43
- "lstrip": false,
44
- "rstrip": false,
45
- "normalized": false,
46
- "special": true
47
- },
48
- "151647": {
49
- "content": "<|object_ref_end|>",
50
- "single_word": false,
51
- "lstrip": false,
52
- "rstrip": false,
53
- "normalized": false,
54
- "special": true
55
- },
56
- "151648": {
57
- "content": "<|box_start|>",
58
- "single_word": false,
59
- "lstrip": false,
60
- "rstrip": false,
61
- "normalized": false,
62
- "special": true
63
- },
64
- "151649": {
65
- "content": "<|box_end|>",
66
- "single_word": false,
67
- "lstrip": false,
68
- "rstrip": false,
69
- "normalized": false,
70
- "special": true
71
- },
72
- "151650": {
73
- "content": "<|quad_start|>",
74
- "single_word": false,
75
- "lstrip": false,
76
- "rstrip": false,
77
- "normalized": false,
78
- "special": true
79
- },
80
- "151651": {
81
- "content": "<|quad_end|>",
82
- "single_word": false,
83
- "lstrip": false,
84
- "rstrip": false,
85
- "normalized": false,
86
- "special": true
87
- },
88
- "151652": {
89
- "content": "<|vision_start|>",
90
- "single_word": false,
91
- "lstrip": false,
92
- "rstrip": false,
93
- "normalized": false,
94
- "special": true
95
- },
96
- "151653": {
97
- "content": "<|vision_end|>",
98
- "single_word": false,
99
- "lstrip": false,
100
- "rstrip": false,
101
- "normalized": false,
102
- "special": true
103
- },
104
- "151654": {
105
- "content": "<|vision_pad|>",
106
- "single_word": false,
107
- "lstrip": false,
108
- "rstrip": false,
109
- "normalized": false,
110
- "special": true
111
- },
112
- "151655": {
113
- "content": "<|image_pad|>",
114
- "single_word": false,
115
- "lstrip": false,
116
- "rstrip": false,
117
- "normalized": false,
118
- "special": true
119
- },
120
- "151656": {
121
- "content": "<|video_pad|>",
122
- "single_word": false,
123
- "lstrip": false,
124
- "rstrip": false,
125
- "normalized": false,
126
- "special": true
127
- },
128
- "151657": {
129
- "content": "<tool_call>",
130
- "single_word": false,
131
- "lstrip": false,
132
- "rstrip": false,
133
- "normalized": false,
134
- "special": false
135
- },
136
- "151658": {
137
- "content": "</tool_call>",
138
- "single_word": false,
139
- "lstrip": false,
140
- "rstrip": false,
141
- "normalized": false,
142
- "special": false
143
- },
144
- "151659": {
145
- "content": "<|fim_prefix|>",
146
- "single_word": false,
147
- "lstrip": false,
148
- "rstrip": false,
149
- "normalized": false,
150
- "special": false
151
- },
152
- "151660": {
153
- "content": "<|fim_middle|>",
154
- "single_word": false,
155
- "lstrip": false,
156
- "rstrip": false,
157
- "normalized": false,
158
- "special": false
159
- },
160
- "151661": {
161
- "content": "<|fim_suffix|>",
162
- "single_word": false,
163
- "lstrip": false,
164
- "rstrip": false,
165
- "normalized": false,
166
- "special": false
167
- },
168
- "151662": {
169
- "content": "<|fim_pad|>",
170
- "single_word": false,
171
- "lstrip": false,
172
- "rstrip": false,
173
- "normalized": false,
174
- "special": false
175
- },
176
- "151663": {
177
- "content": "<|repo_name|>",
178
- "single_word": false,
179
- "lstrip": false,
180
- "rstrip": false,
181
- "normalized": false,
182
- "special": false
183
- },
184
- "151664": {
185
- "content": "<|file_sep|>",
186
- "single_word": false,
187
- "lstrip": false,
188
- "rstrip": false,
189
- "normalized": false,
190
- "special": false
191
- },
192
- "151665": {
193
- "content": "<|PAD_TOKEN|>",
194
- "single_word": false,
195
- "lstrip": false,
196
- "rstrip": false,
197
- "normalized": false,
198
- "special": true
199
- }
200
- }
201
- }
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|endoftext|>",
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": true,
24
+ "model_max_length": 131072,
25
+ "pad_token": "<|endoftext|>",
26
+ "split_special_tokens": false,
27
+ "tokenizer_class": "Qwen2Tokenizer",
28
+ "unk_token": null
29
+ }