Text Generation
Transformers
Safetensors
GGUF
English
llama
formal-logic
reasoning
lora
model-merging
wise-ft
reinforcement-learning
grpo
smollm2
twil-lm
conversational
text-generation-inference
Instructions to use webAI-Official/TwIL-LM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use webAI-Official/TwIL-LM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="webAI-Official/TwIL-LM") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("webAI-Official/TwIL-LM") model = AutoModelForCausalLM.from_pretrained("webAI-Official/TwIL-LM", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use webAI-Official/TwIL-LM with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf webAI-Official/TwIL-LM:Q4_K_M # Run inference directly in the terminal: llama cli -hf webAI-Official/TwIL-LM:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf webAI-Official/TwIL-LM:Q4_K_M # Run inference directly in the terminal: llama cli -hf webAI-Official/TwIL-LM:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf webAI-Official/TwIL-LM:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf webAI-Official/TwIL-LM:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf webAI-Official/TwIL-LM:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf webAI-Official/TwIL-LM:Q4_K_M
Use Docker
docker model run hf.co/webAI-Official/TwIL-LM:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use webAI-Official/TwIL-LM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "webAI-Official/TwIL-LM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "webAI-Official/TwIL-LM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/webAI-Official/TwIL-LM:Q4_K_M
- SGLang
How to use webAI-Official/TwIL-LM with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "webAI-Official/TwIL-LM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "webAI-Official/TwIL-LM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "webAI-Official/TwIL-LM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "webAI-Official/TwIL-LM", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use webAI-Official/TwIL-LM with Ollama:
ollama run hf.co/webAI-Official/TwIL-LM:Q4_K_M
- Unsloth Studio
How to use webAI-Official/TwIL-LM with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for webAI-Official/TwIL-LM to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for webAI-Official/TwIL-LM to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for webAI-Official/TwIL-LM to start chatting
- Docker Model Runner
How to use webAI-Official/TwIL-LM with Docker Model Runner:
docker model run hf.co/webAI-Official/TwIL-LM:Q4_K_M
- Lemonade
How to use webAI-Official/TwIL-LM with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull webAI-Official/TwIL-LM:Q4_K_M
Run and chat with the model
lemonade run user.TwIL-LM-Q4_K_M
List all available models
lemonade list
- Atomic Chat
File size: 8,668 Bytes
ecb9fa7 44bc424 7ced750 44bc424 ecb9fa7 5b63ca3 44bc424 7ced750 44bc424 ecb9fa7 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 44bc424 7ced750 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | ---
language:
- en
library_name: transformers
pipeline_tag: text-generation
base_model: HuggingFaceTB/SmolLM2-1.7B-Instruct
license: other
license_name: webai-non-commercial-license-ver.-1.0
license_link: https://huggingface.co/webAI-Official/webAI-ColVec1-4b/blob/main/LICENSE.md
tags:
- formal-logic
- reasoning
- lora
- model-merging
- wise-ft
- reinforcement-learning
- grpo
- smollm2
- twil-lm
---
# TwIL-LM2
A 1.7B reasoning model for **formal logic** tasks, built from
[`HuggingFaceTB/SmolLM2-1.7B-Instruct`](https://huggingface.co/HuggingFaceTB/SmolLM2-1.7B-Instruct)
through LoRA supervised fine-tuning, checkpoint fusion, WiSE-FT weight interpolation, and
entropy-weighted GRPO reinforcement learning.
It raises in-domain formal-logic performance by **+49% relative** over its base model
(macro gate 0.263 β 0.393) while holding held-out general capability roughly flat.
Its larger sibling, **TwIL-LM3** (3B, from SmolLM3), trades a smaller in-domain gain for
strictly better held-out retention. If you care about not regressing on general benchmarks,
prefer that one.
## Results
### Track A β in-domain formal logic
The **macro gate** is the mean of five objective scores: entailment labelling, multiple-choice
answering, procedural reasoning, Lean proof critique, and rule induction (scored by its
continuous derivation score). MCQ and procedural are credited as `max(exact_match, loose_match)`.
`n = 200` prompts per objective, greedy decoding, 2048 max new tokens.
| objective | SmolLM2-1.7B-Instruct | TwIL-LM2 | Ξ |
|---|---:|---:|---:|
| entailment_label | 0.245 | **0.585** | +0.340 |
| rule_induction | 0.135 | **0.514** | +0.379 |
| lean_critic | 0.490 | **0.525** | +0.035 |
| mcq_answer | 0.290 | 0.270 | β0.020 |
| procedural | 0.155 | 0.070 | β0.085 |
| **macro gate** | **0.2630** | **0.3927** | **+0.1297** |
The gain is concentrated in entailment labelling and rule induction. MCQ answering and
procedural reasoning **regressed**, and that is not hidden by the macro β it is averaged into
the number above.
### Track B β held-out benchmarks
Nothing in this suite was trained on. Scores are re-derived from saved generations with
delimiter-aware answer extractors rather than read from harness metrics.
| | SmolLM2-1.7B-Instruct | TwIL-LM2 | Ξ |
|---|---:|---:|---:|
| core average | 0.499 | **0.508** | +0.009 |
| suite average (14 datasets) | 0.384 | 0.374 | β0.010 |
Per-dataset, largest moves in each direction:
| dataset | base | TwIL-LM2 | Ξ |
|---|---:|---:|---:|
| GSM-Symbolic | 0.220 | 0.260 | +0.040 |
| CommonsenseQA | 0.397 | 0.433 | +0.037 |
| LogicBench BQA | 0.507 | 0.540 | +0.033 |
| MATH-500 | 0.190 | 0.210 | +0.020 |
| IFEval (strict) | 0.470 | 0.430 | β0.040 |
| SVAMP | 0.487 | 0.383 | β0.103 |
| MuSR | 0.422 | 0.313 | β0.109 |
**This model does not pass a no-regression bar on held-out tasks.** MuSR and SVAMP lose about
ten points each. The suite average is slightly negative. The honest summary is that in-domain
logic improves substantially and general capability is approximately preserved *on average*,
with real losses on multi-step narrative and word-problem reasoning.
## Usage
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "webAI-Official/TwIL-LM"
tok = AutoTokenizer.from_pretrained(model_id, revision="TwIL-LM2")
model = AutoModelForCausalLM.from_pretrained(
model_id, revision="TwIL-LM2", torch_dtype=torch.bfloat16, device_map="auto"
)
messages = [{"role": "user", "content":
"Does 'All dogs are mammals. Rex is a dog.' entail 'Rex is a mammal'? "
"Answer entailment, contradiction, or neutral."}]
inputs = tok.apply_chat_template(
messages, add_generation_prompt=True,
return_tensors="pt", return_dict=True,
).to(model.device)
out = model.generate(**inputs, max_new_tokens=2048, do_sample=False)
print(tok.decode(out[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
```
`return_dict=True` matters on transformers 5.x, where `apply_chat_template` returns a
`BatchEncoding` rather than a bare tensor; the above works on both 4.x and 5.x.
The model was trained and evaluated with **greedy decoding** (`do_sample=False`) and a
**2048-token** generation budget. It usually opens a `<think>...</think>` reasoning block before
answering, so give it room β the reported numbers assume at least 2048 new tokens, and a shorter
budget truncates reasoning and scores far worse.
## How it was built
Four stages on top of the base model:
1. **LoRA supervised fine-tuning** on a synthetic formal-logic corpus covering the Track A
objectives (first-order-logic translation, entailment labelling, semantic parsing, Lean
formalisation and critique, procedural reasoning, rule induction).
2. **Checkpoint fusion** β parameter-space averaging of intermediate SFT checkpoints selected
by a diversity probe, rather than taking the final checkpoint.
3. **WiSE-FT interpolation** toward the pretrained base, `W = (1 β Ξ»)Β·W_base + λ·W_finetuned`
with **Ξ» = 0.75**. Ξ» was chosen by constrained optimisation: maximise in-domain score
subject to minimal degradation on held-out benchmarks.
4. **MGPO** β entropy-weighted GRPO reinforcement learning against a programmatic verifier,
with partial credit for loose matches and token-F1 so that all-fail prompt groups still
produce gradient. Published checkpoint is **step 1680**.
## Limitations and caveats
**Truncation.** At a 2048-token budget, 6.9% of Track A generations hit the cap (down from
11.7% for the base). Our protocol marks a comparison `rankable` only below 2% truncation, so
both the base and this model are formally **not rankable** on Track A and the macro gate should
be read as indicative rather than exact. A truncated response scores zero regardless of whether
its reasoning was sound, so both numbers are pessimistic β the base more so.
**Scope.** Tuned for formal logic. The Track B suite does not cover code generation or tool use
(HumanEval, LiveCodeBench and BFCL were not run for this model or its base), so this release
makes no claim about those.
**Not a chat model.** It was optimised against automatic verifiers on logic tasks. It has had no
safety tuning beyond whatever the base model carries, and no instruction-following alignment
work β IFEval in fact regressed.
**Failed consolidation stage.** A post-RL self-distillation round (SDFT) was attempted to recover
held-out capability and made both tracks worse at every budget tried. It is not part of this
model. See the accompanying `SDFT_RESULT.md` in the project repository.
## Evaluation protocol
- Track A: `n = 200` per objective, greedy (`temperature = 0`), `max_new_tokens = 2048`, one
retry at 4096 for truncated rows, `max_seq_len = 8192`, seed 42.
- Track B: 300 examples per task, greedy, `max_gen_toks = 4096`, `max_model_len = 8192`,
`repetition_penalty = 1.0`, chat template applied, vLLM backend.
- Both tracks use the same protocol for the model and its base, in a paired run over identical
sampled rows.
`repetition_penalty = 1.0` is load-bearing. A 1.1 penalty produced apparent 20-point swings on
Track B that were pure decoding artefact; the decoding kwargs are hashed into the protocol
identity so a mismatched runner fails loudly instead of quietly producing a different number.
## Relationship to the `main` branch
The `main` branch of this repository holds the original TwIL-LM release: a PEFT **LoRA adapter**
(plus GGUF builds) for the supervised fine-tuning stage only. This branch holds a **full merged
model** from a later point in the pipeline β after fusion, WiSE-FT interpolation and MGPO
reinforcement learning β so it is loaded directly with `AutoModelForCausalLM`, with no adapter
and no base checkpoint required.
The two are scored on different protocols and their headline numbers are not directly
comparable: `main` reports a macro-*primary* average, while this card reports the five-component
macro *gate* described above.
## License and attribution
Released under the **webAI Non-Commercial License ver. 1.0** β see `LICENSE.md` in this
repository. This matches the licensing of the `main` branch.
The base model,
[`HuggingFaceTB/SmolLM2-1.7B-Instruct`](https://huggingface.co/HuggingFaceTB/SmolLM2-1.7B-Instruct),
is Apache 2.0; its licence text is retained as `apache-2.0-LICENSE.txt` and all credit for the
base model goes to the HuggingFaceTB team. Apache 2.0 permits distributing derivative works
under different terms provided attribution is preserved, which is what the pair of licence files
in this repository does.
|