Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,209 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
datasets:
|
4 |
+
- yahma/alpaca-cleaned
|
5 |
+
---
|
6 |
+
## Model Details
|
7 |
+
|
8 |
+
This model builds upon the neuromorphic **Llama-SNN-LTC** base architecture, incorporating **Spiking Neural Networks (SNNs)** and **Liquid Time Constants (LTCs)**, and fine-tunes it specifically for instruction following using the Alpaca Cleaned dataset.
|
9 |
+
|
10 |
+
**Model Type**: Instruction-Following Language Model with Neuromorphic Enhancements
|
11 |
+
**Supported Languages**: English
|
12 |
+
**Number of Parameters**: 155.8M
|
13 |
+
**Context Length**: 1024 tokens
|
14 |
+
**Base Architecture**: Llama with SNN/LTC modifications
|
15 |
+
**Base Model**: rootxhacker/arthemis-lm
|
16 |
+
**Fine-tuning Data**: Alpaca Cleaned (~52K instruction-response pairs)
|
17 |
+
|
18 |
+
### Architecture Features
|
19 |
+
- **Spiking Neural Networks** in attention mechanisms for temporal processing
|
20 |
+
- **Liquid Time Constants** in feed-forward layers for adaptive dynamics
|
21 |
+
- **12-layer transformer backbone** with neuromorphic enhancements
|
22 |
+
- **RoPE positional encoding** for sequence understanding
|
23 |
+
- **Custom surrogate gradient training** for differentiable spike computation
|
24 |
+
- **Instruction-following fine-tuning** for enhanced conversational abilities
|
25 |
+
|
26 |
+
Here are my major model configurations:
|
27 |
+
|
28 |
+
```
|
29 |
+
hidden_size = 768
|
30 |
+
intermediate_size = 2048
|
31 |
+
num_hidden_layers = 12
|
32 |
+
num_attention_heads = 12
|
33 |
+
num_key_value_heads = 12
|
34 |
+
max_position_embeddings = 1024
|
35 |
+
vocab_size = 50257
|
36 |
+
spiking_threshold = 1.0
|
37 |
+
ltc_hidden_size = 256
|
38 |
+
ltc_layers = 2
|
39 |
+
```
|
40 |
+
|
41 |
+
## Usage
|
42 |
+
|
43 |
+
### Install dependencies
|
44 |
+
```bash
|
45 |
+
pip install transformers torch numpy
|
46 |
+
```
|
47 |
+
|
48 |
+
### Run code!
|
49 |
+
```python
|
50 |
+
# Note: This model requires custom implementation due to SNN/LTC architecture
|
51 |
+
# Standard transformers library cannot load this model directly
|
52 |
+
|
53 |
+
# For custom loading, you'll need the specialized architecture:
|
54 |
+
from custom_model import LlamaSNNLTCModel
|
55 |
+
from transformers import AutoTokenizer
|
56 |
+
|
57 |
+
# Load tokenizer
|
58 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-small")
|
59 |
+
tokenizer.pad_token = tokenizer.eos_token
|
60 |
+
|
61 |
+
# Load the instruction-tuned model
|
62 |
+
model = LlamaSNNLTCModel.from_pretrained("rootxhacker/arthemis-instruct")
|
63 |
+
|
64 |
+
# For instruction-following generation
|
65 |
+
def generate_instruction_response(instruction, input_text="", model=None, tokenizer=None, max_length=150):
|
66 |
+
model.eval()
|
67 |
+
device = next(model.parameters()).device
|
68 |
+
|
69 |
+
# Reset model states for clean generation
|
70 |
+
model.reset_states()
|
71 |
+
|
72 |
+
# Format prompt in Alpaca style
|
73 |
+
if input_text.strip():
|
74 |
+
prompt = f"### Instruction:\n{instruction}\n\n### Input:\n{input_text}\n\n### Response:\n"
|
75 |
+
else:
|
76 |
+
prompt = f"### Instruction:\n{instruction}\n\n### Response:\n"
|
77 |
+
|
78 |
+
inputs = tokenizer(prompt, return_tensors='pt').to(device)
|
79 |
+
input_ids = inputs['input_ids']
|
80 |
+
|
81 |
+
with torch.no_grad():
|
82 |
+
for _ in range(max_length - input_ids.shape[1]):
|
83 |
+
outputs = model(input_ids)
|
84 |
+
logits = outputs['logits'][0, -1, :]
|
85 |
+
|
86 |
+
# Sample with temperature for more natural responses
|
87 |
+
logits = logits / 0.7
|
88 |
+
probs = torch.softmax(logits, dim=-1)
|
89 |
+
next_token = torch.multinomial(probs, 1)
|
90 |
+
|
91 |
+
input_ids = torch.cat([input_ids, next_token.unsqueeze(0)], dim=-1)
|
92 |
+
|
93 |
+
if next_token.item() == tokenizer.eos_token_id:
|
94 |
+
break
|
95 |
+
|
96 |
+
generated = tokenizer.decode(input_ids[0], skip_special_tokens=True)
|
97 |
+
|
98 |
+
# Extract just the response part
|
99 |
+
if "### Response:\n" in generated:
|
100 |
+
response = generated.split("### Response:\n")[-1].strip()
|
101 |
+
return response
|
102 |
+
|
103 |
+
return generated
|
104 |
+
|
105 |
+
# Example usage
|
106 |
+
instruction = "Explain what artificial intelligence is in simple terms."
|
107 |
+
response = generate_instruction_response(instruction, model=model, tokenizer=tokenizer)
|
108 |
+
print(f"Instruction: {instruction}")
|
109 |
+
print(f"Response: {response}")
|
110 |
+
```
|
111 |
+
|
112 |
+
|
113 |
+
## Evaluation
|
114 |
+
|
115 |
+
I performed evaluation using the standard lm-evaluation-harness setup. Following similar methodology to TinyLlama and MicroLlama, I used acc_norm for most datasets except for winogrande and boolq which used acc as the metrics.
|
116 |
+
|
117 |
+
### Results Comparison
|
118 |
+
|
119 |
+
| Model | Params | Budget | HellaSwag | OBQA | WinoGrande | ARC_e | ARC_c | BoolQ | Avg |
|
120 |
+
|-------|--------|--------|-----------|------|------------|-------|-------|-------|-----|
|
121 |
+
| **rootxhacker/arthemis-lm** | **155.8M** | **<$50** | **24.65** | **20.60** | **48.10** | **28.20** | **22.20** | **39.80** | **30.59** |
|
122 |
+
| google/bert-large-uncased | 336M | N/A | 24.53 | 26.20 | 49.80 | 25.08 | 25.68 | 40.86 | 32.03 |
|
123 |
+
|
124 |
+
|
125 |
+
## Technical Specifications
|
126 |
+
|
127 |
+
```
|
128 |
+
Architecture: Llama + Spiking Neural Networks + Liquid Time Constants
|
129 |
+
Hidden Size: 768
|
130 |
+
Intermediate Size: 2048
|
131 |
+
Attention Heads: 12
|
132 |
+
Layers: 12
|
133 |
+
Max Position Embeddings: 1024
|
134 |
+
Vocabulary Size: 50,257
|
135 |
+
Spiking Threshold: 1.0
|
136 |
+
LTC Hidden Size: 256
|
137 |
+
Training Precision: FP32
|
138 |
+
Fine-tuning Dataset: Alpaca Cleaned (52K instructions)
|
139 |
+
```
|
140 |
+
|
141 |
+
## Training Details
|
142 |
+
|
143 |
+
The model was fine-tuned from rootxhacker/arthemis-lm using:
|
144 |
+
- **Base Model**: rootxhacker/arthemis-lm (pretrained neuromorphic LLM)
|
145 |
+
- **Dataset**: Alpaca Cleaned (~52K instruction-response pairs)
|
146 |
+
- **Hardware**: Google Colab Pro Plus (A100 GPU)
|
147 |
+
- **Training Steps**: 5,000 steps
|
148 |
+
- **Batch Size**: 4 with gradient accumulation
|
149 |
+
- **Learning Rate**: 5e-5 (lower for fine-tuning)
|
150 |
+
- **Precision**: FP32 for stability with neuromorphic components
|
151 |
+
|
152 |
+
### Key Features
|
153 |
+
- **Instruction Format**: Uses Alpaca's structured instruction format
|
154 |
+
- **Response Generation**: Optimized for helpful, accurate responses
|
155 |
+
- **Neuromorphic Preservation**: Maintains SNN/LTC benefits during fine-tuning
|
156 |
+
- **Budget-Conscious**: Additional fine-tuning cost under $10
|
157 |
+
|
158 |
+
## Fine-tuning Process
|
159 |
+
|
160 |
+
The fine-tuning process involved:
|
161 |
+
1. **Base Model Loading**: Started from the pretrained arthemis-lm checkpoint
|
162 |
+
2. **Data Formatting**: Converted Alpaca instructions to proper format
|
163 |
+
3. **Careful Training**: Lower learning rate to preserve base model knowledge
|
164 |
+
4. **State Management**: Proper handling of SNN/LTC states during training
|
165 |
+
5. **Validation**: Continuous monitoring of instruction-following quality
|
166 |
+
|
167 |
+
|
168 |
+
## Limitations
|
169 |
+
|
170 |
+
- **Training Data**: Limited to Alpaca Cleaned dataset scope
|
171 |
+
- **Context Length**: Maximum 1024 tokens
|
172 |
+
- **Domain**: Primarily English instructions
|
173 |
+
- **Custom Architecture**: Requires specialized loading code
|
174 |
+
- **Scale**: Smaller than commercial instruction models
|
175 |
+
|
176 |
+
## Model Sources
|
177 |
+
|
178 |
+
- **Repository**: [Coming Soon]
|
179 |
+
- **Base Model**: [rootxhacker/arthemis-lm](https://huggingface.co/rootxhacker/arthemis-lm)
|
180 |
+
- **Hugging Face**: [rootxhacker/arthemis-instruct](https://huggingface.co/rootxhacker/arthemis-instruct)
|
181 |
+
|
182 |
+
## Future Work
|
183 |
+
|
184 |
+
- Scale instruction dataset for broader capabilities
|
185 |
+
- Add multi-turn conversation support
|
186 |
+
- Implement reinforcement learning from human feedback (RLHF)
|
187 |
+
- Explore specialized instruction types (coding, math, reasoning)
|
188 |
+
- Compare instruction-following efficiency with standard transformers
|
189 |
+
|
190 |
+
## Acknowledgments
|
191 |
+
|
192 |
+
Special thanks to **keeeeenw** for the inspiration and open-source MicroLlama project, which demonstrated that impressive language models can be built on a budget. This work extends those principles to instruction-following capabilities while exploring neuromorphic computing approaches.
|
193 |
+
|
194 |
+
Thanks to the Stanford Alpaca team for the high-quality instruction dataset that made this fine-tuning possible.
|
195 |
+
|
196 |
+
## Citation
|
197 |
+
|
198 |
+
```bibtex
|
199 |
+
@misc{arthemis-instruct-2024,
|
200 |
+
title={Arthemis-Instruct: A Neuromorphic Instruction-Following Model with Spiking Neural Networks and Liquid Time Constants},
|
201 |
+
author={rootxhacker},
|
202 |
+
year={2024},
|
203 |
+
howpublished={\url{https://huggingface.co/rootxhacker/arthemis-instruct}}
|
204 |
+
}
|
205 |
+
```
|
206 |
+
|
207 |
+
## License
|
208 |
+
|
209 |
+
Apache License 2.0
|