File size: 7,454 Bytes
fa69329 8beba87 fa69329 55f6f10 fa69329 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | ---
language:
- bg
- en
library_name: pytorch
tags:
- text-generation
- bulgarian
- causal-lm
- custom-architecture
- recurrent-depth
---
# Bulgarian GPT ~700M
A compact decoder-only language model designed for Bulgarian and English text generation, with a Bulgarian-extended GPT-2 tokenizer and optional gated recurrent depth in the middle transformer blocks.
This repository uses a custom PyTorch architecture. Use the included inference runner rather than `AutoModelForCausalLM` or a standard GPT-2 tokenizer.
## Quickstart
Clone this model repository
```bash
git clone https://huggingface.co/clecho52/NikeLLM
cd NikeLLM
pip install -r requirements.txt
```
Install a CUDA-enabled PyTorch build appropriate for your system if using an NVIDIA GPU. CPU inference is also supported. The first tokenizer initialization may download the standard GPT-2 encoding through tiktoken.
**Instruction / chat mode**
```bash
python inference.py --chat --prompt "Обясни накратко какво е машинно обучение." --max-new-tokens 128
```
**Raw text completion**
```bash
python inference.py --prompt "България е страна, която" --max-new-tokens 100
```
**Translation**
```bash
python inference.py --chat --prompt 'Преведи на английски: Днес времето е прекрасно.'
```
These are example inputs, not verified model outputs.
## Python API
```python
from inference import Generator
model = Generator('.', device='auto')
# Or Generator('YOUR_ORG/YOUR_MODEL', revision='COMMIT_SHA')
answer = model.generate(
'Защо небето е синьо?',
chat=True,
max_new_tokens=128,
temperature=0.7,
top_k=50,
top_p=0.95,
seed=42,
)
print(answer)
```
Multi-turn conversations can be passed explicitly:
```python
print(model.generate([
{'role': 'user', 'content': 'Какво е фотосинтеза?'},
{'role': 'assistant', 'content': 'Процес, при който растенията използват светлина.'},
{'role': 'user', 'content': 'А защо е важна?'}
], chat=True))
```
## Architecture
The following describes the supplied training script's defaults, not an independently inspected final checkpoint. The exported `config.json` contains the authoritative release settings.
| Property | Default |
|---|---:|
| Transformer blocks | 22 |
| Hidden dimension | 1,536 |
| Attention heads | 24 |
| Head dimension | 64 |
| SwiGLU intermediate dimension | 4,096 |
| Normalization | RMSNorm |
| Position encoding | RoPE (theta 10,000) |
| Training sequence length | 4,096 |
| Sliding attention window | 2,048 |
| Vocabulary | 50,257 + up to 8,192 Bulgarian subwords |
| EOS token ID | 50,256 |
| Input/output embeddings | Tied |
| Recurrent middle blocks | 9 (blocks 8–16, one-based) |
The middle section shares its weights across repeated passes. For nonzero extra passes, learned sigmoid gates interpolate between the input and output of each middle pass. `--middle-loops 0` executes each block once; `1` executes the middle section twice, for 31 total block executions with the default architecture. Values 2 and 3 execute 40 and 49 blocks respectively. These are execution counts, not additional parameters. By default inference reproduces the checkpoint's fixed depth, or the training sampler's evaluation depth for variable-depth checkpoints. Overriding it may affect quality.
The tokenizer preserves GPT-2 IDs, greedily matches Bulgarian subwords, and splits ASCII digits individually. The exact ordered added vocabulary and its fingerprint are stored in `tokenizer_info.json`. Do not replace it with an ordinary GPT-2 or Llama tokenizer.
## Prompt format
The default instruction format is:
```text
### User
Какво е изкуствен интелект?
### Assistant
```
An optional `### System` section can precede the user message. The runner encodes headers and content separately to match the training pipeline, inserts the assistant header automatically, and stops on EOS or a new role header in chat mode. Raw completion does not insert headers.
## Generation settings
| Argument | Default | Description |
|---|---|---|
| `--max-new-tokens` | 128 | Maximum generated tokens |
| `--temperature` | 0.7 | Set to 0 for greedy decoding |
| `--top-k` | 50 | Set to 0 to disable |
| `--top-p` | 0.95 | Set to 1 to disable |
| `--middle-loops` | Checkpoint-derived | Extra middle passes (0–3) |
| `--device` | auto | CUDA if available, otherwise CPU |
| `--dtype` | auto | BF16/FP16 on CUDA, FP32 on CPU |
| `--seed` | unset | Optional sampling seed |
The implementation recomputes the context at every step (no KV cache), truncating to the most recent configured context length. It is a reference implementation, not a high-throughput serving engine. A roughly 700M-parameter model requires about 1.4 GB of weight storage in BF16 and 2.8 GB in FP32, excluding runtime memory and loading overhead. Actual requirements vary with context and hardware.
## Training approach and data
The training implementation supports a mixture of ordinary causal cross-entropy and assistant-token-supervised examples. The default source configuration includes FineWeb, FineWeb-Edu, Bulgarian Corpus 33B, UltraChat 200K, Bulgarian Aya, FineMath, Python educational code, Bulgarian/English FineWiki and bidirectional subtitle translation. Aya uses balanced shuffled task decks across dialogue, event linking, generation, paraphrase identification, question answering, summarization and simplification. Custom source configurations can override these defaults.
The actual dataset revisions, token count, training duration, checkpoint metrics and final training mixture have not been independently verified for this release. No benchmark or safety evaluation results are claimed here.
## Limitations
This model may produce inaccurate, repetitive, biased or unsafe text; translation and instruction following can be inconsistent. It is not designed for high-stakes decisions or factual verification without independent checks. Longer contexts or untrained recurrent depths may degrade performance. Review generated content before use.
## Maintainer: export a training checkpoint
Only the original training checkpoint is needed; training dependencies and optimizer states are not needed at inference time.
```bash
pip install -r requirements.txt
python export.py /path/to/runs/gpt700m/latest.pt --out . --dtype bfloat16
python inference.py --chat --prompt "Здравей!" --temperature 0 --max-new-tokens 32
```
Use `--dtype float32` (the default) to avoid reducing checkpoint weight precision. The exporter uses restricted PyTorch loading and writes only model tensors in SafeTensors format, plus the actual architecture, loop settings and tokenizer metadata. Older checkpoints missing extended-tokenizer metadata must have the original metadata recovered before export.
Upload these files together: `README.md`, `model.py`, `inference.py`, `requirements.txt`, `config.json`, `tokenizer_info.json`, `model.safetensors`. `export.py` and `smoke_test.py` may also be included. Do not upload the full optimizer checkpoint unless intentionally releasing training state.
Before publishing, replace the example repository identifier, document the actual training data and evaluation results, and choose a license after reviewing model and dataset rights. No license is asserted by this draft.
|