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

Model: NotoriousH2/gemma-3-1b-it-Math-SFT
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-07-04 17:54:15 +08:00
commit b9dd455e0f
13 changed files with 51838 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

140
README.md Normal file
View File

@@ -0,0 +1,140 @@
---
language: ko
license: apache-2.0
base_model: google/gemma-3-1b-it
tags:
- math
- korean
- sft
- gemma
- distillation
datasets:
- NotoriousH2/HRM8K
---
# Gemma-3-1B-IT Math SFT
`google/gemma-3-1b-it`를 한국어 수학 문제(GSM8K)에 대해 교사 증류 SFT한 모델.
## 성능
| Benchmark | Score |
|-----------|-------|
| HRM8K eval GSM8K (264문제, Korean) | **~44.9%** (3회 평균) |
| HRM8K eval MATH (577문제, Korean) | ~17% |
평가: temperature=0, vLLM 서빙, max_tokens=2048
## 데이터 생성 파이프라인
### 원본 데이터
- **GSM8K train set**: 영어 초등 수학 7,473문제 ([openai/gsm8k](https://huggingface.co/datasets/openai/gsm8k))
- **평가 데이터**: [HRM8K](https://huggingface.co/datasets/NotoriousH2/HRM8K) eval set 841문제 (GSM8K 264 + MATH 577, 한국어)
### 교사 모델
- **모델**: (AWQ 4bit)
- **서빙**: vLLM 0.11.0 (구버전 필요, AWQ 호환),
- **중요**: 이 교사 모델은 HRM8K 학습 데이터를 생성한 바로 그 모델. 다른 교사 모델(Qwen3.5-9B/35B 등)은 스타일 불일치로 -10%p 이상 성능 하락.
### 2단계 데이터 생성
### 최종 학습 데이터 형식
- 총 26,254개 (train 95% / eval 5% split)
- 시스템 프롬프트:
## 학습 설정
## 재현 방법
INFO 03-19 14:51:58 [__init__.py:216] Automatically detected platform cuda.
(APIServer pid=3426235) INFO 03-19 14:52:04 [api_server.py:1839] vLLM API server version 0.11.0
(APIServer pid=3426235) INFO 03-19 14:52:04 [utils.py:233] non-default args: {'model_tag': 'cpatonn/Qwen3-30B-A3B-Instruct-2507-AWQ-4bit', 'port': 8001, 'model': 'cpatonn/Qwen3-30B-A3B-Instruct-2507-AWQ-4bit', 'max_model_len': 4096, 'gpu_memory_utilization': 0.8}
(APIServer pid=3426235) INFO 03-19 14:52:06 [model.py:547] Resolved architecture: Qwen3MoeForCausalLM
(APIServer pid=3426235) INFO 03-19 14:52:06 [model.py:1510] Using max model len 4096
(APIServer pid=3426235) INFO 03-19 14:52:07 [scheduler.py:205] Chunked prefill is enabled with max_num_batched_tokens=8192.
INFO 03-19 14:52:19 [__init__.py:216] Automatically detected platform cuda.
(EngineCore_DP0 pid=3426796) INFO 03-19 14:52:25 [core.py:644] Waiting for init message from front-end.
(EngineCore_DP0 pid=3426796) INFO 03-19 14:52:25 [core.py:77] Initializing a V1 LLM engine (v0.11.0) with config: model='cpatonn/Qwen3-30B-A3B-Instruct-2507-AWQ-4bit', speculative_config=None, tokenizer='cpatonn/Qwen3-30B-A3B-Instruct-2507-AWQ-4bit', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, tokenizer_revision=None, trust_remote_code=False, dtype=torch.bfloat16, max_seq_len=4096, download_dir=None, load_format=auto, tensor_parallel_size=1, pipeline_parallel_size=1, data_parallel_size=1, disable_custom_all_reduce=False, quantization=compressed-tensors, enforce_eager=False, kv_cache_dtype=auto, device_config=cuda, structured_outputs_config=StructuredOutputsConfig(backend='auto', disable_fallback=False, disable_any_whitespace=False, disable_additional_properties=False, reasoning_parser=''), observability_config=ObservabilityConfig(show_hidden_metrics_for_version=None, otlp_traces_endpoint=None, collect_detailed_traces=None), seed=0, served_model_name=cpatonn/Qwen3-30B-A3B-Instruct-2507-AWQ-4bit, enable_prefix_caching=True, chunked_prefill_enabled=True, pooler_config=None, compilation_config={"level":3,"debug_dump_path":"","cache_dir":"","backend":"","custom_ops":[],"splitting_ops":["vllm.unified_attention","vllm.unified_attention_with_output","vllm.mamba_mixer2","vllm.mamba_mixer","vllm.short_conv","vllm.linear_attention","vllm.plamo2_mamba_mixer","vllm.gdn_attention","vllm.sparse_attn_indexer"],"use_inductor":true,"compile_sizes":[],"inductor_compile_config":{"enable_auto_functionalized_v2":false},"inductor_passes":{},"cudagraph_mode":[2,1],"use_cudagraph":true,"cudagraph_num_of_warmups":1,"cudagraph_capture_sizes":[512,504,496,488,480,472,464,456,448,440,432,424,416,408,400,392,384,376,368,360,352,344,336,328,320,312,304,296,288,280,272,264,256,248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,4,2,1],"cudagraph_copy_inputs":false,"full_cuda_graph":false,"use_inductor_graph_partition":false,"pass_config":{},"max_capture_size":512,"local_cache_dir":null}
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
(EngineCore_DP0 pid=3426796) INFO 03-19 14:52:26 [parallel_state.py:1208] rank 0 in world size 1 is assigned as DP rank 0, PP rank 0, TP rank 0, EP rank 0
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] EngineCore failed to start.
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] Traceback (most recent call last):
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/v1/engine/core.py", line 699, in run_engine_core
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] engine_core = EngineCoreProc(*args, **kwargs)
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/v1/engine/core.py", line 498, in __init__
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] super().__init__(vllm_config, executor_class, log_stats,
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/v1/engine/core.py", line 83, in __init__
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] self.model_executor = executor_class(vllm_config)
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/executor/executor_base.py", line 54, in __init__
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] self._init_executor()
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/executor/uniproc_executor.py", line 54, in _init_executor
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] self.collective_rpc("init_device")
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/executor/uniproc_executor.py", line 83, in collective_rpc
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] return [run_method(self.driver_worker, method, args, kwargs)]
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/utils/__init__.py", line 3122, in run_method
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] return func(*args, **kwargs)
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/worker/worker_base.py", line 259, in init_device
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] self.worker.init_device() # type: ignore
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/v1/worker/gpu_worker.py", line 187, in init_device
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] raise ValueError(
(EngineCore_DP0 pid=3426796) ERROR 03-19 14:52:26 [core.py:708] ValueError: Free memory on device (7.29/93.1 GiB) on startup is less than desired GPU memory utilization (0.8, 74.48 GiB). Decrease GPU memory utilization or reduce GPU memory used by other processes.
INFO 03-19 14:52:34 [__init__.py:216] Automatically detected platform cuda.
(APIServer pid=3427292) INFO 03-19 14:52:40 [api_server.py:1839] vLLM API server version 0.11.0
(APIServer pid=3427292) INFO 03-19 14:52:40 [utils.py:233] non-default args: {'model_tag': './outputs/models/c17d-gemma-3-1b-it-Math', 'model': './outputs/models/c17d-gemma-3-1b-it-Math', 'dtype': 'bfloat16', 'max_model_len': 4096, 'gpu_memory_utilization': 0.85}
(APIServer pid=3427292) INFO 03-19 14:52:51 [model.py:547] Resolved architecture: Gemma3ForCausalLM
(APIServer pid=3427292) INFO 03-19 14:52:51 [model.py:1510] Using max model len 4096
(APIServer pid=3427292) INFO 03-19 14:52:51 [scheduler.py:205] Chunked prefill is enabled with max_num_batched_tokens=8192.
INFO 03-19 14:52:58 [__init__.py:216] Automatically detected platform cuda.
(EngineCore_DP0 pid=3428117) INFO 03-19 14:53:03 [core.py:644] Waiting for init message from front-end.
(EngineCore_DP0 pid=3428117) INFO 03-19 14:53:03 [core.py:77] Initializing a V1 LLM engine (v0.11.0) with config: model='./outputs/models/c17d-gemma-3-1b-it-Math', speculative_config=None, tokenizer='./outputs/models/c17d-gemma-3-1b-it-Math', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, tokenizer_revision=None, trust_remote_code=False, dtype=torch.bfloat16, max_seq_len=4096, download_dir=None, load_format=auto, tensor_parallel_size=1, pipeline_parallel_size=1, data_parallel_size=1, disable_custom_all_reduce=False, quantization=None, enforce_eager=False, kv_cache_dtype=auto, device_config=cuda, structured_outputs_config=StructuredOutputsConfig(backend='auto', disable_fallback=False, disable_any_whitespace=False, disable_additional_properties=False, reasoning_parser=''), observability_config=ObservabilityConfig(show_hidden_metrics_for_version=None, otlp_traces_endpoint=None, collect_detailed_traces=None), seed=0, served_model_name=./outputs/models/c17d-gemma-3-1b-it-Math, enable_prefix_caching=True, chunked_prefill_enabled=True, pooler_config=None, compilation_config={"level":3,"debug_dump_path":"","cache_dir":"","backend":"","custom_ops":[],"splitting_ops":["vllm.unified_attention","vllm.unified_attention_with_output","vllm.mamba_mixer2","vllm.mamba_mixer","vllm.short_conv","vllm.linear_attention","vllm.plamo2_mamba_mixer","vllm.gdn_attention","vllm.sparse_attn_indexer"],"use_inductor":true,"compile_sizes":[],"inductor_compile_config":{"enable_auto_functionalized_v2":false},"inductor_passes":{},"cudagraph_mode":[2,1],"use_cudagraph":true,"cudagraph_num_of_warmups":1,"cudagraph_capture_sizes":[512,504,496,488,480,472,464,456,448,440,432,424,416,408,400,392,384,376,368,360,352,344,336,328,320,312,304,296,288,280,272,264,256,248,240,232,224,216,208,200,192,184,176,168,160,152,144,136,128,120,112,104,96,88,80,72,64,56,48,40,32,24,16,8,4,2,1],"cudagraph_copy_inputs":false,"full_cuda_graph":false,"use_inductor_graph_partition":false,"pass_config":{},"max_capture_size":512,"local_cache_dir":null}
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
[Gloo] Rank 0 is connected to 0 peer ranks. Expected number of connected peer ranks is : 0
(EngineCore_DP0 pid=3428117) INFO 03-19 14:53:05 [parallel_state.py:1208] rank 0 in world size 1 is assigned as DP rank 0, PP rank 0, TP rank 0, EP rank 0
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] EngineCore failed to start.
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] Traceback (most recent call last):
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/v1/engine/core.py", line 699, in run_engine_core
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] engine_core = EngineCoreProc(*args, **kwargs)
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/v1/engine/core.py", line 498, in __init__
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] super().__init__(vllm_config, executor_class, log_stats,
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/v1/engine/core.py", line 83, in __init__
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] self.model_executor = executor_class(vllm_config)
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/executor/executor_base.py", line 54, in __init__
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] self._init_executor()
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/executor/uniproc_executor.py", line 54, in _init_executor
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] self.collective_rpc("init_device")
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/executor/uniproc_executor.py", line 83, in collective_rpc
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] return [run_method(self.driver_worker, method, args, kwargs)]
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/utils/__init__.py", line 3122, in run_method
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] return func(*args, **kwargs)
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/worker/worker_base.py", line 259, in init_device
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] self.worker.init_device() # type: ignore
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] ^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] File "/tmp/.venv/lib/python3.12/site-packages/vllm/v1/worker/gpu_worker.py", line 187, in init_device
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] raise ValueError(
(EngineCore_DP0 pid=3428117) ERROR 03-19 14:53:05 [core.py:708] ValueError: Free memory on device (7.29/93.1 GiB) on startup is less than desired GPU memory utilization (0.85, 79.13 GiB). Decrease GPU memory utilization or reduce GPU memory used by other processes.
## 파일
- : SFT 학습 스크립트
- : HRM8K 평가 스크립트 (vLLM OpenAI API 호환 서버 필요)

3
added_tokens.json Normal file
View File

@@ -0,0 +1,3 @@
{
"<image_soft_token>": 262144
}

47
chat_template.jinja Normal file
View File

@@ -0,0 +1,47 @@
{{ bos_token }}
{%- if messages[0]['role'] == 'system' -%}
{%- if messages[0]['content'] is string -%}
{%- set first_user_prefix = messages[0]['content'] + '
' -%}
{%- else -%}
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '
' -%}
{%- endif -%}
{%- set loop_messages = messages[1:] -%}
{%- else -%}
{%- set first_user_prefix = "" -%}
{%- set loop_messages = messages -%}
{%- endif -%}
{%- for message in loop_messages -%}
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
{%- endif -%}
{%- if (message['role'] == 'assistant') -%}
{%- set role = "model" -%}
{%- else -%}
{%- set role = message['role'] -%}
{%- endif -%}
{{ '<start_of_turn>' + role + '
' + (first_user_prefix if loop.first else "") }}
{%- if message['content'] is string -%}
{{ message['content'] | trim }}
{%- elif message['content'] is iterable -%}
{%- for item in message['content'] -%}
{%- if item['type'] == 'image' -%}
{{ '<start_of_image>' }}
{%- elif item['type'] == 'text' -%}
{{ item['text'] | trim }}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{{ raise_exception("Invalid content type") }}
{%- endif -%}
{{ '<end_of_turn>
' }}
{%- endfor -%}
{%- if add_generation_prompt -%}
{{'<start_of_turn>model
'}}
{%- endif -%}

64
config.json Normal file
View File

@@ -0,0 +1,64 @@
{
"_sliding_window_pattern": 6,
"architectures": [
"Gemma3ForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"attn_logit_softcapping": null,
"bos_token_id": 2,
"cache_implementation": "hybrid",
"dtype": "bfloat16",
"eos_token_id": 1,
"final_logit_softcapping": null,
"head_dim": 256,
"hidden_activation": "gelu_pytorch_tanh",
"hidden_size": 1152,
"initializer_range": 0.02,
"intermediate_size": 6912,
"layer_types": [
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"sliding_attention",
"full_attention",
"sliding_attention",
"sliding_attention"
],
"max_position_embeddings": 32768,
"model_type": "gemma3_text",
"num_attention_heads": 4,
"num_hidden_layers": 26,
"num_key_value_heads": 1,
"pad_token_id": 1,
"query_pre_attn_scalar": 256,
"rms_norm_eps": 1e-06,
"rope_local_base_freq": 10000,
"rope_scaling": null,
"rope_theta": 1000000,
"sliding_window": 512,
"sliding_window_pattern": 6,
"transformers_version": "4.57.3",
"use_bidirectional_attention": false,
"use_cache": false,
"vocab_size": 262144
}

86
eval.py Normal file
View File

@@ -0,0 +1,86 @@
"""공통 평가 스크립트: vLLM 서버에 연결하여 HRM8K 전체 841문제 평가 (temperature=0)"""
import os, json, re, sys, asyncio
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from openai import OpenAI
MATH_SYSTEM_PROMPT = """주어진 수학 문제를 단계별로 풀고 답변을 작성하세요.
반드시 최종 답변을 \\boxed{정수} 형식으로 마지막 줄에 출력하세요.
예시: \\boxed{42}"""
def extract_boxed(text):
m = re.findall(r'\\boxed\{([^}]+)\}', text)
return m[-1].strip() if m else None
def normalize(a):
if a is None: return None
s = str(a).replace(",","").replace(" ","").strip()
try:
n = float(s)
return str(int(n)) if n == int(n) else str(n)
except: return s
def check(pred, gt):
p, g = normalize(pred), normalize(gt)
return p is not None and g is not None and p == g
async def evaluate(label="", save_path=None):
client = OpenAI(base_url="http://localhost:8000/v1", api_key="token-abc123")
model_name = client.models.list().data[0].id
print(f"모델: {model_name}")
with open("data/HRM8k_eval.json") as f:
data = json.load(f)
print(f"평가: {len(data)}개 (temperature=0, max_tokens=2048)")
llm = ChatOpenAI(base_url="http://localhost:8000/v1", api_key="token-abc123",
model=model_name, temperature=0, max_tokens=2048)
prompt = ChatPromptTemplate([("user", "{sp}\n\n{q}")]).partial(sp=MATH_SYSTEM_PROMPT)
chain = prompt | llm | StrOutputParser()
inputs = [{"q": item["question"]} for item in data]
results = await chain.abatch(inputs, config={"max_concurrency": 400})
by_src = {}
details = []
for item, res in zip(data, results):
s = item.get("source", "?")
if s not in by_src: by_src[s] = {"correct": 0, "total": 0, "no_boxed": 0}
by_src[s]["total"] += 1
pred = extract_boxed(res)
is_correct = False
if pred is None:
by_src[s]["no_boxed"] += 1
elif check(pred, item["answer"]):
by_src[s]["correct"] += 1
is_correct = True
details.append({
"question": item["question"][:80],
"source": s,
"gt": str(item["answer"])[-30:] if isinstance(item["answer"], str) else str(item["answer"]),
"pred": pred,
"correct": is_correct,
})
tc = sum(v["correct"] for v in by_src.values())
tt = sum(v["total"] for v in by_src.values())
print(f"\n=== {label} 결과 (temperature=0) ===")
for s in sorted(by_src):
v = by_src[s]
print(f" [{s.upper()}] {v['correct']}/{v['total']} ({v['correct']/v['total']*100:.1f}%) | boxed미출력: {v['no_boxed']}")
print(f" [전체] {tc}/{tt} ({tc/tt*100:.1f}%)")
result_obj = {"label": label, "correct": tc, "total": tt, "accuracy": tc/tt*100, "by_source": by_src}
if save_path:
os.makedirs(os.path.dirname(save_path) or ".", exist_ok=True)
with open(save_path, "w") as f:
json.dump({"result": result_obj, "details": details}, f, ensure_ascii=False, indent=2)
print(f" 결과 저장: {save_path}")
return result_obj
if __name__ == "__main__":
label = sys.argv[1] if len(sys.argv) > 1 else "eval"
save_path = sys.argv[2] if len(sys.argv) > 2 else None
asyncio.run(evaluate(label, save_path))

14
generation_config.json Normal file
View File

@@ -0,0 +1,14 @@
{
"bos_token_id": 2,
"cache_implementation": "hybrid",
"do_sample": true,
"eos_token_id": [
1,
1,
106
],
"pad_token_id": 1,
"top_k": 64,
"top_p": 0.95,
"transformers_version": "4.57.3"
}

3
pytorch_model.bin Normal file
View File

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

27
special_tokens_map.json Normal file
View File

@@ -0,0 +1,27 @@
{
"boi_token": "<start_of_image>",
"bos_token": {
"content": "<bos>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"eoi_token": "<end_of_image>",
"eos_token": {
"content": "<eos>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"image_token": "<image_soft_token>",
"pad_token": "<eos>",
"unk_token": {
"content": "<unk>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}

3
tokenizer.json Normal file
View File

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

3
tokenizer.model Normal file
View File

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

51345
tokenizer_config.json Normal file

File diff suppressed because it is too large Load Diff

67
train_sft.py Normal file
View File

@@ -0,0 +1,67 @@
"""C17d: 모든 풀이 + 길이 필터 (1500자 이하만) + NaN 방지"""
import json, re, random, torch, numpy as np, os
from collections import defaultdict
from transformers import AutoModelForCausalLM, AutoTokenizer
from trl import SFTTrainer, SFTConfig
from transformers import EarlyStoppingCallback
from datasets import Dataset
SEED = 42
random.seed(SEED); np.random.seed(SEED); torch.manual_seed(SEED)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(SEED)
if torch.cuda.get_device_capability()[0] >= 8: torch.set_float32_matmul_precision('high')
SP = "주어진 수학 문제를 단계별로 풀고 답변을 작성하세요.\n반드시 최종 답변을 \\boxed{정수} 형식으로 마지막 줄에 출력하세요.\n예시: \\boxed{42}"
print("=== C17d: All solutions, length-filtered (≤1500 chars) ===")
with open("data/GSM8K_full_qwen3_30b.json") as f:
data = json.load(f)
# 길이 필터: 1500자 이하만
filtered = [d for d in data if len(d['answer']) <= 1500]
print(f"원본: {len(data)}개 → 필터 후: {len(filtered)}개 (제거: {len(data)-len(filtered)})")
random.shuffle(filtered)
uq = len(set(d["question"] for d in filtered))
print(f"Unique: {uq}, avg {len(filtered)/uq:.1f}/q")
split = int(len(filtered) * 0.95)
train, test = filtered[:split], filtered[split:]
def to_sft(ex):
return {"prompt": [{"role":"user","content":SP+"\n\n"+ex["question"]}],
"completion": [{"role":"assistant","content":ex["answer"]}]}
cols = [c for c in Dataset.from_list(train[:1]).column_names if c not in ["prompt","completion"]]
train_ds = Dataset.from_list(train).map(to_sft, remove_columns=cols)
test_ds = Dataset.from_list(test).map(to_sft, remove_columns=cols)
print(f"학습: {len(train_ds)} / 검증: {len(test_ds)}")
tokenizer = AutoTokenizer.from_pretrained("outputs/models/gemma-3-1b-it")
model = AutoModelForCausalLM.from_pretrained("outputs/models/gemma-3-1b-it", dtype=torch.bfloat16, device_map="auto", attn_implementation='flash_attention_2')
tokenizer.pad_token = tokenizer.eos_token
model.gradient_checkpointing_enable(); model.config.use_cache = False
cfg = SFTConfig(
report_to='none', seed=SEED, eval_strategy="steps", eval_steps=200,
save_total_limit=2, load_best_model_at_end=True, metric_for_best_model="eval_loss",
save_steps=200, num_train_epochs=3, warmup_ratio=0.05, weight_decay=0.01, max_grad_norm=1.0,
neftune_noise_alpha=5, per_device_train_batch_size=8, gradient_accumulation_steps=4,
per_device_eval_batch_size=2, max_length=2048, lr_scheduler_type='cosine',
learning_rate=2e-5, bf16=True, optim="paged_adamw_8bit",
output_dir="outputs/c17d_checkpoints", logging_steps=50, save_strategy="steps",
)
trainer = SFTTrainer(model=model, processing_class=tokenizer, train_dataset=train_ds, eval_dataset=test_ds, args=cfg,
callbacks=[EarlyStoppingCallback(early_stopping_patience=3)])
print("학습 시작 (3 epochs, 모든 풀이, ≤1500자)")
r = trainer.train()
print(f"완료! Loss: {r.training_loss:.4f}")
SAVE = "outputs/models/c17d-gemma-3-1b-it-Math"
os.makedirs(SAVE, exist_ok=True)
model.eval(); model.save_pretrained(SAVE, safe_serialization=False); tokenizer.save_pretrained(SAVE)
print(f"저장: {SAVE}")
del model, trainer; torch.cuda.empty_cache()
print("GPU 해제")