commit debfe62c7ea5adc665eccc1a2f0d6a5f5a04ce5c Author: ModelHub XC Date: Sat Jul 18 17:18:11 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: Phonsiri/gemma-2-2b-SFT-Reasoning-full-Model Source: Original Platform diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..52373fe --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..aad3719 --- /dev/null +++ b/README.md @@ -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 | ` ... ` | Step-by-step internal reasoning | +| Final 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 and tags, " + "and your final answer within and 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 + +``` + +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 + + + +x = 5 + +``` + +--- + +## 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 \ No newline at end of file diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..e53868b --- /dev/null +++ b/chat_template.jinja @@ -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' %}user +{{ message['content'] }} +{% elif message['role'] == 'assistant' or message['role'] == 'model' %}model +{{ message['content'] }} +{% endif %}{% endfor %}{% if add_generation_prompt %}model +{% endif %} \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..fbc9028 --- /dev/null +++ b/config.json @@ -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 +} diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..45f4bab --- /dev/null +++ b/generation_config.json @@ -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" +} diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..aa77470 --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c703bebe930103b1599f177f6c5590be6a1a499261dc45f56ae8835236d8bc4c +size 5228717512 diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..6523cc0 --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:394ace002a144ac6ad5486387502f2d36f70c087310c3d907857240c76fcb36e +size 34362748 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..eabc4ed --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,19 @@ +{ + "backend": "tokenizers", + "bos_token": "", + "clean_up_tokenization_spaces": false, + "eos_token": "", + "extra_special_tokens": [ + "", + "" + ], + "is_local": false, + "mask_token": "", + "model_max_length": 1000000000000000019884624838656, + "pad_token": "", + "sp_model_kwargs": {}, + "spaces_between_special_tokens": false, + "tokenizer_class": "GemmaTokenizer", + "unk_token": "", + "use_default_system_prompt": false +} diff --git a/training_args.bin b/training_args.bin new file mode 100644 index 0000000..0104067 --- /dev/null +++ b/training_args.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:088831a3f7e709d1938b14f23bb852234559ecf3ba69ed3a9d78cc5e64def3c6 +size 5649