xJoePec commited on
Commit
7cccd0c
·
verified ·
1 Parent(s): d0af44d

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +209 -0
README.md ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Galena-2B: Granite 3.3 Math & Physics Model
2
+
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
+ [![Model](https://img.shields.io/badge/Model-Granite%203.3--2B-green.svg)](https://huggingface.co/ibm-granite/granite-3.3-2b-instruct)
5
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
6
+
7
+ A specialized 2B parameter language model fine-tuned on advanced mathematics and physics datasets. Built on IBM's Granite 3.3-2B Instruct base model with LoRA fine-tuning on 26k instruction-response pairs covering advanced calculations and physics concepts.
8
+
9
+ ## Download Model Artifacts
10
+
11
+ The HF checkpoint and GGUF exports are hosted externally (e.g., Hugging Face) and
12
+ are **not** stored inside this repository. Fetch them before running the
13
+ examples:
14
+
15
+ ```bash
16
+ python scripts/download_artifacts.py --artifact all
17
+ ```
18
+
19
+ - `--source huggingface` (default) pulls from `xJoepec/galena-2b-math-physics`.
20
+ - `--source mirror --hf-url ... --gguf-url ...` lets you point to release assets/CDN downloads instead.
21
+
22
+ Artifacts install under `models/math-physics/{hf,gguf}` and are ignored by Git.
23
+
24
+ ## Quick Start
25
+
26
+ ### Using Hugging Face Transformers
27
+
28
+ ```python
29
+ from transformers import AutoModelForCausalLM, AutoTokenizer
30
+
31
+ # Load model and tokenizer
32
+ model = AutoModelForCausalLM.from_pretrained(
33
+ "models/math-physics/hf",
34
+ device_map="auto",
35
+ trust_remote_code=True
36
+ )
37
+ tokenizer = AutoTokenizer.from_pretrained("models/math-physics/hf")
38
+
39
+ # Generate response
40
+ prompt = "Explain the relationship between energy and momentum in special relativity."
41
+ messages = [{"role": "user", "content": prompt}]
42
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
43
+
44
+ outputs = model.generate(inputs, max_new_tokens=256, temperature=0.7)
45
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
46
+ print(response)
47
+ ```
48
+
49
+ ### Using llama.cpp (GGUF)
50
+
51
+ ```bash
52
+ # Requires llama.cpp build and downloaded GGUF artifact
53
+ ./llama.cpp/build/bin/llama-cli \
54
+ -m models/math-physics/gguf/granite-math-physics-f16.gguf \
55
+ -p "Calculate the escape velocity from Earth's surface." \
56
+ -n 256 \
57
+ --temp 0.7
58
+ ```
59
+
60
+ ## Model Details
61
+
62
+ - **Base Model**: [ibm-granite/granite-3.3-2b-instruct](https://huggingface.co/ibm-granite/granite-3.3-2b-instruct)
63
+ - **Parameters**: 2.0B
64
+ - **Architecture**: GraniteForCausalLM (40 layers, 2048 hidden size, 32 attention heads)
65
+ - **Context Length**: 131,072 tokens (128k)
66
+ - **Training Method**: QLoRA (4-bit quantization with Low-Rank Adaptation)
67
+ - **Fine-tuning Data**: 26k examples blending:
68
+ - **nvidia/Nemotron-RL-math-advanced_calculations** - Advanced calculator tasks with tool reasoning traces
69
+ - **camel-ai/physics** - Physics dialogue pairs with topic/subtopic metadata
70
+
71
+ ### Model Formats
72
+
73
+ | Format | Location (after download) | Size | Use Case |
74
+ |--------|---------------------------|------|----------|
75
+ | **Hugging Face** | `models/math-physics/hf/` | ~5.0 GB | PyTorch, Transformers, vLLM, further fine-tuning |
76
+ | **GGUF (F16)** | `models/math-physics/gguf/` | ~4.7 GB | llama.cpp, Ollama, LM Studio, on-device inference |
77
+
78
+ ## Installation
79
+
80
+ ### Prerequisites
81
+
82
+ - Python 3.10 or higher
83
+ - CUDA 12.1+ (for GPU acceleration)
84
+ - `huggingface_hub` (installed via `pip install -r requirements.txt`) for scripted downloads
85
+
86
+ ### For Transformers Usage
87
+
88
+ ```bash
89
+ # Clone repository
90
+ git clone <repository-url>
91
+ cd galena-2B
92
+
93
+ # Install dependencies
94
+ pip install -r requirements.txt
95
+
96
+ # Download artifacts (Hugging Face by default)
97
+ python scripts/download_artifacts.py --artifact hf
98
+ ```
99
+
100
+ ### For llama.cpp Usage
101
+
102
+ ```bash
103
+ # Clone llama.cpp (if not already available)
104
+ git clone https://github.com/ggerganov/llama.cpp.git
105
+ cd llama.cpp
106
+
107
+ # Build with CUDA support (Linux/WSL)
108
+ cmake -B build -DGGML_CUDA=ON
109
+ cmake --build build --config Release
110
+
111
+ # Run inference
112
+ python scripts/download_artifacts.py --artifact gguf
113
+ ./build/bin/llama-cli -m ../galena-2B/models/math-physics/gguf/granite-math-physics-f16.gguf
114
+ ```
115
+
116
+ ## Usage Examples
117
+
118
+ See the [`examples/`](examples/) directory for detailed usage demonstrations:
119
+
120
+ - **[basic_usage.py](examples/basic_usage.py)** - Simple model loading and inference
121
+ - **[chat_example.py](examples/chat_example.py)** - Interactive chat session
122
+ - **[llama_cpp_example.sh](examples/llama_cpp_example.sh)** - GGUF inference with llama.cpp
123
+
124
+ ## Training Details
125
+
126
+ The model was fine-tuned using the following configuration:
127
+
128
+ ```bash
129
+ # LoRA fine-tuning
130
+ python scripts/train_lora.py \
131
+ --base_model ibm-granite/granite-3.3-2b-instruct \
132
+ --dataset_path data/math_physics.jsonl \
133
+ --output_dir outputs/granite-math-physics-lora \
134
+ --use_4bit --gradient_checkpointing \
135
+ --per_device_train_batch_size 1 \
136
+ --gradient_accumulation_steps 4 \
137
+ --num_train_epochs 1 \
138
+ --max_steps 500 \
139
+ --batching_strategy padding \
140
+ --max_seq_length 512 \
141
+ --bf16 \
142
+ --trust_remote_code
143
+ ```
144
+
145
+ For detailed training methodology and dataset preparation, see [MODEL_CARD.md](MODEL_CARD.md).
146
+
147
+ ## Performance & Limitations
148
+
149
+ **Strengths:**
150
+ - Advanced mathematical calculations and reasoning
151
+ - Physics concepts and problem-solving
152
+ - Tool-augmented reasoning for complex calculations
153
+ - Efficient 2B parameter footprint suitable for edge deployment
154
+
155
+ **Limitations:**
156
+ - Specialized for math/physics; may underperform on general tasks
157
+ - 500-step fine-tune optimized for domain knowledge, not extensive generalization
158
+ - Inherits base model biases and constraints
159
+ - Best suited for educational and research applications
160
+
161
+ ## Citation
162
+
163
+ If you use this model in your research, please cite:
164
+
165
+ ```bibtex
166
+ @software{galena_2b_2024,
167
+ title = {Galena-2B: Granite 3.3 Math & Physics Model},
168
+ author = {Your Name},
169
+ year = {2024},
170
+ url = {https://github.com/yourusername/galena-2B},
171
+ note = {Fine-tuned from IBM Granite 3.3-2B Instruct}
172
+ }
173
+ ```
174
+
175
+ Also cite the base Granite model:
176
+
177
+ ```bibtex
178
+ @software{granite_3_3_2024,
179
+ title = {Granite 3.3: IBM's Open Foundation Models},
180
+ author = {IBM Research},
181
+ year = {2024},
182
+ url = {https://www.ibm.com/granite}
183
+ }
184
+ ```
185
+
186
+ ## License
187
+
188
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
189
+
190
+ The base Granite 3.3 model is also released under Apache 2.0 by IBM.
191
+
192
+ ## Acknowledgments
193
+
194
+ - **IBM Research** for the Granite 3.3 foundation models
195
+ - **NVIDIA** for the Nemotron-RL-math dataset
196
+ - **CAMEL-AI** for the physics dialogue dataset
197
+ - **Hugging Face** for the Transformers library and model hosting infrastructure
198
+ - **llama.cpp** project for efficient GGUF inference
199
+
200
+ ## Links
201
+
202
+ - [IBM Granite Models](https://www.ibm.com/granite)
203
+ - [Base Model: granite-3.3-2b-instruct](https://huggingface.co/ibm-granite/granite-3.3-2b-instruct)
204
+ - [Hugging Face Transformers](https://github.com/huggingface/transformers)
205
+ - [llama.cpp](https://github.com/ggerganov/llama.cpp)
206
+
207
+ ## Support
208
+
209
+ For issues, questions, or contributions, please open an issue in this repository's issue tracker.