From fc7b38187d1712f8e7989773727cfc98aa49e55c Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Tue, 7 Jul 2026 19:47:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=8C=E7=94=B1ModelHub=20XC=E7=A4=BE=E5=8C=BA=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Model: cs-552-2026-centralesupechec/general_knowledge_model Source: Original Platform --- .gitattributes | 36 ++++++++++++++ README.md | 104 +++++++++++++++++++++++++++++++++++++++++ chat_template.jinja | 29 ++++++++++++ config.json | 63 +++++++++++++++++++++++++ generation_config.json | 10 ++++ model.safetensors | 3 ++ tokenizer.json | 3 ++ tokenizer_config.json | 31 ++++++++++++ 8 files changed, 279 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 chat_template.jinja create mode 100644 config.json create mode 100644 generation_config.json create mode 100644 model.safetensors create mode 100644 tokenizer.json create mode 100644 tokenizer_config.json 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..af4b0f6 --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +--- +library_name: transformers +license: apache-2.0 +base_model: Qwen/Qwen3-1.7B +pipeline_tag: text-generation +model_name: general_knowledge_model +tags: + - general-knowledge + - multiple-choice + - reasoning + - rejection-sampling + - rft + - lora + - cs-552 +--- + +# Model Card for `general_knowledge_model` + +Post-trained version of [`Qwen/Qwen3-1.7B`](https://huggingface.co/Qwen/Qwen3-1.7B) +for the **General Knowledge** benchmark of EPFL **CS-552 — Modern NLP** (Spring 2026), +team CentraleSupéchec. + +The task is **closed-book multiple-choice QA** (2–20 options). The model reasons +inside a ` ... ` block and ends its reply with the answer wrapped in +`\boxed{LETTER}`, which is parsed for `pass@1` scoring. + +## Training + +The model is trained with **Rejection Fine-Tuning (RFT)** — STaR-style +self-distillation — with an **answer-only loss**: + +1. Sample `n=8` completions (`T=0.7`) from the base model over a ~4.7k-question + pool of **GPQA** and **MMLU-Pro** (excluding Math/CS). +2. Keep the 722 questions the base fails at `pass@1` but solves under repeated + sampling, producing self-generated correct reasoning traces. +3. Fine-tune a **LoRA** adapter (`r=16`, `α=32`) with the cross-entropy loss + **masked to the `\boxed{}` answer span only** — the `` reasoning + conditions the forward pass but receives no gradient. This preserves the + model's pretrained reasoning while sharpening answer commitment and output + formatting. + +The chat template (baked into the tokenizer) enforces a strict `\boxed{LETTER}` +output and a 16,384-token reasoning budget. + +## Quick start + +```python +from transformers import AutoModelForCausalLM, AutoTokenizer + +repo = "cs-552-2026-centralesupechec/general_knowledge_model" +tok = AutoTokenizer.from_pretrained(repo) +model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype="bfloat16", device_map="cuda") + +question = ( + "Which of the following is the capital of Australia?\n\n" + "Choices:\nA. Sydney\nB. Melbourne\nC. Canberra\nD. Perth" +) +inputs = tok.apply_chat_template( + [{"role": "user", "content": question}], + add_generation_prompt=True, return_tensors="pt", +).to(model.device) + +out = model.generate(inputs, max_new_tokens=16384, temperature=0.6, top_p=0.95, top_k=20) +print(tok.decode(out[0][inputs.shape[1]:], skip_special_tokens=True)) +# ... reasoning ... \boxed{C} +``` + +For vLLM, mirror the CI: apply the model's chat template, `seed=42`, +`max_new_tokens=16384`, `temperature=0.6`, `top_p=0.95`, `top_k=20`. + +## Generation config + +`max_new_tokens: 16384` · `temperature: 0.6` · `top_p: 0.95` · `top_k: 20` · +`do_sample: true`. The 16k budget is essential: it removes the format failures +that occur when reasoning is truncated before the boxed answer. + +## Evaluation + +`pass@1` on held-out sets disjoint from training (n=4, 16k tokens): + +| Set | pass@1 | +|---|---| +| 650-question MMLU sweep (26 subjects) | ~0.74 | +| Internal 100-question expert set | ~0.59 | + +See the project report and code for the full comparison against the base model, +full-trace SFT, and GRPO. + +## Framework versions + +- Transformers 5.7.0 +- PyTorch 2.10.0+cu128 +- TRL 0.12, PEFT 0.13 + +## Citation + +```bibtex +@inproceedings{zelikman2022star, + title = {{STaR}: Bootstrapping Reasoning With Reasoning}, + author = {Zelikman, Eric and Wu, Yuhuai and Mu, Jesse and Goodman, Noah D.}, + booktitle = {Advances in Neural Information Processing Systems}, + year = {2022} +} +``` diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..70dc5e8 --- /dev/null +++ b/chat_template.jinja @@ -0,0 +1,29 @@ +{#- + General Knowledge — thinking-enabled chat template for Qwen3-1.7B. + Allows the model to emit a ... reasoning block first, then + the final \boxed{LETTER} answer. + + The CI calls: + tokenizer.apply_chat_template(messages, add_generation_prompt=True) + with no extra kwargs, so any behaviour we want must be encoded here. +-#} +{%- set gk_system = "You are a knowledge expert. Read the question and the labelled options carefully. Reason step by step inside ... , then choose exactly one option. End your reply with the letter of the correct option wrapped in \\boxed{}, e.g. \\boxed{C}. Do not output anything after the boxed answer." -%} + +{%- if messages[0].role == 'system' -%} + {{- '<|im_start|>system\n' + messages[0].content + '\n\n' + gk_system + '<|im_end|>\n' -}} + {%- set messages = messages[1:] -%} +{%- else -%} + {{- '<|im_start|>system\n' + gk_system + '<|im_end|>\n' -}} +{%- endif -%} + +{%- for message in messages -%} + {%- if message.role == 'user' -%} + {{- '<|im_start|>user\n' + message.content + '<|im_end|>\n' -}} + {%- elif message.role == 'assistant' -%} + {{- '<|im_start|>assistant\n' + message.content + '<|im_end|>\n' -}} + {%- endif -%} +{%- endfor -%} + +{%- if add_generation_prompt -%} + {{- '<|im_start|>assistant\n\n' -}} +{%- endif -%} diff --git a/config.json b/config.json new file mode 100644 index 0000000..c1ff45d --- /dev/null +++ b/config.json @@ -0,0 +1,63 @@ +{ + "architectures": [ + "Qwen3ForCausalLM" + ], + "attention_bias": false, + "attention_dropout": 0.0, + "bos_token_id": 151643, + "dtype": "bfloat16", + "eos_token_id": 151645, + "head_dim": 128, + "hidden_act": "silu", + "hidden_size": 2048, + "initializer_range": 0.02, + "intermediate_size": 6144, + "layer_types": [ + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention", + "full_attention" + ], + "max_position_embeddings": 40960, + "max_window_layers": 28, + "model_type": "qwen3", + "num_attention_heads": 16, + "num_hidden_layers": 28, + "num_key_value_heads": 8, + "pad_token_id": null, + "rms_norm_eps": 1e-06, + "rope_parameters": { + "rope_theta": 1000000, + "rope_type": "default" + }, + "sliding_window": null, + "tie_word_embeddings": true, + "transformers_version": "5.7.0", + "use_cache": true, + "use_sliding_window": false, + "vocab_size": 151936 +} diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..4ceeb70 --- /dev/null +++ b/generation_config.json @@ -0,0 +1,10 @@ +{ + "do_sample": true, + "eos_token_id": 151645, + "max_new_tokens": 16384, + "pad_token_id": 151643, + "temperature": 0.6, + "top_k": 20, + "top_p": 0.95, + "transformers_version": "5.7.0" +} diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..24a7146 --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ab3886a57655baad8bb2bc6f25efc47cbf66f0dfd613d85c699c0f079605d0b +size 3441185608 diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..c7afbed --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506 +size 11422650 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..2527e40 --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,31 @@ +{ + "add_prefix_space": false, + "backend": "tokenizers", + "bos_token": null, + "clean_up_tokenization_spaces": false, + "eos_token": "<|im_end|>", + "errors": "replace", + "extra_special_tokens": [ + "<|im_start|>", + "<|im_end|>", + "<|object_ref_start|>", + "<|object_ref_end|>", + "<|box_start|>", + "<|box_end|>", + "<|quad_start|>", + "<|quad_end|>", + "<|vision_start|>", + "<|vision_end|>", + "<|vision_pad|>", + "<|image_pad|>", + "<|video_pad|>" + ], + "is_local": true, + "local_files_only": false, + "model_max_length": 131072, + "pad_token": "<|endoftext|>", + "split_special_tokens": false, + "tokenizer_class": "Qwen2Tokenizer", + "unk_token": null, + "chat_template": "{#-\n General Knowledge — thinking-enabled chat template for Qwen3-1.7B.\n Allows the model to emit a ... reasoning block first, then\n the final \\boxed{LETTER} answer.\n The CI calls:\n tokenizer.apply_chat_template(messages, add_generation_prompt=True)\n with no extra kwargs, so any behaviour we want must be encoded here.\n-#}\n{%- set gk_system = \"You are a knowledge expert. Read the question and the labelled options carefully. Reason step by step inside ... , then choose exactly one option. End your reply with the letter of the correct option wrapped in \\\\boxed{}, e.g. \\\\boxed{C}. Do not output anything after the boxed answer.\" -%}\n{%- if messages[0].role == 'system' -%}\n {{- '<|im_start|>system\\n' + messages[0].content + '\\n\\n' + gk_system + '<|im_end|>\\n' -}}\n {%- set messages = messages[1:] -%}\n{%- else -%}\n {{- '<|im_start|>system\\n' + gk_system + '<|im_end|>\\n' -}}\n{%- endif -%}\n{%- for message in messages -%}\n {%- if message.role == 'user' -%}\n {{- '<|im_start|>user\\n' + message.content + '<|im_end|>\\n' -}}\n {%- elif message.role == 'assistant' -%}\n {{- '<|im_start|>assistant\\n' + message.content + '<|im_end|>\\n' -}}\n {%- endif -%}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n {{- '<|im_start|>assistant\\n\\n' -}}\n{%- endif -%}\n" +} \ No newline at end of file