初始化项目,由ModelHub XC社区提供模型

Model: Phonsiri/gemma-2-2b-SFT-Reasoning-full-Model
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-07-18 17:18:11 +08:00
commit debfe62c7e
9 changed files with 295 additions and 0 deletions

36
.gitattributes vendored Normal file
View File

@@ -0,0 +1,36 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
tokenizer.json filter=lfs diff=lfs merge=lfs -text

150
README.md Normal file
View File

@@ -0,0 +1,150 @@
---
base_model: google/gemma-2-2b
library_name: transformers
tags:
- math
- reasoning
- sft
- gemma
datasets:
- nohurry/Opus-4.6-Reasoning-3000x-filtered
language:
- en
- th
license: gemma
---
# Gemma-2-2B SFT Reasoning Model
A supervised fine-tuned version of [`google/gemma-2-2b`](https://huggingface.co/google/gemma-2-2b), trained to produce structured chain-of-thought reasoning on mathematical and logical problems.
> **Model Lineage:** This SFT model serves as the foundation for downstream training:
> [**Phonsiri/gemma-2-2b-GRPO-Reasoning-full**](https://huggingface.co/Phonsiri/gemma-2-2b-GRPO-Reasoning-full)
---
## Model Highlights
This model was trained to explicitly separate its reasoning process from its final answer, using a structured output format. It learns the **syntax and structure** of chain-of-thought reasoning before any reinforcement signal is applied.
**Output Format:**
| Section | Tag | Description |
|---|---|---|
| Chain-of-Thought | `<reasoning> ... </reasoning>` | Step-by-step internal reasoning |
| Final Answer | `<answer> ... </answer>` | Concise final answer |
---
## Training Details
### Base Model
Fine-tuned from [`google/gemma-2-2b-it`](https://huggingface.co/google/gemma-2-2b-it) using full parameter fine-tuning (no LoRA/PEFT).
### Datasets
Training data was combined from the following sources:
| Dataset | Type |
|---|---|
| [`nohurry/Opus-4.6-Reasoning-3000x-filtered`](https://huggingface.co/datasets/nohurry/Opus-4.6-Reasoning-3000x-filtered) | HuggingFace — Reasoning |
| `math_combined_2566_2567.json` | Local — Thai math problems |
| `problems_1_5.json` | Local — Math problems |
| `problems_6_10.json` | Local — Math problems |
| `problems_101_125.json` | Local — Math problems |
| `combined.json` | Local — Combined problems |
| `all_solutions.json` | Local — Solutions |
### Hyperparameters
| Parameter | Value |
|---|---|
| Epochs | 3 |
| Learning Rate | 2e-5 |
| LR Scheduler | Cosine |
| Max Seq Length | 8192 |
| Batch Size (per device) | 4 |
| Gradient Accumulation | 4 |
| Effective Batch Size | 16 |
| Warmup Ratio | 0.1 |
| Weight Decay | 0.01 |
| Precision | bfloat16 |
| Gradient Checkpointing | Yes |
| Attention | SDPA |
| Optimizer | AdamW |
---
## Usage
```python
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
import torch
model_id = "Phonsiri/gemma-2-2b-SFT-Reasoning-full-Model"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.bfloat16
)
system_prompt = (
"You are a helpful assistant. Please reason step by step, "
"and put your thoughts within <reasoning> and </reasoning> tags, "
"and your final answer within <answer> and </answer> tags."
)
prompt = "Solve for x: 3x + 5 = 20"
messages = [{"role": "user", "content": f"{system_prompt}\n\n{prompt}"}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=False)
with torch.no_grad():
model.generate(
**inputs,
streamer=streamer,
max_new_tokens=4096,
temperature=0.6,
top_p=0.9,
repetition_penalty=1.1,
)
```
### Example Output
```
<reasoning>
We need to isolate x on one side of the equation.
Step 1: Subtract 5 from both sides.
3x + 5 - 5 = 20 - 5
3x = 15
Step 2: Divide both sides by 3.
x = 15 / 3
x = 5
</reasoning>
<answer>
x = 5
</answer>
```
---
## Acknowledgements
**Authors:**
- **Phonsiri Thabunsri** — [@Phonsiriwillbejommarn](https://github.com/Phonsiriwillbejommarn)
- **CYP777** — [@CYP777](https://github.com/CYP777)
**Project Advisor:**
- **Supaporn Bunrit, Ph.D.** — Suranaree University of Technology
**Institutions & Credits:**
- **Suranaree University of Technology (SUT)** — Research support and computing resources
- **Google DeepMind** — Open-weights Gemma 2 model

6
chat_template.jinja Normal file
View File

@@ -0,0 +1,6 @@
{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}<start_of_turn>user
{{ message['content'] }}<end_of_turn>
{% elif message['role'] == 'assistant' or message['role'] == 'model' %}<start_of_turn>model
{{ message['content'] }}<end_of_turn>
{% endif %}{% endfor %}{% if add_generation_prompt %}<start_of_turn>model
{% endif %}

65
config.json Normal file
View File

@@ -0,0 +1,65 @@
{
"architectures": [
"Gemma2ForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"attn_logit_softcapping": 50.0,
"bos_token_id": 2,
"cache_implementation": "hybrid",
"dtype": "bfloat16",
"eos_token_id": 1,
"final_logit_softcapping": 30.0,
"head_dim": 256,
"hidden_act": "gelu_pytorch_tanh",
"hidden_activation": "gelu_pytorch_tanh",
"hidden_size": 2304,
"initializer_range": 0.02,
"intermediate_size": 9216,
"layer_types": [
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"full_attention"
],
"max_position_embeddings": 8192,
"model_type": "gemma2",
"num_attention_heads": 8,
"num_hidden_layers": 26,
"num_key_value_heads": 4,
"pad_token_id": 0,
"query_pre_attn_scalar": 256,
"rms_norm_eps": 1e-06,
"rope_parameters": {
"rope_theta": 10000.0,
"rope_type": "default"
},
"sliding_window": 4096,
"tie_word_embeddings": true,
"transformers_version": "5.2.0",
"use_bidirectional_attention": null,
"use_cache": false,
"vocab_size": 256000
}

10
generation_config.json Normal file
View File

@@ -0,0 +1,10 @@
{
"_from_model_config": true,
"bos_token_id": 2,
"cache_implementation": "hybrid",
"eos_token_id": [
1
],
"pad_token_id": 0,
"transformers_version": "5.2.0"
}

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c703bebe930103b1599f177f6c5590be6a1a499261dc45f56ae8835236d8bc4c
size 5228717512

3
tokenizer.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:394ace002a144ac6ad5486387502f2d36f70c087310c3d907857240c76fcb36e
size 34362748

19
tokenizer_config.json Normal file
View File

@@ -0,0 +1,19 @@
{
"backend": "tokenizers",
"bos_token": "<bos>",
"clean_up_tokenization_spaces": false,
"eos_token": "<eos>",
"extra_special_tokens": [
"<start_of_turn>",
"<end_of_turn>"
],
"is_local": false,
"mask_token": "<mask>",
"model_max_length": 1000000000000000019884624838656,
"pad_token": "<pad>",
"sp_model_kwargs": {},
"spaces_between_special_tokens": false,
"tokenizer_class": "GemmaTokenizer",
"unk_token": "<unk>",
"use_default_system_prompt": false
}

3
training_args.bin Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:088831a3f7e709d1938b14f23bb852234559ecf3ba69ed3a9d78cc5e64def3c6
size 5649