SalgrAI_v2.1 / README.md
salgr's picture
Upload 14 files
b87f745 verified
|
Raw History Blame Contribute Delete
10 kB
---
language:
- ru
license: gemma
base_model: google/gemma-3-270m-it
library_name: transformers
pipeline_tag: text-generation
tags:
- gemma3
- gguf
- safetensors
- tiny-model
- russian
- chat
- fine-tuned
- vocabulary-pruning
- model-soup
- salgrai
---
<!-- Before publishing: the license is dictated by the base model (Gemma Terms of Use). Read them and attach a copy, see UPLOAD.md. -->
# SalgrAI-v2.1
[Русская версия](README_RU.md)
**SalgrAI-v2.1 is the next update of SalgrAI-v2: Gemma 3 270M-it (131M parameters after vocabulary pruning) fine-tuned for short casual Russian chat that actually uses the earlier messages of the conversation.** Compared with v2 it is much more concise, can write and continue simple Python functions and remembers facts from the dialog. It is **not** better than v2 on every test (see Evaluation). Made by one person on a single RTX 3060. For experiments, demos and learning, **not** for serious use.
> **Please read the Limitations section.** Knowledge is weak, there is no safety filter beyond Gemma's own, and benchmark numbers of this small model are noisy.
## Model summary
| | |
|---|---|
| Base model | [google/gemma-3-270m-it](https://huggingface.co/google/gemma-3-270m-it), fine-tuned, vocabulary pruned |
| Architecture | Gemma 3, decoder-only: 18 layers, hidden 640, 4 heads (1 KV head), FFN 2048 |
| Parameters | **131,105,536** = 100,326,016 in the layers + 30,779,520 in the embedding table (48,093 tokens x 640) |
| Vocabulary | **48,093** tokens (original 262,144): Cyrillic, ASCII, punctuation, emoji, byte tokens, special tokens. It is not the same vocabulary as in SalgrAI-v2 (47,544) |
| Language | Russian (English only in fragments, weak) |
| Format | Gemma chat template: `<start_of_turn>user ... <end_of_turn><start_of_turn>model ...` |
| Developed by | Salgr |
| License | Gemma Terms of Use (see License) |
## Files
| File | Size | What it is |
|---|---|---|
| `model.safetensors` | 262 MB | weights, bfloat16 (loads with `transformers`) |
| `SalgrAI-v2.1-F16.gguf` | 263 MB | GGUF, float16, for llama.cpp |
| `SalgrAI-v2.1-Q8_0.gguf` | 141 MB | GGUF, 8-bit: recommended |
| `SalgrAI-v2.1-Q4_K_M.gguf` | 102 MB | GGUF, 4-bit: smallest, **not evaluated** |
| `config.json`, `generation_config.json` | | config and recommended sampling (temperature 0.5) |
| `tokenizer.json`, `tokenizer.model`, `tokenizer_config.json`, `special_tokens_map.json`, `chat_template.jinja` | | the pruned Gemma tokenizer and chat template |
| `chat_example.py` | | a minimal chat script that keeps the dialog history |
| `NOTICE` | | the notice required by the Gemma Terms of Use |
## Quick start
### Transformers
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "YOUR-USERNAME/SalgrAI-v2.1"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16)
messages = [{"role": "user", "content": "привет, меня зовут Артур"}]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True)
out = model.generate(**inputs) # sampling settings come from generation_config.json
print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
```
Use `bfloat16` or `float32`. **Do not run it in float16**: Gemma 3 is numerically unstable in fp16. To continue a conversation, append the model reply and the next user message to `messages` (`chat_example.py` does this and keeps the last 8 messages).
### llama.cpp (GGUF)
```bash
llama-server -m SalgrAI-v2.1-Q8_0.gguf -c 1024 --port 8080
curl http://127.0.0.1:8080/v1/chat/completions -d '{"messages": [{"role": "user", "content": "привет"}], "max_tokens": 80, "temperature": 0.5, "top_k": 40, "top_p": 0.9, "repeat_penalty": 1.1}'
```
The chat template is embedded in the file. In a raw `/completion` prompt do not write `<bos>`: llama.cpp adds it itself.
## What changed since v2
- **Data.** Two fine-tuning runs on 31,510 and 35,871 short dialogs (small groups repeated 2-4 times): casual chat, simple knowledge dialogs, Python basics ("what does this code print", "write a function", both programmatic and checked by execution), self-identification and **6,689 multi-turn dialogs in which the last answer is impossible without the earlier messages** (name, city, color, number, "and you?", continuing arithmetic or code, "repeat that"). Part of the dialogs was written by Claude Haiku (Anthropic) from a written specification, part is generated by scripts. The dialogs are not released.
- **Training.** Full fine-tuning in bf16 with the embedding table frozen, 3 epochs, loss on reply tokens only, best epoch by validation loss. The released weights are the **average of two such runs** (weight soup of run 1, epoch 2 and run 2, epoch 1); the decision to average was made before looking at benchmark results.
- **Leak filter.** Dialogs that repeat a benchmark prompt, share its key words and answer, or contain code snippets from SBKCB were removed (0 snippet matches in the final data; the first attempt had 6 and was discarded).
## Evaluation
All numbers are from our own local runs, **temperature 0**, repetition penalty 1.1, one message without history, unless noted. The benchmarks are small, so **a difference of 3-4 points is noise**: the same weights give 58 / 56 / 53 points on SBKCB in bf16 / F16 / Q8_0, and the two runs that were averaged scored 59 and 52.
**SBKCB V1.0** (150 questions: 90 knowledge, 20 Python, 40 conversation; https://salgr.top/freeopus/benchmarks/sbkcb):
| Model | Total (of 150) | Knowledge /90 | Code /20 | Conversation /40 |
|---|---|---|---|---|
| **SalgrAI-v2.1** (bf16) | **58** | 16 | 14 | 28 |
| SalgrAI-v2.1 (F16 GGUF) | 56 | 16 | 13 | 27 |
| SalgrAI-v2.1 (Q8_0 GGUF) | 53 | 15 | 12 | 26 |
| SalgrAI-v2 (Q8_0 GGUF) | 56 | 19 | 6 | 31 |
| Qwen2.5-Coder-0.5B-Instruct (not ours) | 59 | 18 | 19 | 22 |
| SalgrAI-v2-Pro-Full (Q8_0 GGUF) | 62 | 17 | 18 | 27 |
**In total v2.1 is on the level of v2 and below Qwen2.5-Coder and Pro-Full (within noise): it does not "beat" them.** What improved is code (12-14 of 20 against 5-6 for v2) and the behaviours below; knowledge did not improve (15-16 against 18-19, within noise).
**Use of the conversation history.** 300 dialogs in which the last reply depends on earlier messages (names, cities and numbers that are not in the training data; the test was written by us from the same task types as the training part, so it is *in-distribution*): **v2.1 288 of 300 (96%)**, v2 66 (22%), SalgrAI-v2-Pro-Full 112 (37%). The weakest types: "repeat that" (19 of 25) and continuing arithmetic (20 of 25).
**Conciseness.** On 300 prompts the mean reply length is **6.7 words** (v2: 11.6, Pro-Full: 6.6); replies longer than 25 words: 0% (v2: 4%).
**Where it is worse than v2.** On SBB V1.0, a small casual-chat benchmark (100 messages; the rules check keywords) v2.1 scores 74 (Q8_0) / 75 (bf16) against 79 / 82 for v2. The drop comes from "simple requests and advice" and "how are you": the replies are shorter and drier ("как подготовиться к экзамену?" - "удачи, ты справишься!") and the rules do not accept them. The benchmark is archived on the site and v2.1 is not listed there. Quality of the Q4_K_M file was not measured.
**About the code score.** The code questions of SBKCB are of the same *types* as part of the training data ("what does this code print", "write a function"), although the benchmark prompts and the code snippets from them were removed. Do not read the 12-14 of 20 as a general ability to program. The earlier models SalgrAI-v2-Pro-Full and SalgrAI-v2.1-Lite had a small leak of benchmark code snippets in their data (4 and up to 5 dialogs), which was found and fixed only for v2.1.
## Intended use, limitations and risks
- **Intended use:** hobby experiments, demos, studying how small language models behave, a small Russian chat baseline with a working short-term memory.
- **Not for:** advice, facts, calculations, moderation, anything where a wrong or rude answer matters.
- Factual knowledge is unreliable (capitals, authors and dates outside the training tables are often wrong); the model sounds fluent while often being wrong. Hard questions: 3 of 19 in SBKCB.
- It reads code better than it writes it: it writes short functions, but predicts the output of non-trivial code unreliably.
- The memory works within one short conversation (the training and test dialogs are short, 2-3 turns). Long dialogs were not tested.
- Russian only. English text is split into small fragments and understood poorly; other scripts are not supported.
- The model calls itself "SalgrAI" in Latin letters; this is by design.
- **No extra safety tuning.** The base model has Gemma's own alignment, which fine-tuning may have weakened. If you expose it publicly, add your own filtering.
- Not for float16 inference.
## SalgrAI family
| Model | Parameters | Notes |
|---|---|---|
| SalgrAI-v2-Lite / v2.1-Lite | 24,874,368 | from scratch, our own architecture |
| SalgrAI-v2-Full | 268,098,176 | Gemma 3 270M-it fine-tuned, full vocabulary |
| SalgrAI-v2 | 130,754,176 | v2-Full with pruned vocabulary |
| **SalgrAI-v2.1** | 131,105,536 | this model |
| SalgrAI-v2-Pro-Full | 494M | Qwen2.5-Coder-0.5B-Instruct fine-tuned |
Live demo: https://salgr.top/freeopus/ - benchmark page: https://salgr.top/freeopus/benchmarks
## License
This model is a **Model Derivative of Gemma** and is provided under the **Gemma Terms of Use** (https://gemma.ai/resources/terms). Whoever uses or redistributes it must follow those terms, including the Gemma Prohibited Use Policy (https://gemma.ai/resources/prohibited_use_policy), must receive a copy of the terms and must keep the `NOTICE` file. The weights and the tokenizer were modified (fine-tuning, vocabulary pruning and averaging of two checkpoints). Also consider the terms of the data used to generate the dialogs.