Text Generation
Transformers
Safetensors
PEFT
English
qwen2
from-
custom-architecture
custom-tokenizer
reasoning
chain-of-thought
think-tags
coding
fine-tuned
lora
unsloth
astragpt
tantra-ai-labs
rtx-4090
conversational
text-generation-inference
Instructions to use adityawakharkar/AstraGPTCoder-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use adityawakharkar/AstraGPTCoder-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="adityawakharkar/AstraGPTCoder-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("adityawakharkar/AstraGPTCoder-7B") model = AutoModelForCausalLM.from_pretrained("adityawakharkar/AstraGPTCoder-7B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - PEFT
How to use adityawakharkar/AstraGPTCoder-7B with PEFT:
Task type is invalid.
- Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use adityawakharkar/AstraGPTCoder-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "adityawakharkar/AstraGPTCoder-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "adityawakharkar/AstraGPTCoder-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/adityawakharkar/AstraGPTCoder-7B
- SGLang
How to use adityawakharkar/AstraGPTCoder-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "adityawakharkar/AstraGPTCoder-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "adityawakharkar/AstraGPTCoder-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "adityawakharkar/AstraGPTCoder-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "adityawakharkar/AstraGPTCoder-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use adityawakharkar/AstraGPTCoder-7B with Docker Model Runner:
docker model run hf.co/adityawakharkar/AstraGPTCoder-7B
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,384 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
library_name: transformers
|
| 3 |
-
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
<
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
<
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- **Developed by:** [More Information Needed]
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
-
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
-
### Direct Use
|
| 41 |
-
|
| 42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
-
|
| 70 |
-
## How to Get Started with the Model
|
| 71 |
-
|
| 72 |
-
Use the code below to get started with the model.
|
| 73 |
-
|
| 74 |
-
[More Information Needed]
|
| 75 |
-
|
| 76 |
-
## Training Details
|
| 77 |
-
|
| 78 |
-
### Training Data
|
| 79 |
-
|
| 80 |
-
<!-- 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. -->
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
|
| 84 |
-
##
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
|
| 114 |
|
| 115 |
-
##
|
| 116 |
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
|
|
|
| 134 |
|
| 135 |
-
##
|
| 136 |
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
|
| 141 |
## Environmental Impact
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
|
| 183 |
-
##
|
| 184 |
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
-
|
| 188 |
|
| 189 |
-
##
|
| 190 |
|
| 191 |
-
[
|
| 192 |
|
| 193 |
-
##
|
| 194 |
|
| 195 |
-
|
|
|
|
| 196 |
|
| 197 |
-
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
tags:
|
| 7 |
+
- from-scratch
|
| 8 |
+
- custom-architecture
|
| 9 |
+
- custom-tokenizer
|
| 10 |
+
- reasoning
|
| 11 |
+
- chain-of-thought
|
| 12 |
+
- think-tags
|
| 13 |
+
- coding
|
| 14 |
+
- fine-tuned
|
| 15 |
+
- lora
|
| 16 |
+
- peft
|
| 17 |
+
- unsloth
|
| 18 |
+
- astragpt
|
| 19 |
+
- tantra-ai-labs
|
| 20 |
+
- rtx-4090
|
| 21 |
+
pipeline_tag: text-generation
|
| 22 |
library_name: transformers
|
| 23 |
+
model_creator: Tantra AI Labs
|
| 24 |
---
|
| 25 |
|
| 26 |
+
# AstraGPT-7B π
|
| 27 |
|
| 28 |
+
<div align="center">
|
| 29 |
|
| 30 |
+
**A 7-Billion Parameter Language Model β Built From Scratch**
|
| 31 |
|
| 32 |
+
*Custom Architecture Β· Custom BPE Tokenizer Β· Reasoning Fine-Tuned on Dual RTX 4090*
|
| 33 |
|
| 34 |
+
[](https://opensource.org/licenses/Apache-2.0)
|
| 35 |
+
[](https://huggingface.co/adityawakharkar/AstraGPT-7B)
|
| 36 |
+
[]()
|
| 37 |
+
[](https://www.nvidia.com)
|
| 38 |
+
[](https://github.com/codewith-aditya)
|
| 39 |
|
| 40 |
+
Built by **Aditya Wakharkar** | [Tantra AI Labs](https://github.com/codewith-aditya)
|
| 41 |
|
| 42 |
+
</div>
|
| 43 |
|
| 44 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
## π§ What is AstraGPT-7B?
|
| 47 |
|
| 48 |
+
AstraGPT-7B is a **7-billion parameter decoder-only language model** designed for coding and chain-of-thought reasoning.
|
| 49 |
|
| 50 |
+
Unlike most open-source fine-tunes, **every core component of AstraGPT was designed and implemented from scratch in PyTorch** β including the transformer architecture, the BPE tokenizer, and the supervised fine-tuning pipeline.
|
| 51 |
|
| 52 |
+
The model was then **fine-tuned on a reasoning dataset** using LoRA on a **private VPS equipped with dual NVIDIA RTX 4090 GPUs**, giving it native support for `<think>...</think>` style reasoning output.
|
| 53 |
|
| 54 |
+
> *"Most people fine-tune models. We built one."*
|
| 55 |
|
| 56 |
+
---
|
| 57 |
|
| 58 |
+
## ποΈ Built From Scratch β Architecture Overview
|
| 59 |
+
|
| 60 |
+
Every layer of AstraGPT-7B was implemented from first principles in PyTorch. No `AutoModel`, no copy-paste β pure custom code.
|
| 61 |
+
|
| 62 |
+
```
|
| 63 |
+
Input Token IDs
|
| 64 |
+
β
|
| 65 |
+
βΌ
|
| 66 |
+
Token Embedding [64,000 β 4,096]
|
| 67 |
+
β
|
| 68 |
+
βΌ Γ32 Transformer Blocks
|
| 69 |
+
βββββββββββββββββββββββββββββββββββββββ
|
| 70 |
+
β AstraGPT Block β
|
| 71 |
+
β β
|
| 72 |
+
β RMSNorm (Pre-norm) β
|
| 73 |
+
β β Grouped Query Attention (GQA) β
|
| 74 |
+
β Β· 32 Query Heads β
|
| 75 |
+
β Β· 8 Key-Value Heads β
|
| 76 |
+
β Β· RoPE (ΞΈ = 1,000,000) β
|
| 77 |
+
β Β· KV Cache for inference β
|
| 78 |
+
β β Residual Add β
|
| 79 |
+
β β
|
| 80 |
+
β RMSNorm (Pre-norm) β
|
| 81 |
+
β β SwiGLU Feed-Forward Network β
|
| 82 |
+
β Β· gate_proj, up_proj, down_proj β
|
| 83 |
+
β Β· intermediate_size = 11,008 β
|
| 84 |
+
β β Residual Add β
|
| 85 |
+
βββββββββββββββββββββββββββββββββββββββ
|
| 86 |
+
β
|
| 87 |
+
βΌ
|
| 88 |
+
Final RMSNorm
|
| 89 |
+
β
|
| 90 |
+
βΌ
|
| 91 |
+
LM Head [4,096 β 64,000]
|
| 92 |
+
β
|
| 93 |
+
βΌ
|
| 94 |
+
Logits β Next Token
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
### Architecture Highlights
|
| 98 |
+
|
| 99 |
+
| Component | Implementation | Why |
|
| 100 |
+
|-----------|---------------|-----|
|
| 101 |
+
| **Grouped Query Attention (GQA)** | 32Q / 8KV heads β built from scratch | 4Γ less KV memory vs MHA. Same used in LLaMA-3, Mistral |
|
| 102 |
+
| **Rotary Position Embeddings (RoPE)** | Full RoPE math from scratch, ΞΈ=1M | Better long-context vs learned embeddings |
|
| 103 |
+
| **SwiGLU FFN** | gate Γ SiLU(up) through down_proj | Outperforms GELU/ReLU on LM benchmarks |
|
| 104 |
+
| **RMSNorm** | Pre-norm, no bias, no mean subtraction | ~30% faster than LayerNorm |
|
| 105 |
+
| **Flash Attention** | PyTorch 2.0 `scaled_dot_product_attention` | Memory-efficient attention with O(n) space |
|
| 106 |
+
|
| 107 |
+
### Parameter Count (~7B)
|
| 108 |
+
|
| 109 |
+
| Component | Parameters |
|
| 110 |
+
|-----------|-----------|
|
| 111 |
+
| Token Embedding (64K Γ 4096) | ~262M |
|
| 112 |
+
| Attention Γ 32 layers | ~2.15B |
|
| 113 |
+
| SwiGLU FFN Γ 32 layers | ~4.32B |
|
| 114 |
+
| RMSNorm Γ 65 | ~267K |
|
| 115 |
+
| LM Head | ~262M |
|
| 116 |
+
| **Total** | **~7.0B** |
|
| 117 |
|
| 118 |
+
---
|
| 119 |
|
| 120 |
+
## π€ Custom BPE Tokenizer β From Scratch
|
| 121 |
|
| 122 |
+
AstraGPT uses a **custom Byte Pair Encoding tokenizer** built entirely from scratch β no SentencePiece, no HuggingFace tokenizers library.
|
| 123 |
|
| 124 |
+
```python
|
| 125 |
+
# Built from scratch
|
| 126 |
+
from tokenizer import BPETokenizer
|
| 127 |
|
| 128 |
+
tok = BPETokenizer(vocab_size=64_000)
|
| 129 |
+
tok.train(open("corpus.txt"), num_merges=60_000)
|
| 130 |
+
```
|
| 131 |
|
| 132 |
+
**Tokenizer features:**
|
| 133 |
+
- **Byte-level base vocabulary** β 256 raw bytes, handles any Unicode
|
| 134 |
+
- **GPT-4 style pre-tokenization regex** β smart word boundary splitting
|
| 135 |
+
- **64,000 vocab size** β 60K BPE merges on top of byte base
|
| 136 |
+
- **Built-in special tokens:** `<think>`, `</think>`, `<|im_start|>`, `<|im_end|>`, BOS, EOS, PAD
|
| 137 |
+
- **`apply_chat_template()`** β custom chat format support
|
| 138 |
+
- **Save/load** β JSON-serializable merge rules
|
| 139 |
|
| 140 |
+
---
|
| 141 |
|
| 142 |
+
## β‘ Training β Dual RTX 4090 on Private VPS
|
| 143 |
+
|
| 144 |
+
Fine-tuning was performed on a **private Linux VPS with 2Γ NVIDIA RTX 4090 GPUs** (total 48GB VRAM).
|
| 145 |
+
|
| 146 |
+
### Hardware Setup
|
| 147 |
+
|
| 148 |
+
| Spec | Value |
|
| 149 |
+
|------|-------|
|
| 150 |
+
| GPUs | **2Γ NVIDIA RTX 4090** (24GB VRAM each) |
|
| 151 |
+
| Total VRAM | **48 GB** |
|
| 152 |
+
| CPU | High-core count server CPU |
|
| 153 |
+
| Infrastructure | Private VPS (bare metal) |
|
| 154 |
+
| OS | Ubuntu 22.04 LTS |
|
| 155 |
+
| CUDA | 12.x |
|
| 156 |
+
|
| 157 |
+
### Training Pipeline β Also Built From Scratch
|
| 158 |
+
|
| 159 |
+
The SFT (Supervised Fine-Tuning) training loop was implemented from scratch with production-grade features:
|
| 160 |
+
|
| 161 |
+
```python
|
| 162 |
+
# Full custom training loop
|
| 163 |
+
trainer = SFTTrainer(
|
| 164 |
+
model=model,
|
| 165 |
+
tokenizer=tokenizer,
|
| 166 |
+
dataset=dataset,
|
| 167 |
+
# Dual GPU via DDP
|
| 168 |
+
use_bf16=True,
|
| 169 |
+
grad_accumulation=8,
|
| 170 |
+
learning_rate=2e-4,
|
| 171 |
+
use_wandb=True,
|
| 172 |
+
)
|
| 173 |
+
trainer.train()
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
**Training loop features:**
|
| 177 |
+
- β
**Gradient accumulation** β effective large batch training
|
| 178 |
+
- β
**Mixed precision (BF16)** β full RTX 4090 tensor core utilization
|
| 179 |
+
- β
**Cosine LR schedule with warmup** β smooth convergence
|
| 180 |
+
- β
**Gradient clipping** β stable training
|
| 181 |
+
- β
**W&B logging** β real-time loss/LR tracking
|
| 182 |
+
- β
**Checkpoint saving** β best model tracking by loss
|
| 183 |
+
|
| 184 |
+
### Fine-Tuning Hyperparameters
|
| 185 |
+
|
| 186 |
+
| Parameter | Value |
|
| 187 |
+
|-----------|-------|
|
| 188 |
+
| Method | LoRA (PEFT) via Unsloth |
|
| 189 |
+
| LoRA Rank | 16 |
|
| 190 |
+
| LoRA Alpha | 32 |
|
| 191 |
+
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
| 192 |
+
| Max Sequence Length | 2,048 tokens |
|
| 193 |
+
| Effective Batch Size | 16 (2 Γ grad_accum 8) |
|
| 194 |
+
| Learning Rate | 2e-4 |
|
| 195 |
+
| LR Scheduler | Cosine with warmup |
|
| 196 |
+
| Warmup Ratio | 5% |
|
| 197 |
+
| Epochs | 3 |
|
| 198 |
+
| Precision | BF16 mixed precision |
|
| 199 |
+
| Optimizer | AdamW 8-bit |
|
| 200 |
+
|
| 201 |
+
### Post-Training
|
| 202 |
+
|
| 203 |
+
After fine-tuning, the LoRA adapter was **merged back into base model weights** β resulting in a single, self-contained model with no external adapter dependency.
|
| 204 |
|
| 205 |
+
---
|
| 206 |
|
| 207 |
+
## π€ Thinking / Reasoning Support
|
| 208 |
|
| 209 |
+
AstraGPT-7B natively generates `<think>` tag reasoning when triggered. This was trained in via the fine-tuning dataset, which used structured chain-of-thought formatting.
|
| 210 |
|
| 211 |
+
**Example:**
|
| 212 |
|
| 213 |
+
**Input:**
|
| 214 |
+
```
|
| 215 |
+
What is 15 * 47?
|
| 216 |
+
```
|
| 217 |
|
| 218 |
+
**Output:**
|
| 219 |
+
```
|
| 220 |
+
<think>
|
| 221 |
+
The multiplication involves multiplying 15 by 47.
|
| 222 |
+
15 Γ 47 = 15 Γ 40 + 15 Γ 7
|
| 223 |
+
= 600 + 105
|
| 224 |
+
= 705
|
| 225 |
+
</think>
|
| 226 |
+
705
|
| 227 |
+
```
|
| 228 |
|
| 229 |
+
**Trigger thinking mode:**
|
| 230 |
+
```python
|
| 231 |
+
# Append this to your prompt to force reasoning
|
| 232 |
+
prompt = tokenizer.apply_chat_template(messages, ...) + "<think>\n"
|
| 233 |
+
```
|
| 234 |
|
| 235 |
+
---
|
| 236 |
|
| 237 |
+
## β‘ Quick Start
|
| 238 |
+
|
| 239 |
+
### Install
|
| 240 |
+
|
| 241 |
+
```bash
|
| 242 |
+
pip install transformers torch bitsandbytes accelerate
|
| 243 |
+
```
|
| 244 |
+
|
| 245 |
+
### Basic Inference
|
| 246 |
+
|
| 247 |
+
```python
|
| 248 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 249 |
+
import torch
|
| 250 |
+
|
| 251 |
+
model_id = "adityawakharkar/AstraGPT-7B"
|
| 252 |
+
|
| 253 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 254 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 255 |
+
model_id,
|
| 256 |
+
torch_dtype=torch.float16,
|
| 257 |
+
device_map="auto"
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
messages = [
|
| 261 |
+
{
|
| 262 |
+
"role": "system",
|
| 263 |
+
"content": "You are AstraGPT, a helpful coding AI built by Tantra AI Labs. Think carefully using <think>...</think> tags before answering."
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"role": "user",
|
| 267 |
+
"content": "Write a Python function to reverse a linked list."
|
| 268 |
+
}
|
| 269 |
+
]
|
| 270 |
+
|
| 271 |
+
prompt = tokenizer.apply_chat_template(
|
| 272 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 273 |
+
) + "<think>\n" # β triggers reasoning
|
| 274 |
+
|
| 275 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 276 |
+
|
| 277 |
+
with torch.no_grad():
|
| 278 |
+
output = model.generate(
|
| 279 |
+
**inputs,
|
| 280 |
+
max_new_tokens=1024,
|
| 281 |
+
temperature=0.3,
|
| 282 |
+
do_sample=True,
|
| 283 |
+
repetition_penalty=1.1,
|
| 284 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
response = tokenizer.decode(
|
| 288 |
+
output[0][inputs["input_ids"].shape[1]:],
|
| 289 |
+
skip_special_tokens=True
|
| 290 |
+
)
|
| 291 |
+
print(response)
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
### 4-bit Quantized (Runs on ~6GB VRAM)
|
| 295 |
+
|
| 296 |
+
```python
|
| 297 |
+
from transformers import BitsAndBytesConfig
|
| 298 |
+
|
| 299 |
+
bnb = BitsAndBytesConfig(
|
| 300 |
+
load_in_4bit=True,
|
| 301 |
+
bnb_4bit_quant_type="nf4",
|
| 302 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 303 |
+
bnb_4bit_use_double_quant=True,
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 307 |
+
"adityawakharkar/AstraGPT-7B",
|
| 308 |
+
quantization_config=bnb,
|
| 309 |
+
device_map="auto"
|
| 310 |
+
)
|
| 311 |
+
```
|
| 312 |
|
| 313 |
+
---
|
| 314 |
|
| 315 |
+
## π Codebase
|
| 316 |
+
|
| 317 |
+
The full from-scratch implementation is open-source:
|
| 318 |
+
|
| 319 |
+
```
|
| 320 |
+
AstraGPT-7B-scratch/
|
| 321 |
+
βββ model/
|
| 322 |
+
β βββ config.py β AstraGPTConfig (7B hyperparams, 1B/3B presets)
|
| 323 |
+
β βββ rotary_embedding.py β RoPE from scratch (precompute + apply)
|
| 324 |
+
β βββ attention.py β GQA from scratch (32Q / 8KV + KV cache)
|
| 325 |
+
β βββ feedforward.py β SwiGLU + RMSNorm + TransformerBlock
|
| 326 |
+
β βββ transformer.py β Full model + generate() + save/load
|
| 327 |
+
βββ tokenizer/
|
| 328 |
+
β βββ bpe_tokenizer.py β Full BPE tokenizer (train, encode, decode)
|
| 329 |
+
β βββ train_tokenizer.py β Train on any text corpus
|
| 330 |
+
βββ training/
|
| 331 |
+
βββ sft_trainer.py β Complete SFT loop (grad accum, bf16, cosine LR)
|
| 332 |
+
```
|
| 333 |
|
| 334 |
+
---
|
| 335 |
|
| 336 |
+
## Bias, Risks, and Limitations
|
| 337 |
|
| 338 |
+
- **Hallucination:** Can produce confident but incorrect answers β always verify
|
| 339 |
+
- **Math limits:** Complex multi-step math may fail β 7B is a small model
|
| 340 |
+
- **English-primary:** Best performance in English
|
| 341 |
+
- **Reasoning trigger:** `<think>` tags work most reliably with explicit `<think>\n` prefix in prompt
|
| 342 |
|
| 343 |
+
---
|
| 344 |
|
| 345 |
## Environmental Impact
|
| 346 |
|
| 347 |
+
- **Hardware:** 2Γ NVIDIA RTX 4090 (48GB combined VRAM)
|
| 348 |
+
- **Infrastructure:** Private bare-metal VPS
|
| 349 |
+
- **Training Duration:** ~3β4 hours
|
| 350 |
+
- **Carbon Emitted:** Estimated ~2β3 kgCO2eq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
|
| 354 |
+
## Citation
|
| 355 |
|
| 356 |
+
```bibtex
|
| 357 |
+
@misc{astragpt7b2026,
|
| 358 |
+
author = {Aditya Wakharkar},
|
| 359 |
+
title = {AstraGPT-7B: A 7B LLM Built From Scratch with Chain-of-Thought Reasoning},
|
| 360 |
+
year = {2026},
|
| 361 |
+
publisher = {HuggingFace},
|
| 362 |
+
organization = {Tantra AI Labs},
|
| 363 |
+
url = {https://huggingface.co/adityawakharkar/AstraGPT-7B},
|
| 364 |
+
note = {Custom architecture, custom BPE tokenizer, trained on 2Γ RTX 4090}
|
| 365 |
+
}
|
| 366 |
+
```
|
| 367 |
|
| 368 |
+
---
|
| 369 |
|
| 370 |
+
## Model Card Authors
|
| 371 |
|
| 372 |
+
**Aditya Wakharkar** β [@adityawakharkar](https://huggingface.co/adityawakharkar) | [GitHub @codewith-aditya](https://github.com/codewith-aditya)
|
| 373 |
|
| 374 |
+
## Contact
|
| 375 |
|
| 376 |
+
- π GitHub: [github.com/codewith-aditya](https://github.com/codewith-aditya)
|
| 377 |
+
- π€ HuggingFace: [@adityawakharkar](https://huggingface.co/adityawakharkar)
|
| 378 |
|
| 379 |
+
---
|
| 380 |
|
| 381 |
+
<div align="center">
|
| 382 |
+
<em>Built from scratch with β€οΈ by <strong>Tantra AI Labs</strong></em><br/>
|
| 383 |
+
<em>Every layer. Every weight. Every line of code.</em>
|
| 384 |
+
</div>
|